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: 4 additions & 1 deletion compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2291,8 +2291,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
fn_sig,
);
let name = inherent_method.name();
let inputs = fn_sig.inputs();
let expected_inputs =
if inherent_method.is_method() { &inputs[1..] } else { inputs };
if let Some(ref args) = call_args
&& fn_sig.inputs()[1..]
&& expected_inputs
.iter()
.eq_by(args, |expected, found| self.may_coerce(*expected, *found))
{
Expand Down
22 changes: 22 additions & 0 deletions tests/ui/attributes/rustc_confusables_assoc_fn.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#![feature(rustc_attrs)]

struct S;

impl S {
#[rustc_confusables("bar")]
fn foo() {}

#[rustc_confusables("baz")]
fn qux(&self, x: i32) {}
}

fn main() {
S::bar();
//~^ ERROR no function or associated item named `bar`
//~| HELP you might have meant to use `foo`

let s = S;
s.baz(10);
//~^ ERROR no method named `baz`
//~| HELP you might have meant to use `qux`
}
33 changes: 33 additions & 0 deletions tests/ui/attributes/rustc_confusables_assoc_fn.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
error[E0599]: no function or associated item named `bar` found for struct `S` in the current scope
--> $DIR/rustc_confusables_assoc_fn.rs:14:8
|
LL | struct S;
| -------- function or associated item `bar` not found for this struct
...
LL | S::bar();
| ^^^ function or associated item not found in `S`
|
help: you might have meant to use `foo`
|
LL - S::bar();
LL + S::foo();
|

error[E0599]: no method named `baz` found for struct `S` in the current scope
--> $DIR/rustc_confusables_assoc_fn.rs:19: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`
|
LL - s.baz(10);
LL + s.qux(10);
|

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0599`.
Loading