File tree 3 files changed +52
-2
lines changed
compiler/rustc_hir_typeck/src/method
3 files changed +52
-2
lines changed Original file line number Diff line number Diff line change @@ -3296,8 +3296,12 @@ fn print_disambiguation_help<'tcx>(
3296
3296
{
3297
3297
let def_kind_descr = tcx. def_kind_descr ( item. kind . as_def_kind ( ) , item. def_id ) ;
3298
3298
let item_name = item. ident ( tcx) ;
3299
- let rcvr_ref = tcx. fn_sig ( item. def_id ) . skip_binder ( ) . skip_binder ( ) . inputs ( ) [ 0 ]
3300
- . ref_mutability ( )
3299
+ let rcvr_ref = tcx. fn_sig ( item. def_id )
3300
+ . skip_binder ( )
3301
+ . skip_binder ( )
3302
+ . inputs ( )
3303
+ . get ( 0 )
3304
+ . and_then ( |ty| ty. ref_mutability ( ) )
3301
3305
. map_or ( "" , |mutbl| mutbl. ref_prefix_str ( ) ) ;
3302
3306
let args = format ! (
3303
3307
"({}{})" ,
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