- if let TyKind::Path(QPath::Resolved(_, Path { res, .. })) = self_ty.kind {
- if !map.contains_key(res) {
- map.insert(
- *res,
- ExistingName {
- impl_methods: BTreeMap::new(),
- trait_methods: BTreeMap::new(),
- },
- );
- }
- let existing_name = map.get_mut(res).unwrap();
-
- match of_trait {
- Some(trait_ref) => {
- let mut methods_in_trait: BTreeSet<Symbol> = if_chain! {
- if let Some(Node::TraitRef(TraitRef { path, .. })) =
- cx.tcx.hir().find(trait_ref.hir_ref_id);
- if let Res::Def(DefKind::Trait, did) = path.res;
- then{
- // FIXME: if
- // `rustc_middle::ty::assoc::AssocItems::items` is public,
- // we can iterate its keys instead of `in_definition_order`,
- // which's more efficient
- cx.tcx
- .associated_items(did)
- .in_definition_order()
- .filter(|assoc_item| {
- matches!(assoc_item.kind, AssocKind::Fn)
- })
- .map(|assoc_item| assoc_item.name)
- .collect()
- }else{
- BTreeSet::new()
- }
- };
-
- let mut check_trait_method = |method_name: Symbol, trait_method_span: Span| {
- if let Some(impl_span) = existing_name.impl_methods.get(&method_name) {
- span_lint_and_then(
- cx,
- SAME_NAME_METHOD,
- *impl_span,
- "method's name is the same as an existing method in a trait",
- |diag| {
- diag.span_note(
- trait_method_span,
- &format!("existing `{}` defined here", method_name),
- );
- },
- );
- }
- if let Some(v) = existing_name.trait_methods.get_mut(&method_name) {
- v.push(trait_method_span);
- } else {
- existing_name.trait_methods.insert(method_name, vec![trait_method_span]);
- }
- };
+ if !map.contains_key(res) {
+ map.insert(
+ *res,
+ ExistingName {
+ impl_methods: BTreeMap::new(),
+ trait_methods: BTreeMap::new(),
+ },
+ );
+ }
+ let existing_name = map.get_mut(res).unwrap();