@@ -119,11 +119,16 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
119
119
}
120
120
} ;
121
121
122
- let note_str = format ! ( "candidate #{} is defined in an impl{} \
123
- for the type `{}`",
124
- idx + 1 ,
125
- insertion,
126
- impl_ty) ;
122
+ let note_str = if sources. len ( ) > 1 {
123
+ format ! ( "candidate #{} is defined in an impl{} for the type `{}`" ,
124
+ idx + 1 ,
125
+ insertion,
126
+ impl_ty)
127
+ } else {
128
+ format ! ( "the candidate is defined in an impl{} for the type `{}`" ,
129
+ insertion,
130
+ impl_ty)
131
+ } ;
127
132
if let Some ( note_span) = note_span {
128
133
// We have a span pointing to the method. Show note with snippet.
129
134
err. span_note ( self . tcx . sess . codemap ( ) . def_span ( note_span) , & note_str) ;
@@ -137,11 +142,18 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
137
142
. unwrap ( ) ;
138
143
let item_span = self . tcx . sess . codemap ( )
139
144
. def_span ( self . tcx . def_span ( item. def_id ) ) ;
140
- span_note ! ( err,
141
- item_span,
142
- "candidate #{} is defined in the trait `{}`" ,
143
- idx + 1 ,
144
- self . tcx. item_path_str( trait_did) ) ;
145
+ if sources. len ( ) > 1 {
146
+ span_note ! ( err,
147
+ item_span,
148
+ "candidate #{} is defined in the trait `{}`" ,
149
+ idx + 1 ,
150
+ self . tcx. item_path_str( trait_did) ) ;
151
+ } else {
152
+ span_note ! ( err,
153
+ item_span,
154
+ "the candidate is defined in the trait `{}`" ,
155
+ self . tcx. item_path_str( trait_did) ) ;
156
+ }
145
157
err. help ( & format ! ( "to disambiguate the method call, write `{}::{}({}{})` \
146
158
instead",
147
159
self . tcx. item_path_str( trait_did) ,
@@ -368,7 +380,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
368
380
if !static_sources. is_empty ( ) {
369
381
err. note ( "found the following associated functions; to be used as methods, \
370
382
functions must have a `self` parameter") ;
371
- err. help ( & format ! ( "try with `{}::{}`" , self . ty_to_string( actual) , item_name) ) ;
383
+ if let Some ( expr) = rcvr_expr {
384
+ err. span_suggestion ( expr. span . to ( span) ,
385
+ "use associated function syntax intead" ,
386
+ format ! ( "{}::{}" , self . ty_to_string( actual) , item_name) ) ;
387
+ } else {
388
+ err. help ( & format ! ( "try with `{}::{}`" ,
389
+ self . ty_to_string( actual) , item_name) ) ;
390
+ }
372
391
373
392
report_candidates ( & mut err, static_sources) ;
374
393
}
@@ -468,9 +487,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
468
487
} else {
469
488
let limit = if candidates. len ( ) == 5 { 5 } else { 4 } ;
470
489
for ( i, trait_did) in candidates. iter ( ) . take ( limit) . enumerate ( ) {
471
- msg. push_str ( & format ! ( "\n candidate #{}: `use {};`" ,
472
- i + 1 ,
473
- self . tcx. item_path_str( * trait_did) ) ) ;
490
+ if candidates. len ( ) > 1 {
491
+ msg. push_str ( & format ! ( "\n candidate #{}: `use {};`" ,
492
+ i + 1 ,
493
+ self . tcx. item_path_str( * trait_did) ) ) ;
494
+ } else {
495
+ msg. push_str ( & format ! ( "\n `use {};`" ,
496
+ self . tcx. item_path_str( * trait_did) ) ) ;
497
+ }
474
498
}
475
499
if candidates. len ( ) > limit {
476
500
msg. push_str ( & format ! ( "\n and {} others" , candidates. len( ) - limit) ) ;
0 commit comments