diff options
Diffstat (limited to 'crates/hir_def/src/item_tree')
-rw-r--r-- | crates/hir_def/src/item_tree/lower.rs | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/crates/hir_def/src/item_tree/lower.rs b/crates/hir_def/src/item_tree/lower.rs index d3fe1ce1e..8d3862811 100644 --- a/crates/hir_def/src/item_tree/lower.rs +++ b/crates/hir_def/src/item_tree/lower.rs | |||
@@ -11,7 +11,7 @@ use syntax::{ | |||
11 | 11 | ||
12 | use crate::{ | 12 | use crate::{ |
13 | generics::{GenericParams, TypeParamData, TypeParamProvenance}, | 13 | generics::{GenericParams, TypeParamData, TypeParamProvenance}, |
14 | type_ref::LifetimeRef, | 14 | type_ref::{LifetimeRef, TraitRef}, |
15 | }; | 15 | }; |
16 | 16 | ||
17 | use super::*; | 17 | use super::*; |
@@ -87,14 +87,6 @@ impl Ctx { | |||
87 | self.tree | 87 | self.tree |
88 | } | 88 | } |
89 | 89 | ||
90 | pub(super) fn lower_single_item(mut self, item: ast::Item) -> ItemTree { | ||
91 | self.tree.top_level = self | ||
92 | .lower_mod_item(&item, false) | ||
93 | .map(|item| item.0) | ||
94 | .unwrap_or_else(|| Default::default()); | ||
95 | self.tree | ||
96 | } | ||
97 | |||
98 | pub(super) fn lower_inner_items(mut self, within: &SyntaxNode) -> ItemTree { | 90 | pub(super) fn lower_inner_items(mut self, within: &SyntaxNode) -> ItemTree { |
99 | self.collect_inner_items(within); | 91 | self.collect_inner_items(within); |
100 | self.tree | 92 | self.tree |
@@ -544,8 +536,11 @@ impl Ctx { | |||
544 | fn lower_impl(&mut self, impl_def: &ast::Impl) -> Option<FileItemTreeId<Impl>> { | 536 | fn lower_impl(&mut self, impl_def: &ast::Impl) -> Option<FileItemTreeId<Impl>> { |
545 | let generic_params = | 537 | let generic_params = |
546 | self.lower_generic_params_and_inner_items(GenericsOwner::Impl, impl_def); | 538 | self.lower_generic_params_and_inner_items(GenericsOwner::Impl, impl_def); |
547 | let target_trait = impl_def.trait_().map(|tr| self.lower_type_ref(&tr)); | 539 | // FIXME: If trait lowering fails, due to a non PathType for example, we treat this impl |
548 | let target_type = self.lower_type_ref(&impl_def.self_ty()?); | 540 | // as if it was an non-trait impl. Ideally we want to create a unique missing ref that only |
541 | // equals itself. | ||
542 | let target_trait = impl_def.trait_().and_then(|tr| self.lower_trait_ref(&tr)); | ||
543 | let self_ty = self.lower_type_ref(&impl_def.self_ty()?); | ||
549 | let is_negative = impl_def.excl_token().is_some(); | 544 | let is_negative = impl_def.excl_token().is_some(); |
550 | 545 | ||
551 | // We cannot use `assoc_items()` here as that does not include macro calls. | 546 | // We cannot use `assoc_items()` here as that does not include macro calls. |
@@ -562,7 +557,7 @@ impl Ctx { | |||
562 | }) | 557 | }) |
563 | .collect(); | 558 | .collect(); |
564 | let ast_id = self.source_ast_id_map.ast_id(impl_def); | 559 | let ast_id = self.source_ast_id_map.ast_id(impl_def); |
565 | let res = Impl { generic_params, target_trait, target_type, is_negative, items, ast_id }; | 560 | let res = Impl { generic_params, target_trait, self_ty, is_negative, items, ast_id }; |
566 | Some(id(self.data().impls.alloc(res))) | 561 | Some(id(self.data().impls.alloc(res))) |
567 | } | 562 | } |
568 | 563 | ||
@@ -748,10 +743,16 @@ impl Ctx { | |||
748 | self.data().vis.alloc(vis) | 743 | self.data().vis.alloc(vis) |
749 | } | 744 | } |
750 | 745 | ||
746 | fn lower_trait_ref(&mut self, trait_ref: &ast::Type) -> Option<Idx<TraitRef>> { | ||
747 | let trait_ref = TraitRef::from_ast(&self.body_ctx, trait_ref.clone())?; | ||
748 | Some(self.data().trait_refs.intern(trait_ref)) | ||
749 | } | ||
750 | |||
751 | fn lower_type_ref(&mut self, type_ref: &ast::Type) -> Idx<TypeRef> { | 751 | fn lower_type_ref(&mut self, type_ref: &ast::Type) -> Idx<TypeRef> { |
752 | let tyref = TypeRef::from_ast(&self.body_ctx, type_ref.clone()); | 752 | let tyref = TypeRef::from_ast(&self.body_ctx, type_ref.clone()); |
753 | self.data().type_refs.intern(tyref) | 753 | self.data().type_refs.intern(tyref) |
754 | } | 754 | } |
755 | |||
755 | fn lower_type_ref_opt(&mut self, type_ref: Option<ast::Type>) -> Idx<TypeRef> { | 756 | fn lower_type_ref_opt(&mut self, type_ref: Option<ast::Type>) -> Idx<TypeRef> { |
756 | match type_ref.map(|ty| self.lower_type_ref(&ty)) { | 757 | match type_ref.map(|ty| self.lower_type_ref(&ty)) { |
757 | Some(it) => it, | 758 | Some(it) => it, |