Skip to content

Commit b4bb774

Browse files
committed
Remove TraitRef::Error
1 parent c2a63b9 commit b4bb774

File tree

3 files changed

+15
-17
lines changed

3 files changed

+15
-17
lines changed

crates/hir_def/src/item_tree/lower.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,10 @@ impl Ctx {
536536
fn lower_impl(&mut self, impl_def: &ast::Impl) -> Option<FileItemTreeId<Impl>> {
537537
let generic_params =
538538
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));
540543
let self_ty = self.lower_type_ref(&impl_def.self_ty()?);
541544
let is_negative = impl_def.excl_token().is_some();
542545

@@ -740,9 +743,9 @@ impl Ctx {
740743
self.data().vis.alloc(vis)
741744
}
742745

743-
fn lower_trait_ref(&mut self, trait_ref: &ast::Type) -> Idx<TraitRef> {
744-
let trait_ref = TraitRef::from_ast(&self.body_ctx, trait_ref.clone());
745-
self.data().trait_refs.intern(trait_ref)
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))
746749
}
747750

748751
fn lower_type_ref(&mut self, type_ref: &ast::Type) -> Idx<TypeRef> {

crates/hir_def/src/type_ref.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,19 @@ impl Rawness {
5252
}
5353

5454
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
55-
pub enum TraitRef {
56-
Path(Path),
57-
Error,
55+
pub struct TraitRef {
56+
pub path: Path,
5857
}
5958

6059
impl TraitRef {
6160
/// 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> {
6362
// FIXME: Use `Path::from_src`
6463
match node {
65-
ast::Type::PathType(path) => path
66-
.path()
67-
.and_then(|it| ctx.lower_path(it))
68-
.map_or(TraitRef::Error, TraitRef::Path),
69-
_ => TraitRef::Error,
64+
ast::Type::PathType(path) => {
65+
path.path().and_then(|it| ctx.lower_path(it)).map(|path| TraitRef { path })
66+
}
67+
_ => None,
7068
}
7169
}
7270
}

crates/hir_ty/src/lower.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -670,10 +670,7 @@ impl<'a> TyLoweringContext<'a> {
670670
trait_ref: &HirTraitRef,
671671
explicit_self_ty: Option<Ty>,
672672
) -> Option<TraitRef> {
673-
match trait_ref {
674-
HirTraitRef::Path(path) => self.lower_trait_ref_from_path(path, explicit_self_ty),
675-
HirTraitRef::Error => None,
676-
}
673+
self.lower_trait_ref_from_path(&trait_ref.path, explicit_self_ty)
677674
}
678675

679676
fn trait_ref_substs_from_path(

0 commit comments

Comments
 (0)