@@ -69,13 +69,17 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
6969 error : MethodError < ' tcx > ,
7070 args : Option < & ' gcx [ hir:: Expr ] > ,
7171 ) {
72+ let mut span = span;
7273 // Avoid suggestions when we don't know what's going on.
7374 if rcvr_ty. references_error ( ) {
7475 return ;
7576 }
7677
77- let report_candidates = |err : & mut DiagnosticBuilder < ' _ > ,
78- mut sources : Vec < CandidateSource > | {
78+ let report_candidates = |
79+ span : Span ,
80+ err : & mut DiagnosticBuilder < ' _ > ,
81+ mut sources : Vec < CandidateSource > ,
82+ | {
7983 sources. sort( ) ;
8084 sources. dedup( ) ;
8185 // Dynamic limit to avoid hiding just one candidate, which is silly.
@@ -293,9 +297,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
293297 err. emit ( ) ;
294298 return ;
295299 } else {
300+ span = item_name. span ;
296301 let mut err = struct_span_err ! (
297302 tcx. sess,
298- item_name . span,
303+ span,
299304 E0599 ,
300305 "no {} named `{}` found for type `{}` in the current scope" ,
301306 item_kind,
@@ -305,7 +310,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
305310 if let Some ( suggestion) = suggestion {
306311 // enum variant
307312 err. span_suggestion (
308- item_name . span ,
313+ span,
309314 "did you mean" ,
310315 suggestion. to_string ( ) ,
311316 Applicability :: MaybeIncorrect ,
@@ -434,9 +439,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
434439 self . ty_to_string( actual) , item_name) ) ;
435440 }
436441
437- report_candidates ( & mut err, static_sources) ;
442+ report_candidates ( span , & mut err, static_sources) ;
438443 } else if static_sources. len ( ) > 1 {
439- report_candidates ( & mut err, static_sources) ;
444+ report_candidates ( span , & mut err, static_sources) ;
440445 }
441446
442447 if !unsatisfied_predicates. is_empty ( ) {
@@ -481,7 +486,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
481486 "multiple applicable items in scope" ) ;
482487 err. span_label ( span, format ! ( "multiple `{}` found" , item_name) ) ;
483488
484- report_candidates ( & mut err, sources) ;
489+ report_candidates ( span , & mut err, sources) ;
485490 err. emit ( ) ;
486491 }
487492
0 commit comments