Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions compiler/rustc_attr_parsing/src/attributes/confusables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ impl<S: Stage> AttributeParser<S> for ConfusablesParser {
return None;
}

Some(AttributeKind::RustcConfusables {
symbols: self.confusables,
first_span: self.first_span.unwrap(),
})
Some(AttributeKind::RustcConfusables { confusables: self.confusables })
}
}
4 changes: 1 addition & 3 deletions compiler/rustc_hir/src/attrs/data_structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1331,9 +1331,7 @@ pub enum AttributeKind {

/// Represents `#[rustc_confusables]`.
RustcConfusables {
symbols: ThinVec<Symbol>,
// FIXME(jdonszelmann): remove when target validation code is moved
first_span: Span,
confusables: ThinVec<Symbol>,
},
/// Represents `#[rustc_const_stable]` and `#[rustc_const_unstable]`.
RustcConstStability {
Expand Down
31 changes: 9 additions & 22 deletions compiler/rustc_hir_typeck/src/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use rustc_span::def_id::{DefId, LocalDefId};
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;
Expand Down Expand Up @@ -2591,38 +2591,25 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
}

/// 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);
Copy link
Copy Markdown
Contributor

@JonathanBrouwer JonathanBrouwer Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old code ran this query only one time, the new code runs it multiple times, lets see if that matters

View changes since the review


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) {
Comment thread
jdonszelmann marked this conversation as resolved.
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;
}

Comment thread
JonathanBrouwer marked this conversation as resolved.
false
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2276,8 +2276,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
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 =
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/attributes/rustc_confusables.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`
|
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/attributes/rustc_confusables_assoc_fn.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`
|
Expand Down
10 changes: 5 additions & 5 deletions tests/ui/attributes/rustc_confusables_std_cases.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0599]: no method named `push` found for struct `BTreeSet<T, A>` 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`
|
Expand All @@ -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`
|
Expand All @@ -26,7 +26,7 @@ error[E0599]: no method named `push` found for struct `VecDeque<T, A>` 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
Expand Down Expand Up @@ -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`
|
Expand All @@ -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`
|
Expand Down
Loading