diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-10-31 08:24:03 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-10-31 08:24:03 +0000 |
commit | d067afb064a7fa67b172abf561b7d80740cd6f18 (patch) | |
tree | ddf0901cdf3aa454d6bfce3fa142191c22563494 /crates | |
parent | 7973c91281837bbb5c5a0bf3b1c71a5b52654b20 (diff) | |
parent | 1602db7d7d6aa38b4ee50de8cbe734529853d615 (diff) |
Merge #2141
2141: add ModuleDefId to hir_def r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir/src/adt.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir_def/src/lib.rs | 58 |
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 | ||
4 | use std::sync::Arc; | 4 | use std::sync::Arc; |
5 | 5 | ||
6 | use hir_def::type_ref::TypeRef; | 6 | use hir_def::{type_ref::TypeRef, LocalEnumVariantId}; |
7 | use hir_expand::name::AsName; | 7 | use hir_expand::name::AsName; |
8 | use ra_arena::{impl_arena_id, Arena, RawId}; | 8 | use ra_arena::{impl_arena_id, Arena, RawId}; |
9 | use ra_syntax::ast::{self, NameOwner, StructKind, TypeAscriptionOwner}; | 9 | use 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)] |
69 | pub struct EnumData { | 69 | pub 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 | ||
74 | impl EnumData { | 74 | impl EnumData { |
@@ -85,10 +85,6 @@ impl EnumData { | |||
85 | } | 85 | } |
86 | } | 86 | } |
87 | 87 | ||
88 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
89 | pub(crate) struct EnumVariantId(RawId); | ||
90 | impl_arena_id!(EnumVariantId); | ||
91 | |||
92 | #[derive(Debug, Clone, PartialEq, Eq)] | 88 | #[derive(Debug, Clone, PartialEq, Eq)] |
93 | pub(crate) struct EnumVariantData { | 89 | pub(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; | |||
8 | use hir_def::{ | 8 | use 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 | }; |
13 | use hir_expand::name::{self, AsName}; | 13 | use hir_expand::name::{self, AsName}; |
14 | use ra_db::{CrateId, Edition}; | 14 | use ra_db::{CrateId, Edition}; |
15 | use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; | 15 | use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; |
16 | 16 | ||
17 | use crate::{ | 17 | use 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)] |
411 | pub struct EnumVariant { | 411 | pub 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 | ||
416 | impl EnumVariant { | 416 | impl 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}; | |||
23 | use ra_db::{salsa, CrateId, FileId}; | 23 | use ra_db::{salsa, CrateId, FileId}; |
24 | use ra_syntax::{ast, AstNode, SyntaxNode}; | 24 | use ra_syntax::{ast, AstNode, SyntaxNode}; |
25 | 25 | ||
26 | use crate::db::InternDatabase; | 26 | use crate::{builtin_type::BuiltinType, db::InternDatabase}; |
27 | 27 | ||
28 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] | 28 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] |
29 | pub struct Source<T> { | 29 | pub 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)] |
259 | pub(crate) struct LocalEnumVariantId(RawId); | 259 | pub struct LocalEnumVariantId(RawId); |
260 | impl_arena_id!(LocalEnumVariantId); | 260 | impl_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 | |||
310 | macro_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)] | ||
331 | pub enum AdtId { | ||
332 | StructId(StructId), | ||
333 | UnionId(UnionId), | ||
334 | EnumId(EnumId), | ||
335 | } | ||
336 | impl_froms!(AdtId: StructId, UnionId, EnumId); | ||
337 | |||
338 | /// The defs which can be visible in the module. | ||
339 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
340 | pub 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 | } | ||
352 | impl_froms!( | ||
353 | ModuleDefId: ModuleId, | ||
354 | FunctionId, | ||
355 | AdtId(StructId, EnumId, UnionId), | ||
356 | EnumVariantId, | ||
357 | ConstId, | ||
358 | StaticId, | ||
359 | TraitId, | ||
360 | TypeAliasId, | ||
361 | BuiltinType | ||
362 | ); | ||