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>> {
|
fn lower_impl(&mut self, impl_def: &ast::Impl) -> Option<FileItemTreeId<Impl>> {
|
||||||
let generic_params =
|
let generic_params =
|
||||||
self.lower_generic_params_and_inner_items(GenericsOwner::Impl, impl_def);
|
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 self_ty = self.lower_type_ref(&impl_def.self_ty()?);
|
||||||
let is_negative = impl_def.excl_token().is_some();
|
let is_negative = impl_def.excl_token().is_some();
|
||||||
|
|
||||||
@ -740,9 +743,9 @@ impl Ctx {
|
|||||||
self.data().vis.alloc(vis)
|
self.data().vis.alloc(vis)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lower_trait_ref(&mut self, trait_ref: &ast::Type) -> Idx<TraitRef> {
|
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());
|
let trait_ref = TraitRef::from_ast(&self.body_ctx, trait_ref.clone())?;
|
||||||
self.data().trait_refs.intern(trait_ref)
|
Some(self.data().trait_refs.intern(trait_ref))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lower_type_ref(&mut self, type_ref: &ast::Type) -> Idx<TypeRef> {
|
fn lower_type_ref(&mut self, type_ref: &ast::Type) -> Idx<TypeRef> {
|
||||||
|
@ -52,21 +52,19 @@ impl Rawness {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
|
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
|
||||||
pub enum TraitRef {
|
pub struct TraitRef {
|
||||||
Path(Path),
|
pub path: Path,
|
||||||
Error,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TraitRef {
|
impl TraitRef {
|
||||||
/// Converts an `ast::PathType` to a `hir::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`
|
// FIXME: Use `Path::from_src`
|
||||||
match node {
|
match node {
|
||||||
ast::Type::PathType(path) => path
|
ast::Type::PathType(path) => {
|
||||||
.path()
|
path.path().and_then(|it| ctx.lower_path(it)).map(|path| TraitRef { path })
|
||||||
.and_then(|it| ctx.lower_path(it))
|
}
|
||||||
.map_or(TraitRef::Error, TraitRef::Path),
|
_ => None,
|
||||||
_ => TraitRef::Error,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -670,10 +670,7 @@ impl<'a> TyLoweringContext<'a> {
|
|||||||
trait_ref: &HirTraitRef,
|
trait_ref: &HirTraitRef,
|
||||||
explicit_self_ty: Option<Ty>,
|
explicit_self_ty: Option<Ty>,
|
||||||
) -> Option<TraitRef> {
|
) -> Option<TraitRef> {
|
||||||
match trait_ref {
|
self.lower_trait_ref_from_path(&trait_ref.path, explicit_self_ty)
|
||||||
HirTraitRef::Path(path) => self.lower_trait_ref_from_path(path, explicit_self_ty),
|
|
||||||
HirTraitRef::Error => None,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn trait_ref_substs_from_path(
|
fn trait_ref_substs_from_path(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user