@@ -119,11 +119,16 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
119119 }
120120 } ;
121121
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+ } ;
127132 if let Some ( note_span) = note_span {
128133 // We have a span pointing to the method. Show note with snippet.
129134 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> {
137142 . unwrap ( ) ;
138143 let item_span = self . tcx . sess . codemap ( )
139144 . 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+ }
145157 err. help ( & format ! ( "to disambiguate the method call, write `{}::{}({}{})` \
146158 instead",
147159 self . tcx. item_path_str( trait_did) ,
@@ -368,7 +380,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
368380 if !static_sources. is_empty ( ) {
369381 err. note ( "found the following associated functions; to be used as methods, \
370382 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+ }
372391
373392 report_candidates ( & mut err, static_sources) ;
374393 }
@@ -468,9 +487,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
468487 } else {
469488 let limit = if candidates. len ( ) == 5 { 5 } else { 4 } ;
470489 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+ }
474498 }
475499 if candidates. len ( ) > limit {
476500 msg. push_str ( & format ! ( "\n and {} others" , candidates. len( ) - limit) ) ;
0 commit comments