File tree Expand file tree Collapse file tree 3 files changed +52
-2
lines changed
compiler/rustc_hir_typeck/src/method Expand file tree Collapse file tree 3 files changed +52
-2
lines changed Original file line number Diff line number Diff line change @@ -3264,8 +3264,12 @@ fn print_disambiguation_help<'tcx>(
3264
3264
{
3265
3265
let def_kind_descr = tcx.def_kind_descr(item.kind.as_def_kind(), item.def_id);
3266
3266
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())
3269
3273
.map_or("", |mutbl| mutbl.ref_prefix_str());
3270
3274
let args = format!(
3271
3275
"({}{})",
Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
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`.
You can’t perform that action at this time.
0 commit comments