Remove TraitRef::Error
This commit is contained in:
parent
c2a63b97a8
commit
b4bb774381
@ -536,7 +536,10 @@ impl Ctx {
|
||||
fn lower_impl(&mut self, impl_def: &ast::Impl) -> Option<FileItemTreeId<Impl>> {
|
||||
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<TraitRef> {
|
||||
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<Idx<TraitRef>> {
|
||||
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<TypeRef> {
|
||||
|
@ -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<Self> {
|
||||
// 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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -670,10 +670,7 @@ impl<'a> TyLoweringContext<'a> {
|
||||
trait_ref: &HirTraitRef,
|
||||
explicit_self_ty: Option<Ty>,
|
||||
) -> Option<TraitRef> {
|
||||
match trait_ref {
|
||||
HirTraitRef::Path(path) => self.lower_trait_ref_from_path(path, explicit_self_ty),
|
||||
HirTraitRef::Error => None,
|
||||
}
|
||||
self.lower_trait_ref_from_path(&trait_ref.path, explicit_self_ty)
|
||||
}
|
||||
|
||||
fn trait_ref_substs_from_path(
|
||||
|
Loading…
x
Reference in New Issue
Block a user