From b4bb7743810b1e6ac8b897a465c430e9ed8d5c44 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 29 Mar 2021 18:39:58 +0200 Subject: Remove TraitRef::Error --- crates/hir_def/src/item_tree/lower.rs | 11 +++++++---- crates/hir_def/src/type_ref.rs | 16 +++++++--------- 2 files changed, 14 insertions(+), 13 deletions(-) (limited to 'crates/hir_def') 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 { fn lower_impl(&mut self, impl_def: &ast::Impl) -> Option> { let generic_params = self.lower_generic_params_and_inner_items(GenericsOwner::Impl, impl_def); - let target_trait = impl_def.trait_().map(|tr| self.lower_trait_ref(&tr)); + // FIXME: If trait lowering fails, due to a non PathType for example, we treat this impl + // as if it was an non-trait impl. Ideally we want to create a unique missing ref that only + // equals itself. + let target_trait = impl_def.trait_().and_then(|tr| self.lower_trait_ref(&tr)); let self_ty = self.lower_type_ref(&impl_def.self_ty()?); let is_negative = impl_def.excl_token().is_some(); @@ -740,9 +743,9 @@ impl Ctx { self.data().vis.alloc(vis) } - fn lower_trait_ref(&mut self, trait_ref: &ast::Type) -> Idx { - let trait_ref = TraitRef::from_ast(&self.body_ctx, trait_ref.clone()); - self.data().trait_refs.intern(trait_ref) + fn lower_trait_ref(&mut self, trait_ref: &ast::Type) -> Option> { + let trait_ref = TraitRef::from_ast(&self.body_ctx, trait_ref.clone())?; + Some(self.data().trait_refs.intern(trait_ref)) } fn lower_type_ref(&mut self, type_ref: &ast::Type) -> Idx { 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 { } #[derive(Clone, PartialEq, Eq, Hash, Debug)] -pub enum TraitRef { - Path(Path), - Error, +pub struct TraitRef { + pub path: Path, } impl TraitRef { /// Converts an `ast::PathType` to a `hir::TraitRef`. - pub(crate) fn from_ast(ctx: &LowerCtx, node: ast::Type) -> Self { + pub(crate) fn from_ast(ctx: &LowerCtx, node: ast::Type) -> Option { // FIXME: Use `Path::from_src` match node { - ast::Type::PathType(path) => path - .path() - .and_then(|it| ctx.lower_path(it)) - .map_or(TraitRef::Error, TraitRef::Path), - _ => TraitRef::Error, + ast::Type::PathType(path) => { + path.path().and_then(|it| ctx.lower_path(it)).map(|path| TraitRef { path }) + } + _ => None, } } } -- cgit v1.2.3