use crate::ResolutionError::*;
match &item.kind {
AssocItemKind::Const(_default, _ty, _expr) => {
- debug!("resolve_implementation AssocItemKind::Const",);
+ debug!("resolve_implementation AssocItemKind::Const");
// If this is a trait impl, ensure the const
// exists in trait
this.check_trait_item(
item.ident,
+ &item.kind,
ValueNS,
item.span,
- |n, s| ConstNotMemberOfTrait(n, s),
+ |i, s, c| ConstNotMemberOfTrait(i, s, c),
);
// We allow arbitrary const expressions inside of associated consts,
);
}
AssocItemKind::Fn(box FnKind(.., generics, _)) => {
+ debug!("resolve_implementation AssocItemKind::Fn");
// We also need a new scope for the impl item type parameters.
this.with_generic_param_rib(
generics,
// exists in trait
this.check_trait_item(
item.ident,
+ &item.kind,
ValueNS,
item.span,
- |n, s| MethodNotMemberOfTrait(n, s),
+ |i, s, c| MethodNotMemberOfTrait(i, s, c),
);
visit::walk_assoc_item(
_,
_,
)) => {
+ debug!("resolve_implementation AssocItemKind::TyAlias");
// We also need a new scope for the impl item type parameters.
this.with_generic_param_rib(
generics,
// exists in trait
this.check_trait_item(
item.ident,
+ &item.kind,
TypeNS,
item.span,
- |n, s| TypeNotMemberOfTrait(n, s),
+ |i, s, c| TypeNotMemberOfTrait(i, s, c),
);
visit::walk_assoc_item(
});
}
- fn check_trait_item<F>(&mut self, ident: Ident, ns: Namespace, span: Span, err: F)
- where
- F: FnOnce(Symbol, &str) -> ResolutionError<'_>,
+ fn check_trait_item<F>(
+ &mut self,
+ ident: Ident,
+ kind: &AssocItemKind,
+ ns: Namespace,
+ span: Span,
+ err: F,
+ ) where
+ F: FnOnce(Ident, &str, Option<Symbol>) -> ResolutionError<'_>,
{
// If there is a TraitRef in scope for an impl, then the method must be in the
// trait.
)
.is_err()
{
+ let candidate = self.find_similarly_named_assoc_item(ident.name, kind);
let path = &self.current_trait_ref.as_ref().unwrap().1.path;
- self.report_error(span, err(ident.name, &path_names_to_string(path)));
+ self.report_error(span, err(ident, &path_names_to_string(path), candidate));
}
}
}
if ns == ValueNS {
let item_name = path.last().unwrap().ident;
let traits = self.traits_in_scope(item_name, ns);
- self.r.trait_map.as_mut().unwrap().insert(id, traits);
+ self.r.trait_map.insert(id, traits);
}
if PrimTy::from_name(path[0].ident.name).is_some() {
// the field name so that we can do some nice error reporting
// later on in typeck.
let traits = self.traits_in_scope(ident, ValueNS);
- self.r.trait_map.as_mut().unwrap().insert(expr.id, traits);
+ self.r.trait_map.insert(expr.id, traits);
}
ExprKind::MethodCall(ref segment, ..) => {
debug!("(recording candidate traits for expr) recording traits for {}", expr.id);
let traits = self.traits_in_scope(segment.ident, ValueNS);
- self.r.trait_map.as_mut().unwrap().insert(expr.id, traits);
+ self.r.trait_map.insert(expr.id, traits);
}
_ => {
// Nothing to do.