aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-10-31 08:24:03 +0000
committerGitHub <[email protected]>2019-10-31 08:24:03 +0000
commitd067afb064a7fa67b172abf561b7d80740cd6f18 (patch)
treeddf0901cdf3aa454d6bfce3fa142191c22563494
parent7973c91281837bbb5c5a0bf3b1c71a5b52654b20 (diff)
parent1602db7d7d6aa38b4ee50de8cbe734529853d615 (diff)
Merge #2141
2141: add ModuleDefId to hir_def r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
-rw-r--r--crates/ra_hir/src/adt.rs8
-rw-r--r--crates/ra_hir/src/code_model.rs6
-rw-r--r--crates/ra_hir_def/src/lib.rs58
3 files changed, 61 insertions, 11 deletions
diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs
index 97424b39e..4fa2062bd 100644
--- a/crates/ra_hir/src/adt.rs
+++ b/crates/ra_hir/src/adt.rs
@@ -3,7 +3,7 @@
3 3
4use std::sync::Arc; 4use std::sync::Arc;
5 5
6use hir_def::type_ref::TypeRef; 6use hir_def::{type_ref::TypeRef, LocalEnumVariantId};
7use hir_expand::name::AsName; 7use hir_expand::name::AsName;
8use ra_arena::{impl_arena_id, Arena, RawId}; 8use ra_arena::{impl_arena_id, Arena, RawId};
9use ra_syntax::ast::{self, NameOwner, StructKind, TypeAscriptionOwner}; 9use ra_syntax::ast::{self, NameOwner, StructKind, TypeAscriptionOwner};
@@ -68,7 +68,7 @@ impl EnumVariant {
68#[derive(Debug, Clone, PartialEq, Eq)] 68#[derive(Debug, Clone, PartialEq, Eq)]
69pub struct EnumData { 69pub struct EnumData {
70 pub(crate) name: Option<Name>, 70 pub(crate) name: Option<Name>,
71 pub(crate) variants: Arena<EnumVariantId, EnumVariantData>, 71 pub(crate) variants: Arena<LocalEnumVariantId, EnumVariantData>,
72} 72}
73 73
74impl EnumData { 74impl EnumData {
@@ -85,10 +85,6 @@ impl EnumData {
85 } 85 }
86} 86}
87 87
88#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
89pub(crate) struct EnumVariantId(RawId);
90impl_arena_id!(EnumVariantId);
91
92#[derive(Debug, Clone, PartialEq, Eq)] 88#[derive(Debug, Clone, PartialEq, Eq)]
93pub(crate) struct EnumVariantData { 89pub(crate) struct EnumVariantData {
94 pub(crate) name: Option<Name>, 90 pub(crate) name: Option<Name>,
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index e0c6d6340..b32aa145e 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -8,14 +8,14 @@ use std::sync::Arc;
8use hir_def::{ 8use hir_def::{
9 builtin_type::BuiltinType, 9 builtin_type::BuiltinType,
10 type_ref::{Mutability, TypeRef}, 10 type_ref::{Mutability, TypeRef},
11 CrateModuleId, ModuleId, 11 CrateModuleId, LocalEnumVariantId, ModuleId,
12}; 12};
13use hir_expand::name::{self, AsName}; 13use hir_expand::name::{self, AsName};
14use ra_db::{CrateId, Edition}; 14use ra_db::{CrateId, Edition};
15use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; 15use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner};
16 16
17use crate::{ 17use crate::{
18 adt::{EnumVariantId, StructFieldId, VariantDef}, 18 adt::{StructFieldId, VariantDef},
19 db::{AstDatabase, DefDatabase, HirDatabase}, 19 db::{AstDatabase, DefDatabase, HirDatabase},
20 diagnostics::DiagnosticSink, 20 diagnostics::DiagnosticSink,
21 expr::{validation::ExprValidator, Body, BodySourceMap}, 21 expr::{validation::ExprValidator, Body, BodySourceMap},
@@ -410,7 +410,7 @@ impl Enum {
410#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 410#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
411pub struct EnumVariant { 411pub struct EnumVariant {
412 pub(crate) parent: Enum, 412 pub(crate) parent: Enum,
413 pub(crate) id: EnumVariantId, 413 pub(crate) id: LocalEnumVariantId,
414} 414}
415 415
416impl EnumVariant { 416impl EnumVariant {
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs
index 8cbff673c..93ad40005 100644
--- a/crates/ra_hir_def/src/lib.rs
+++ b/crates/ra_hir_def/src/lib.rs
@@ -23,7 +23,7 @@ use ra_arena::{impl_arena_id, RawId};
23use ra_db::{salsa, CrateId, FileId}; 23use ra_db::{salsa, CrateId, FileId};
24use ra_syntax::{ast, AstNode, SyntaxNode}; 24use ra_syntax::{ast, AstNode, SyntaxNode};
25 25
26use crate::db::InternDatabase; 26use crate::{builtin_type::BuiltinType, db::InternDatabase};
27 27
28#[derive(Debug, PartialEq, Eq, Clone, Copy)] 28#[derive(Debug, PartialEq, Eq, Clone, Copy)]
29pub struct Source<T> { 29pub struct Source<T> {
@@ -256,7 +256,7 @@ pub struct EnumVariantId {
256} 256}
257 257
258#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 258#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
259pub(crate) struct LocalEnumVariantId(RawId); 259pub struct LocalEnumVariantId(RawId);
260impl_arena_id!(LocalEnumVariantId); 260impl_arena_id!(LocalEnumVariantId);
261 261
262#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 262#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@@ -306,3 +306,57 @@ impl AstItemDef<ast::TypeAliasDef> for TypeAliasId {
306 db.lookup_intern_type_alias(self) 306 db.lookup_intern_type_alias(self)
307 } 307 }
308} 308}
309
310macro_rules! impl_froms {
311 ($e:ident: $($v:ident $(($($sv:ident),*))?),*) => {
312 $(
313 impl From<$v> for $e {
314 fn from(it: $v) -> $e {
315 $e::$v(it)
316 }
317 }
318 $($(
319 impl From<$sv> for $e {
320 fn from(it: $sv) -> $e {
321 $e::$v($v::$sv(it))
322 }
323 }
324 )*)?
325 )*
326 }
327}
328
329/// A Data Type
330#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
331pub enum AdtId {
332 StructId(StructId),
333 UnionId(UnionId),
334 EnumId(EnumId),
335}
336impl_froms!(AdtId: StructId, UnionId, EnumId);
337
338/// The defs which can be visible in the module.
339#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
340pub enum ModuleDefId {
341 ModuleId(ModuleId),
342 FunctionId(FunctionId),
343 AdtId(AdtId),
344 // Can't be directly declared, but can be imported.
345 EnumVariantId(EnumVariantId),
346 ConstId(ConstId),
347 StaticId(StaticId),
348 TraitId(TraitId),
349 TypeAliasId(TypeAliasId),
350 BuiltinType(BuiltinType),
351}
352impl_froms!(
353 ModuleDefId: ModuleId,
354 FunctionId,
355 AdtId(StructId, EnumId, UnionId),
356 EnumVariantId,
357 ConstId,
358 StaticId,
359 TraitId,
360 TypeAliasId,
361 BuiltinType
362);