aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/hir_def/src/item_tree/lower.rs11
-rw-r--r--crates/hir_def/src/type_ref.rs16
-rw-r--r--crates/hir_ty/src/lower.rs5
3 files changed, 15 insertions, 17 deletions
diff --git a/crates/hir_def/src/item_tree/lower.rs b/crates/hir_def/src/item_tree/lower.rs
index 4b2af564e..8d3862811 100644
--- a/crates/hir_def/src/item_tree/lower.rs
+++ b/crates/hir_def/src/item_tree/lower.rs
@@ -536,7 +536,10 @@ impl Ctx {
536 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>> {
537 let generic_params = 537 let generic_params =
538 self.lower_generic_params_and_inner_items(GenericsOwner::Impl, impl_def); 538 self.lower_generic_params_and_inner_items(GenericsOwner::Impl, impl_def);
539 let target_trait = impl_def.trait_().map(|tr| self.lower_trait_ref(&tr)); 539 // FIXME: If trait lowering fails, due to a non PathType for example, we treat this impl
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));
540 let self_ty = self.lower_type_ref(&impl_def.self_ty()?); 543 let self_ty = self.lower_type_ref(&impl_def.self_ty()?);
541 let is_negative = impl_def.excl_token().is_some(); 544 let is_negative = impl_def.excl_token().is_some();
542 545
@@ -740,9 +743,9 @@ impl Ctx {
740 self.data().vis.alloc(vis) 743 self.data().vis.alloc(vis)
741 } 744 }
742 745
743 fn lower_trait_ref(&mut self, trait_ref: &ast::Type) -> Idx<TraitRef> { 746 fn lower_trait_ref(&mut self, trait_ref: &ast::Type) -> Option<Idx<TraitRef>> {
744 let trait_ref = TraitRef::from_ast(&self.body_ctx, trait_ref.clone()); 747 let trait_ref = TraitRef::from_ast(&self.body_ctx, trait_ref.clone())?;
745 self.data().trait_refs.intern(trait_ref) 748 Some(self.data().trait_refs.intern(trait_ref))
746 } 749 }
747 750
748 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> {
diff --git a/crates/hir_def/src/type_ref.rs b/crates/hir_def/src/type_ref.rs
index b7484ed0d..4c24aae94 100644
--- a/crates/hir_def/src/type_ref.rs
+++ b/crates/hir_def/src/type_ref.rs
@@ -52,21 +52,19 @@ impl Rawness {
52} 52}
53 53
54#[derive(Clone, PartialEq, Eq, Hash, Debug)] 54#[derive(Clone, PartialEq, Eq, Hash, Debug)]
55pub enum TraitRef { 55pub struct TraitRef {
56 Path(Path), 56 pub path: Path,
57 Error,
58} 57}
59 58
60impl TraitRef { 59impl TraitRef {
61 /// Converts an `ast::PathType` to a `hir::TraitRef`. 60 /// Converts an `ast::PathType` to a `hir::TraitRef`.
62 pub(crate) fn from_ast(ctx: &LowerCtx, node: ast::Type) -> Self { 61 pub(crate) fn from_ast(ctx: &LowerCtx, node: ast::Type) -> Option<Self> {
63 // FIXME: Use `Path::from_src` 62 // FIXME: Use `Path::from_src`
64 match node { 63 match node {
65 ast::Type::PathType(path) => path 64 ast::Type::PathType(path) => {
66 .path() 65 path.path().and_then(|it| ctx.lower_path(it)).map(|path| TraitRef { path })
67 .and_then(|it| ctx.lower_path(it)) 66 }
68 .map_or(TraitRef::Error, TraitRef::Path), 67 _ => None,
69 _ => TraitRef::Error,
70 } 68 }
71 } 69 }
72} 70}
diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs
index ee627e125..afbfa12d5 100644
--- a/crates/hir_ty/src/lower.rs
+++ b/crates/hir_ty/src/lower.rs
@@ -670,10 +670,7 @@ impl<'a> TyLoweringContext<'a> {
670 trait_ref: &HirTraitRef, 670 trait_ref: &HirTraitRef,
671 explicit_self_ty: Option<Ty>, 671 explicit_self_ty: Option<Ty>,
672 ) -> Option<TraitRef> { 672 ) -> Option<TraitRef> {
673 match trait_ref { 673 self.lower_trait_ref_from_path(&trait_ref.path, explicit_self_ty)
674 HirTraitRef::Path(path) => self.lower_trait_ref_from_path(path, explicit_self_ty),
675 HirTraitRef::Error => None,
676 }
677 } 674 }
678 675
679 fn trait_ref_substs_from_path( 676 fn trait_ref_substs_from_path(