diff options
author | Aleksey Kladov <[email protected]> | 2019-11-20 14:39:58 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-11-20 14:43:03 +0000 |
commit | 64c21ed19594b323e72605ba8c5dd4c6eee433f6 (patch) | |
tree | 6b48928149607fa6396357af29abfb4eb3d4d791 | |
parent | b7a36b54431ca5b746af53549a1b6e142570c7f4 (diff) |
Switch type aliases to new sources
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 28 | ||||
-rw-r--r-- | crates/ra_hir/src/code_model/src.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir/src/from_source.rs | 112 | ||||
-rw-r--r-- | crates/ra_hir_def/src/db.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir_def/src/generics.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/impls.rs | 13 | ||||
-rw-r--r-- | crates/ra_hir_def/src/lib.rs | 48 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 14 | ||||
-rw-r--r-- | crates/ra_hir_def/src/traits.rs | 10 |
9 files changed, 162 insertions, 73 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index c49190a0f..b8d48a500 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -13,7 +13,7 @@ use hir_def::{ | |||
13 | traits::TraitData, | 13 | traits::TraitData, |
14 | type_ref::{Mutability, TypeRef}, | 14 | type_ref::{Mutability, TypeRef}, |
15 | AssocItemId, CrateModuleId, FunctionContainerId, HasModule, ImplId, LocalEnumVariantId, | 15 | AssocItemId, CrateModuleId, FunctionContainerId, HasModule, ImplId, LocalEnumVariantId, |
16 | LocalStructFieldId, Lookup, ModuleId, UnionId, | 16 | LocalStructFieldId, Lookup, ModuleId, TypeAliasContainerId, UnionId, |
17 | }; | 17 | }; |
18 | use hir_expand::{ | 18 | use hir_expand::{ |
19 | diagnostics::DiagnosticSink, | 19 | diagnostics::DiagnosticSink, |
@@ -954,30 +954,34 @@ pub struct TypeAlias { | |||
954 | 954 | ||
955 | impl TypeAlias { | 955 | impl TypeAlias { |
956 | pub fn module(self, db: &impl DefDatabase) -> Module { | 956 | pub fn module(self, db: &impl DefDatabase) -> Module { |
957 | Module { id: self.id.module(db) } | 957 | Module { id: self.id.lookup(db).module(db) } |
958 | } | 958 | } |
959 | 959 | ||
960 | pub fn krate(self, db: &impl DefDatabase) -> Option<Crate> { | 960 | pub fn krate(self, db: &impl DefDatabase) -> Option<Crate> { |
961 | Some(self.module(db).krate()) | 961 | Some(self.module(db).krate()) |
962 | } | 962 | } |
963 | 963 | ||
964 | /// The containing impl block, if this is a method. | 964 | /// The containing impl block, if this is a type alias. |
965 | pub fn impl_block(self, db: &impl DefDatabase) -> Option<ImplBlock> { | 965 | pub fn impl_block(self, db: &impl DefDatabase) -> Option<ImplBlock> { |
966 | ImplBlock::containing(db, self.into()) | 966 | match self.container(db) { |
967 | Some(Container::ImplBlock(it)) => Some(it), | ||
968 | _ => None, | ||
969 | } | ||
967 | } | 970 | } |
968 | 971 | ||
969 | /// The containing trait, if this is a trait method definition. | 972 | /// The containing trait, if this is a trait type alias definition. |
970 | pub fn parent_trait(self, db: &impl DefDatabase) -> Option<Trait> { | 973 | pub fn parent_trait(self, db: &impl DefDatabase) -> Option<Trait> { |
971 | db.trait_items_index(self.module(db).id).get_parent_trait(self.id.into()).map(Trait::from) | 974 | match self.container(db) { |
975 | Some(Container::Trait(it)) => Some(it), | ||
976 | _ => None, | ||
977 | } | ||
972 | } | 978 | } |
973 | 979 | ||
974 | pub fn container(self, db: &impl DefDatabase) -> Option<Container> { | 980 | pub fn container(self, db: &impl DefDatabase) -> Option<Container> { |
975 | if let Some(impl_block) = self.impl_block(db) { | 981 | match self.id.lookup(db).container { |
976 | Some(impl_block.into()) | 982 | TypeAliasContainerId::TraitId(it) => Some(Container::Trait(it.into())), |
977 | } else if let Some(trait_) = self.parent_trait(db) { | 983 | TypeAliasContainerId::ImplId(it) => Some(Container::ImplBlock(it.into())), |
978 | Some(trait_.into()) | 984 | TypeAliasContainerId::ModuleId(_) => None, |
979 | } else { | ||
980 | None | ||
981 | } | 985 | } |
982 | } | 986 | } |
983 | 987 | ||
diff --git a/crates/ra_hir/src/code_model/src.rs b/crates/ra_hir/src/code_model/src.rs index 91cab7414..04675e08e 100644 --- a/crates/ra_hir/src/code_model/src.rs +++ b/crates/ra_hir/src/code_model/src.rs | |||
@@ -138,7 +138,7 @@ impl HasSource for Trait { | |||
138 | impl HasSource for TypeAlias { | 138 | impl HasSource for TypeAlias { |
139 | type Ast = ast::TypeAliasDef; | 139 | type Ast = ast::TypeAliasDef; |
140 | fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<ast::TypeAliasDef> { | 140 | fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<ast::TypeAliasDef> { |
141 | self.id.source(db) | 141 | self.id.lookup(db).source(db) |
142 | } | 142 | } |
143 | } | 143 | } |
144 | impl HasSource for MacroDef { | 144 | impl HasSource for MacroDef { |
diff --git a/crates/ra_hir/src/from_source.rs b/crates/ra_hir/src/from_source.rs index 303d5f138..f5fdaafa3 100644 --- a/crates/ra_hir/src/from_source.rs +++ b/crates/ra_hir/src/from_source.rs | |||
@@ -4,7 +4,7 @@ use hir_def::{ModuleId, StructId, StructOrUnionId, UnionId}; | |||
4 | use hir_expand::{name::AsName, AstId, MacroDefId, MacroDefKind}; | 4 | use hir_expand::{name::AsName, AstId, MacroDefId, MacroDefKind}; |
5 | use ra_syntax::{ | 5 | use ra_syntax::{ |
6 | ast::{self, AstNode, NameOwner}, | 6 | ast::{self, AstNode, NameOwner}, |
7 | match_ast, AstPtr, | 7 | match_ast, AstPtr, SyntaxNode, |
8 | }; | 8 | }; |
9 | 9 | ||
10 | use crate::{ | 10 | use crate::{ |
@@ -52,48 +52,27 @@ impl FromSource for Trait { | |||
52 | impl FromSource for Function { | 52 | impl FromSource for Function { |
53 | type Ast = ast::FnDef; | 53 | type Ast = ast::FnDef; |
54 | fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> { | 54 | fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> { |
55 | // FIXME: this doesn't try to handle nested declarations | 55 | let items = match Container::find(db, src.as_ref().map(|it| it.syntax()))? { |
56 | for container in src.value.syntax().ancestors() { | 56 | Container::Trait(it) => it.items(db), |
57 | let res = match_ast! { | 57 | Container::ImplBlock(it) => it.items(db), |
58 | match container { | 58 | Container::Module(m) => { |
59 | ast::TraitDef(it) => { | 59 | return m |
60 | let c = Trait::from_source(db, src.with_value(it))?; | 60 | .declarations(db) |
61 | c.items(db) | 61 | .into_iter() |
62 | .into_iter() | 62 | .filter_map(|it| match it { |
63 | .filter_map(|it| match it { | 63 | ModuleDef::Function(it) => Some(it), |
64 | AssocItem::Function(it) => Some(it), | 64 | _ => None, |
65 | _ => None | 65 | }) |
66 | }) | 66 | .find(|it| same_source(&it.source(db), &src)) |
67 | .find(|it| same_source(&it.source(db), &src))? | 67 | } |
68 | }, | 68 | }; |
69 | ast::ImplBlock(it) => { | 69 | items |
70 | let c = ImplBlock::from_source(db, src.with_value(it))?; | ||
71 | c.items(db) | ||
72 | .into_iter() | ||
73 | .filter_map(|it| match it { | ||
74 | AssocItem::Function(it) => Some(it), | ||
75 | _ => None | ||
76 | }) | ||
77 | .find(|it| same_source(&it.source(db), &src))? | ||
78 | |||
79 | }, | ||
80 | _ => { continue }, | ||
81 | } | ||
82 | }; | ||
83 | return Some(res); | ||
84 | } | ||
85 | |||
86 | let module_source = ModuleSource::from_child_node(db, src.as_ref().map(|it| it.syntax())); | ||
87 | let c = Module::from_definition(db, src.with_value(module_source))?; | ||
88 | let res = c | ||
89 | .declarations(db) | ||
90 | .into_iter() | 70 | .into_iter() |
91 | .filter_map(|it| match it { | 71 | .filter_map(|it| match it { |
92 | ModuleDef::Function(it) => Some(it), | 72 | AssocItem::Function(it) => Some(it), |
93 | _ => None, | 73 | _ => None, |
94 | }) | 74 | }) |
95 | .find(|it| same_source(&it.source(db), &src)); | 75 | .find(|it| same_source(&it.source(db), &src)) |
96 | res | ||
97 | } | 76 | } |
98 | } | 77 | } |
99 | 78 | ||
@@ -114,8 +93,27 @@ impl FromSource for Static { | |||
114 | impl FromSource for TypeAlias { | 93 | impl FromSource for TypeAlias { |
115 | type Ast = ast::TypeAliasDef; | 94 | type Ast = ast::TypeAliasDef; |
116 | fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> { | 95 | fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> { |
117 | let id = from_source(db, src)?; | 96 | let items = match Container::find(db, src.as_ref().map(|it| it.syntax()))? { |
118 | Some(TypeAlias { id }) | 97 | Container::Trait(it) => it.items(db), |
98 | Container::ImplBlock(it) => it.items(db), | ||
99 | Container::Module(m) => { | ||
100 | return m | ||
101 | .declarations(db) | ||
102 | .into_iter() | ||
103 | .filter_map(|it| match it { | ||
104 | ModuleDef::TypeAlias(it) => Some(it), | ||
105 | _ => None, | ||
106 | }) | ||
107 | .find(|it| same_source(&it.source(db), &src)) | ||
108 | } | ||
109 | }; | ||
110 | items | ||
111 | .into_iter() | ||
112 | .filter_map(|it| match it { | ||
113 | AssocItem::TypeAlias(it) => Some(it), | ||
114 | _ => None, | ||
115 | }) | ||
116 | .find(|it| same_source(&it.source(db), &src)) | ||
119 | } | 117 | } |
120 | } | 118 | } |
121 | 119 | ||
@@ -258,6 +256,38 @@ where | |||
258 | Some(DEF::from_ast(ctx, &src.value)) | 256 | Some(DEF::from_ast(ctx, &src.value)) |
259 | } | 257 | } |
260 | 258 | ||
259 | enum Container { | ||
260 | Trait(Trait), | ||
261 | ImplBlock(ImplBlock), | ||
262 | Module(Module), | ||
263 | } | ||
264 | |||
265 | impl Container { | ||
266 | fn find(db: &impl DefDatabase, src: Source<&SyntaxNode>) -> Option<Container> { | ||
267 | // FIXME: this doesn't try to handle nested declarations | ||
268 | for container in src.value.ancestors() { | ||
269 | let res = match_ast! { | ||
270 | match container { | ||
271 | ast::TraitDef(it) => { | ||
272 | let c = Trait::from_source(db, src.with_value(it))?; | ||
273 | Container::Trait(c) | ||
274 | }, | ||
275 | ast::ImplBlock(it) => { | ||
276 | let c = ImplBlock::from_source(db, src.with_value(it))?; | ||
277 | Container::ImplBlock(c) | ||
278 | }, | ||
279 | _ => { continue }, | ||
280 | } | ||
281 | }; | ||
282 | return Some(res); | ||
283 | } | ||
284 | |||
285 | let module_source = ModuleSource::from_child_node(db, src); | ||
286 | let c = Module::from_definition(db, src.with_value(module_source))?; | ||
287 | Some(Container::Module(c)) | ||
288 | } | ||
289 | } | ||
290 | |||
261 | /// XXX: AST Nodes and SyntaxNodes have identity equality semantics: nodes are | 291 | /// XXX: AST Nodes and SyntaxNodes have identity equality semantics: nodes are |
262 | /// equal if they point to exactly the same object. | 292 | /// equal if they point to exactly the same object. |
263 | /// | 293 | /// |
diff --git a/crates/ra_hir_def/src/db.rs b/crates/ra_hir_def/src/db.rs index e4ffdebe9..d6d32fb8c 100644 --- a/crates/ra_hir_def/src/db.rs +++ b/crates/ra_hir_def/src/db.rs | |||
@@ -14,13 +14,13 @@ use crate::{ | |||
14 | CrateDefMap, | 14 | CrateDefMap, |
15 | }, | 15 | }, |
16 | traits::{TraitData, TraitItemsIndex}, | 16 | traits::{TraitData, TraitItemsIndex}, |
17 | DefWithBodyId, EnumId, FunctionLoc, ImplId, ItemLoc, ModuleId, StructOrUnionId, TraitId, | 17 | DefWithBodyId, EnumId, ImplId, ItemLoc, ModuleId, StructOrUnionId, TraitId, |
18 | }; | 18 | }; |
19 | 19 | ||
20 | #[salsa::query_group(InternDatabaseStorage)] | 20 | #[salsa::query_group(InternDatabaseStorage)] |
21 | pub trait InternDatabase: SourceDatabase { | 21 | pub trait InternDatabase: SourceDatabase { |
22 | #[salsa::interned] | 22 | #[salsa::interned] |
23 | fn intern_function(&self, loc: FunctionLoc) -> crate::FunctionId; | 23 | fn intern_function(&self, loc: crate::FunctionLoc) -> crate::FunctionId; |
24 | #[salsa::interned] | 24 | #[salsa::interned] |
25 | fn intern_struct_or_union(&self, loc: ItemLoc<ast::StructDef>) -> crate::StructOrUnionId; | 25 | fn intern_struct_or_union(&self, loc: ItemLoc<ast::StructDef>) -> crate::StructOrUnionId; |
26 | #[salsa::interned] | 26 | #[salsa::interned] |
@@ -32,7 +32,7 @@ pub trait InternDatabase: SourceDatabase { | |||
32 | #[salsa::interned] | 32 | #[salsa::interned] |
33 | fn intern_trait(&self, loc: ItemLoc<ast::TraitDef>) -> crate::TraitId; | 33 | fn intern_trait(&self, loc: ItemLoc<ast::TraitDef>) -> crate::TraitId; |
34 | #[salsa::interned] | 34 | #[salsa::interned] |
35 | fn intern_type_alias(&self, loc: ItemLoc<ast::TypeAliasDef>) -> crate::TypeAliasId; | 35 | fn intern_type_alias(&self, loc: crate::TypeAliasLoc) -> crate::TypeAliasId; |
36 | #[salsa::interned] | 36 | #[salsa::interned] |
37 | fn intern_impl(&self, loc: ItemLoc<ast::ImplBlock>) -> crate::ImplId; | 37 | fn intern_impl(&self, loc: ItemLoc<ast::ImplBlock>) -> crate::ImplId; |
38 | } | 38 | } |
diff --git a/crates/ra_hir_def/src/generics.rs b/crates/ra_hir_def/src/generics.rs index 11dd2a948..17a5d5f43 100644 --- a/crates/ra_hir_def/src/generics.rs +++ b/crates/ra_hir_def/src/generics.rs | |||
@@ -72,7 +72,7 @@ impl GenericParams { | |||
72 | let self_param = TypeRef::Path(name::SELF_TYPE.into()); | 72 | let self_param = TypeRef::Path(name::SELF_TYPE.into()); |
73 | generics.fill_bounds(&it.source(db).value, self_param); | 73 | generics.fill_bounds(&it.source(db).value, self_param); |
74 | } | 74 | } |
75 | GenericDefId::TypeAliasId(it) => generics.fill(&it.source(db).value, start), | 75 | GenericDefId::TypeAliasId(it) => generics.fill(&it.lookup(db).source(db).value, start), |
76 | // Note that we don't add `Self` here: in `impl`s, `Self` is not a | 76 | // Note that we don't add `Self` here: in `impl`s, `Self` is not a |
77 | // type-parameter, but rather is a type-alias for impl's target | 77 | // type-parameter, but rather is a type-alias for impl's target |
78 | // type, so this is handled by the resolver. | 78 | // type, so this is handled by the resolver. |
diff --git a/crates/ra_hir_def/src/impls.rs b/crates/ra_hir_def/src/impls.rs index 9be38c5e1..703e4d503 100644 --- a/crates/ra_hir_def/src/impls.rs +++ b/crates/ra_hir_def/src/impls.rs | |||
@@ -10,7 +10,7 @@ use ra_syntax::ast; | |||
10 | 10 | ||
11 | use crate::{ | 11 | use crate::{ |
12 | db::DefDatabase2, type_ref::TypeRef, AssocItemId, AstItemDef, ConstId, FunctionContainerId, | 12 | db::DefDatabase2, type_ref::TypeRef, AssocItemId, AstItemDef, ConstId, FunctionContainerId, |
13 | FunctionLoc, ImplId, Intern, LocationCtx, TypeAliasId, | 13 | FunctionLoc, ImplId, Intern, LocationCtx, TypeAliasContainerId, TypeAliasLoc, |
14 | }; | 14 | }; |
15 | 15 | ||
16 | #[derive(Debug, Clone, PartialEq, Eq)] | 16 | #[derive(Debug, Clone, PartialEq, Eq)] |
@@ -36,18 +36,23 @@ impl ImplData { | |||
36 | .impl_items() | 36 | .impl_items() |
37 | .map(|item_node| match item_node { | 37 | .map(|item_node| match item_node { |
38 | ast::ImplItem::FnDef(it) => { | 38 | ast::ImplItem::FnDef(it) => { |
39 | let func_id = FunctionLoc { | 39 | let def = FunctionLoc { |
40 | container: FunctionContainerId::ImplId(id), | 40 | container: FunctionContainerId::ImplId(id), |
41 | ast_id: AstId::new(src.file_id, items.ast_id(&it)), | 41 | ast_id: AstId::new(src.file_id, items.ast_id(&it)), |
42 | } | 42 | } |
43 | .intern(db); | 43 | .intern(db); |
44 | func_id.into() | 44 | def.into() |
45 | } | 45 | } |
46 | ast::ImplItem::ConstDef(it) => { | 46 | ast::ImplItem::ConstDef(it) => { |
47 | ConstId::from_ast_id(ctx, items.ast_id(&it)).into() | 47 | ConstId::from_ast_id(ctx, items.ast_id(&it)).into() |
48 | } | 48 | } |
49 | ast::ImplItem::TypeAliasDef(it) => { | 49 | ast::ImplItem::TypeAliasDef(it) => { |
50 | TypeAliasId::from_ast_id(ctx, items.ast_id(&it)).into() | 50 | let def = TypeAliasLoc { |
51 | container: TypeAliasContainerId::ImplId(id), | ||
52 | ast_id: AstId::new(src.file_id, items.ast_id(&it)), | ||
53 | } | ||
54 | .intern(db); | ||
55 | def.into() | ||
51 | } | 56 | } |
52 | }) | 57 | }) |
53 | .collect() | 58 | .collect() |
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index b9a13776f..6052370b4 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs | |||
@@ -332,16 +332,35 @@ impl AstItemDef<ast::TraitDef> for TraitId { | |||
332 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 332 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
333 | pub struct TypeAliasId(salsa::InternId); | 333 | pub struct TypeAliasId(salsa::InternId); |
334 | impl_intern_key!(TypeAliasId); | 334 | impl_intern_key!(TypeAliasId); |
335 | impl AstItemDef<ast::TypeAliasDef> for TypeAliasId { | 335 | |
336 | fn intern(db: &impl InternDatabase, loc: ItemLoc<ast::TypeAliasDef>) -> Self { | 336 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
337 | db.intern_type_alias(loc) | 337 | pub struct TypeAliasLoc { |
338 | pub container: TypeAliasContainerId, | ||
339 | pub ast_id: AstId<ast::TypeAliasDef>, | ||
340 | } | ||
341 | |||
342 | impl Intern for TypeAliasLoc { | ||
343 | type ID = TypeAliasId; | ||
344 | fn intern(self, db: &impl db::DefDatabase2) -> TypeAliasId { | ||
345 | db.intern_type_alias(self) | ||
338 | } | 346 | } |
339 | fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<ast::TypeAliasDef> { | 347 | } |
340 | db.lookup_intern_type_alias(self) | 348 | |
349 | impl Lookup for TypeAliasId { | ||
350 | type Data = TypeAliasLoc; | ||
351 | fn lookup(&self, db: &impl db::DefDatabase2) -> TypeAliasLoc { | ||
352 | db.lookup_intern_type_alias(*self) | ||
341 | } | 353 | } |
342 | } | 354 | } |
343 | 355 | ||
344 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 356 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
357 | pub enum TypeAliasContainerId { | ||
358 | ModuleId(ModuleId), | ||
359 | ImplId(ImplId), | ||
360 | TraitId(TraitId), | ||
361 | } | ||
362 | |||
363 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
345 | pub struct ImplId(salsa::InternId); | 364 | pub struct ImplId(salsa::InternId); |
346 | impl_intern_key!(ImplId); | 365 | impl_intern_key!(ImplId); |
347 | impl AstItemDef<ast::ImplBlock> for ImplId { | 366 | impl AstItemDef<ast::ImplBlock> for ImplId { |
@@ -476,6 +495,16 @@ impl HasModule for FunctionLoc { | |||
476 | } | 495 | } |
477 | } | 496 | } |
478 | 497 | ||
498 | impl HasModule for TypeAliasLoc { | ||
499 | fn module(&self, db: &impl db::DefDatabase2) -> ModuleId { | ||
500 | match self.container { | ||
501 | TypeAliasContainerId::ModuleId(it) => it, | ||
502 | TypeAliasContainerId::ImplId(it) => it.module(db), | ||
503 | TypeAliasContainerId::TraitId(it) => it.module(db), | ||
504 | } | ||
505 | } | ||
506 | } | ||
507 | |||
479 | pub trait HasSource { | 508 | pub trait HasSource { |
480 | type Value; | 509 | type Value; |
481 | fn source(&self, db: &impl db::DefDatabase2) -> Source<Self::Value>; | 510 | fn source(&self, db: &impl db::DefDatabase2) -> Source<Self::Value>; |
@@ -489,3 +518,12 @@ impl HasSource for FunctionLoc { | |||
489 | Source::new(self.ast_id.file_id(), node) | 518 | Source::new(self.ast_id.file_id(), node) |
490 | } | 519 | } |
491 | } | 520 | } |
521 | |||
522 | impl HasSource for TypeAliasLoc { | ||
523 | type Value = ast::TypeAliasDef; | ||
524 | |||
525 | fn source(&self, db: &impl db::DefDatabase2) -> Source<ast::TypeAliasDef> { | ||
526 | let node = self.ast_id.to_node(db); | ||
527 | Source::new(self.ast_id.file_id(), node) | ||
528 | } | ||
529 | } | ||
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index d2ed94a87..060185b61 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs | |||
@@ -21,7 +21,7 @@ use crate::{ | |||
21 | path::{Path, PathKind}, | 21 | path::{Path, PathKind}, |
22 | AdtId, AstId, AstItemDef, ConstId, CrateModuleId, EnumId, EnumVariantId, FunctionContainerId, | 22 | AdtId, AstId, AstItemDef, ConstId, CrateModuleId, EnumId, EnumVariantId, FunctionContainerId, |
23 | FunctionLoc, ImplId, Intern, LocationCtx, ModuleDefId, ModuleId, StaticId, StructId, | 23 | FunctionLoc, ImplId, Intern, LocationCtx, ModuleDefId, ModuleId, StaticId, StructId, |
24 | StructOrUnionId, TraitId, TypeAliasId, UnionId, | 24 | StructOrUnionId, TraitId, TypeAliasContainerId, TypeAliasLoc, UnionId, |
25 | }; | 25 | }; |
26 | 26 | ||
27 | pub(super) fn collect_defs(db: &impl DefDatabase2, mut def_map: CrateDefMap) -> CrateDefMap { | 27 | pub(super) fn collect_defs(db: &impl DefDatabase2, mut def_map: CrateDefMap) -> CrateDefMap { |
@@ -673,13 +673,13 @@ where | |||
673 | let name = def.name.clone(); | 673 | let name = def.name.clone(); |
674 | let def: PerNs = match def.kind { | 674 | let def: PerNs = match def.kind { |
675 | raw::DefKind::Function(ast_id) => { | 675 | raw::DefKind::Function(ast_id) => { |
676 | let f = FunctionLoc { | 676 | let def = FunctionLoc { |
677 | container: FunctionContainerId::ModuleId(module), | 677 | container: FunctionContainerId::ModuleId(module), |
678 | ast_id: AstId::new(self.file_id, ast_id), | 678 | ast_id: AstId::new(self.file_id, ast_id), |
679 | } | 679 | } |
680 | .intern(self.def_collector.db); | 680 | .intern(self.def_collector.db); |
681 | 681 | ||
682 | PerNs::values(f.into()) | 682 | PerNs::values(def.into()) |
683 | } | 683 | } |
684 | raw::DefKind::Struct(ast_id) => { | 684 | raw::DefKind::Struct(ast_id) => { |
685 | let id = StructOrUnionId::from_ast_id(ctx, ast_id).into(); | 685 | let id = StructOrUnionId::from_ast_id(ctx, ast_id).into(); |
@@ -698,7 +698,13 @@ where | |||
698 | } | 698 | } |
699 | raw::DefKind::Trait(ast_id) => PerNs::types(TraitId::from_ast_id(ctx, ast_id).into()), | 699 | raw::DefKind::Trait(ast_id) => PerNs::types(TraitId::from_ast_id(ctx, ast_id).into()), |
700 | raw::DefKind::TypeAlias(ast_id) => { | 700 | raw::DefKind::TypeAlias(ast_id) => { |
701 | PerNs::types(TypeAliasId::from_ast_id(ctx, ast_id).into()) | 701 | let def = TypeAliasLoc { |
702 | container: TypeAliasContainerId::ModuleId(module), | ||
703 | ast_id: AstId::new(self.file_id, ast_id), | ||
704 | } | ||
705 | .intern(self.def_collector.db); | ||
706 | |||
707 | PerNs::types(def.into()) | ||
702 | } | 708 | } |
703 | }; | 709 | }; |
704 | let resolution = Resolution { def, import: None }; | 710 | let resolution = Resolution { def, import: None }; |
diff --git a/crates/ra_hir_def/src/traits.rs b/crates/ra_hir_def/src/traits.rs index 6e36bc0d0..228524a57 100644 --- a/crates/ra_hir_def/src/traits.rs +++ b/crates/ra_hir_def/src/traits.rs | |||
@@ -12,7 +12,7 @@ use rustc_hash::FxHashMap; | |||
12 | 12 | ||
13 | use crate::{ | 13 | use crate::{ |
14 | db::DefDatabase2, AssocItemId, AstItemDef, ConstId, FunctionContainerId, FunctionLoc, Intern, | 14 | db::DefDatabase2, AssocItemId, AstItemDef, ConstId, FunctionContainerId, FunctionLoc, Intern, |
15 | LocationCtx, ModuleDefId, ModuleId, TraitId, TypeAliasId, | 15 | LocationCtx, ModuleDefId, ModuleId, TraitId, TypeAliasContainerId, TypeAliasLoc, |
16 | }; | 16 | }; |
17 | 17 | ||
18 | #[derive(Debug, Clone, PartialEq, Eq)] | 18 | #[derive(Debug, Clone, PartialEq, Eq)] |
@@ -41,7 +41,12 @@ impl TraitData { | |||
41 | .intern(db) | 41 | .intern(db) |
42 | .into(), | 42 | .into(), |
43 | ast::ImplItem::ConstDef(it) => ConstId::from_ast(ctx, &it).into(), | 43 | ast::ImplItem::ConstDef(it) => ConstId::from_ast(ctx, &it).into(), |
44 | ast::ImplItem::TypeAliasDef(it) => TypeAliasId::from_ast(ctx, &it).into(), | 44 | ast::ImplItem::TypeAliasDef(it) => TypeAliasLoc { |
45 | container: TypeAliasContainerId::TraitId(tr), | ||
46 | ast_id: AstId::new(src.file_id, ast_id_map.ast_id(&it)), | ||
47 | } | ||
48 | .intern(db) | ||
49 | .into(), | ||
45 | }) | 50 | }) |
46 | .collect() | 51 | .collect() |
47 | } else { | 52 | } else { |
@@ -65,6 +70,7 @@ impl TraitItemsIndex { | |||
65 | for item in db.trait_data(tr).items.iter() { | 70 | for item in db.trait_data(tr).items.iter() { |
66 | match item { | 71 | match item { |
67 | AssocItemId::FunctionId(_) => (), | 72 | AssocItemId::FunctionId(_) => (), |
73 | AssocItemId::TypeAliasId(_) => (), | ||
68 | _ => { | 74 | _ => { |
69 | let prev = index.traits_by_def.insert(*item, tr); | 75 | let prev = index.traits_by_def.insert(*item, tr); |
70 | assert!(prev.is_none()); | 76 | assert!(prev.is_none()); |