Skip to content

Commit 99664b0

Browse files
Don't expect a rcvr in print_disambiguation_help
1 parent d8dbf7c commit 99664b0

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

compiler/rustc_hir_typeck/src/method/suggest.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -3264,8 +3264,12 @@ fn print_disambiguation_help<'tcx>(
32643264
{
32653265
let def_kind_descr = tcx.def_kind_descr(item.kind.as_def_kind(), item.def_id);
32663266
let item_name = item.ident(tcx);
3267-
let rcvr_ref = tcx.fn_sig(item.def_id).skip_binder().skip_binder().inputs()[0]
3268-
.ref_mutability()
3267+
let rcvr_ref = tcx.fn_sig(item.def_id)
3268+
.skip_binder()
3269+
.skip_binder()
3270+
.inputs()
3271+
.get(0)
3272+
.and_then(|ty| ty.ref_mutability())
32693273
.map_or("", |mutbl| mutbl.ref_prefix_str());
32703274
let args = format!(
32713275
"({}{})",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
struct Qux;
2+
3+
trait Foo {
4+
fn foo();
5+
}
6+
7+
trait FooBar {
8+
fn foo() {}
9+
}
10+
11+
fn main() {
12+
Qux.foo();
13+
//~^ ERROR no method named `foo` found for struct `Qux` in the current scope
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
error[E0599]: no method named `foo` found for struct `Qux` in the current scope
2+
--> $DIR/method-ambiguity-no-rcvr.rs:12:9
3+
|
4+
LL | struct Qux;
5+
| ---------- method `foo` not found for this struct
6+
...
7+
LL | Qux.foo();
8+
| ^^^ this is an associated function, not a method
9+
|
10+
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
11+
note: candidate #1 is defined in the trait `Foo`
12+
--> $DIR/method-ambiguity-no-rcvr.rs:4:5
13+
|
14+
LL | fn foo();
15+
| ^^^^^^^^^
16+
note: candidate #2 is defined in the trait `FooBar`
17+
--> $DIR/method-ambiguity-no-rcvr.rs:8:5
18+
|
19+
LL | fn foo() {}
20+
| ^^^^^^^^
21+
help: disambiguate the associated function for candidate #1
22+
|
23+
LL | <Qux as Foo>::foo(Qux);
24+
| ~~~~~~~~~~~~~~~~~~~~~~
25+
help: disambiguate the associated function for candidate #2
26+
|
27+
LL | <Qux as FooBar>::foo(Qux);
28+
| ~~~~~~~~~~~~~~~~~~~~~~~~~
29+
30+
error: aborting due to previous error
31+
32+
For more information about this error, try `rustc --explain E0599`.

0 commit comments

Comments
 (0)