diff --git a/compiler/rustc_attr_parsing/src/attributes/confusables.rs b/compiler/rustc_attr_parsing/src/attributes/confusables.rs index e4634547358c..4041ce85fa98 100644 --- a/compiler/rustc_attr_parsing/src/attributes/confusables.rs +++ b/compiler/rustc_attr_parsing/src/attributes/confusables.rs @@ -44,9 +44,6 @@ fn finalize(self, _cx: &FinalizeContext<'_, '_, S>) -> Option { return None; } - Some(AttributeKind::RustcConfusables { - symbols: self.confusables, - first_span: self.first_span.unwrap(), - }) + Some(AttributeKind::RustcConfusables { confusables: self.confusables }) } } diff --git a/compiler/rustc_hir/src/attrs/data_structures.rs b/compiler/rustc_hir/src/attrs/data_structures.rs index 48b03bc94659..724df6642f2e 100644 --- a/compiler/rustc_hir/src/attrs/data_structures.rs +++ b/compiler/rustc_hir/src/attrs/data_structures.rs @@ -1331,9 +1331,7 @@ pub enum AttributeKind { /// Represents `#[rustc_confusables]`. RustcConfusables { - symbols: ThinVec, - // FIXME(jdonszelmann): remove when target validation code is moved - first_span: Span, + confusables: ThinVec, }, /// Represents `#[rustc_const_stable]` and `#[rustc_const_unstable]`. RustcConstStability { diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs index c7442373353e..ba17bfa2ed94 100644 --- a/compiler/rustc_hir_typeck/src/method/probe.rs +++ b/compiler/rustc_hir_typeck/src/method/probe.rs @@ -26,7 +26,7 @@ use rustc_span::edit_distance::{ edit_distance_with_substrings, find_best_match_for_name_with_substrings, }; -use rustc_span::{DUMMY_SP, Ident, Span, Symbol, sym}; +use rustc_span::{DUMMY_SP, Ident, Span, Symbol}; use rustc_trait_selection::error_reporting::infer::need_type_info::TypeAnnotationNeeded; use rustc_trait_selection::infer::InferCtxtExt as _; use rustc_trait_selection::solve::Goal; @@ -2591,38 +2591,25 @@ fn is_relevant_kind_for_mode(&self, kind: ty::AssocKind) -> bool { } /// Determine if the associated item with the given DefId matches - /// the desired name via a doc alias. + /// the desired name via a doc alias or rustc_confusables fn matches_by_doc_alias(&self, def_id: DefId) -> bool { let Some(method) = self.method_name else { return false; }; - let Some(local_def_id) = def_id.as_local() else { - return false; - }; - let hir_id = self.fcx.tcx.local_def_id_to_hir_id(local_def_id); - let attrs = self.fcx.tcx.hir_attrs(hir_id); - if let Some(d) = find_attr!(attrs, Doc(d) => d) + if let Some(d) = find_attr!(self.tcx, def_id, Doc(d) => d) && d.aliases.contains_key(&method.name) { return true; } - for attr in attrs { - if attr.has_name(sym::rustc_confusables) { - let Some(confusables) = attr.meta_item_list() else { - continue; - }; - // #[rustc_confusables("foo", "bar"))] - for n in confusables { - if let Some(lit) = n.lit() - && method.name == lit.symbol - { - return true; - } - } - } + if let Some(confusables) = + find_attr!(self.tcx, def_id, RustcConfusables{ confusables } => confusables) + && confusables.contains(&method.name) + { + return true; } + false } diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index fa90c0c6269c..3fcc3f03f7aa 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -2276,8 +2276,8 @@ pub(crate) fn confusable_method_name( for inherent_method in self.tcx.associated_items(inherent_impl_did).in_definition_order() { - if let Some(candidates) = find_attr!(self.tcx, inherent_method.def_id, RustcConfusables{symbols, ..} => symbols) - && candidates.contains(&item_name.name) + if let Some(confusables) = find_attr!(self.tcx, inherent_method.def_id, RustcConfusables{confusables} => confusables) + && confusables.contains(&item_name.name) && inherent_method.is_fn() { let args = diff --git a/tests/ui/attributes/rustc_confusables.stderr b/tests/ui/attributes/rustc_confusables.stderr index c714257ee77d..81bf0db4ab04 100644 --- a/tests/ui/attributes/rustc_confusables.stderr +++ b/tests/ui/attributes/rustc_confusables.stderr @@ -51,7 +51,7 @@ error[E0599]: no method named `push` found for struct `rustc_confusables_across_ --> $DIR/rustc_confusables.rs:17:7 | LL | x.push(); - | ^^^^ method not found in `rustc_confusables_across_crate::BTreeSet` + | ^^^^ | help: you might have meant to use `insert` | diff --git a/tests/ui/attributes/rustc_confusables_assoc_fn.stderr b/tests/ui/attributes/rustc_confusables_assoc_fn.stderr index da5cf27632ac..87bdac598480 100644 --- a/tests/ui/attributes/rustc_confusables_assoc_fn.stderr +++ b/tests/ui/attributes/rustc_confusables_assoc_fn.stderr @@ -20,7 +20,7 @@ LL | struct S; | -------- method `baz` not found for this struct ... LL | s.baz(10); - | ^^^ method not found in `S` + | ^^^ | help: you might have meant to use `qux` | diff --git a/tests/ui/attributes/rustc_confusables_std_cases.stderr b/tests/ui/attributes/rustc_confusables_std_cases.stderr index 771c0c6dfe98..f58950f3cc61 100644 --- a/tests/ui/attributes/rustc_confusables_std_cases.stderr +++ b/tests/ui/attributes/rustc_confusables_std_cases.stderr @@ -2,7 +2,7 @@ error[E0599]: no method named `push` found for struct `BTreeSet` in the cu --> $DIR/rustc_confusables_std_cases.rs:6:7 | LL | x.push(1); - | ^^^^ method not found in `BTreeSet<_>` + | ^^^^ | help: you might have meant to use `insert` | @@ -14,7 +14,7 @@ error[E0599]: no method named `push_back` found for struct `Vec<_>` in the curre --> $DIR/rustc_confusables_std_cases.rs:9:7 | LL | x.push_back(1); - | ^^^^^^^^^ method not found in `Vec<_>` + | ^^^^^^^^^ | help: you might have meant to use `push` | @@ -26,7 +26,7 @@ error[E0599]: no method named `push` found for struct `VecDeque` in the cu --> $DIR/rustc_confusables_std_cases.rs:12:7 | LL | x.push(1); - | ^^^^ method not found in `VecDeque<_>` + | ^^^^ | note: there's an earlier shadowed binding `x` of type `Vec<_>` that has method `push` available --> $DIR/rustc_confusables_std_cases.rs:8:9 @@ -104,7 +104,7 @@ error[E0599]: no method named `append` found for struct `String` in the current --> $DIR/rustc_confusables_std_cases.rs:24:19 | LL | String::new().append(""); - | ^^^^^^ method not found in `String` + | ^^^^^^ | help: you might have meant to use `push_str` | @@ -116,7 +116,7 @@ error[E0599]: no method named `get_line` found for struct `Stdin` in the current --> $DIR/rustc_confusables_std_cases.rs:28:11 | LL | stdin.get_line(&mut buffer).unwrap(); - | ^^^^^^^^ method not found in `Stdin` + | ^^^^^^^^ | help: you might have meant to use `read_line` |