@@ -69,13 +69,18 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
6969 error : MethodError < ' tcx > ,
7070 args : Option < & ' gcx [ hir:: Expr ] > ,
7171 ) {
72+ let orig_span = span;
73+ let mut span = span;
7274 // Avoid suggestions when we don't know what's going on.
7375 if rcvr_ty. references_error ( ) {
7476 return ;
7577 }
7678
77- let report_candidates = |err : & mut DiagnosticBuilder < ' _ > ,
78- mut sources : Vec < CandidateSource > | {
79+ let report_candidates = |
80+ span : Span ,
81+ err : & mut DiagnosticBuilder < ' _ > ,
82+ mut sources : Vec < CandidateSource > ,
83+ | {
7984 sources. sort( ) ;
8085 sources. dedup( ) ;
8186 // Dynamic limit to avoid hiding just one candidate, which is silly.
@@ -293,9 +298,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
293298 err. emit ( ) ;
294299 return ;
295300 } else {
301+ span = item_name. span ;
296302 let mut err = struct_span_err ! (
297303 tcx. sess,
298- item_name . span,
304+ span,
299305 E0599 ,
300306 "no {} named `{}` found for type `{}` in the current scope" ,
301307 item_kind,
@@ -305,7 +311,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
305311 if let Some ( suggestion) = suggestion {
306312 // enum variant
307313 err. span_suggestion (
308- item_name . span ,
314+ span,
309315 "did you mean" ,
310316 suggestion. to_string ( ) ,
311317 Applicability :: MaybeIncorrect ,
@@ -392,7 +398,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
392398 }
393399 } else {
394400 err. span_label ( span, format ! ( "{} not found in `{}`" , item_kind, ty_str) ) ;
395- self . tcx . sess . trait_methods_not_found . borrow_mut ( ) . insert ( span ) ;
401+ self . tcx . sess . trait_methods_not_found . borrow_mut ( ) . insert ( orig_span ) ;
396402 }
397403
398404 if self . is_fn_ty ( & rcvr_ty, span) {
@@ -434,9 +440,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
434440 self . ty_to_string( actual) , item_name) ) ;
435441 }
436442
437- report_candidates ( & mut err, static_sources) ;
443+ report_candidates ( span , & mut err, static_sources) ;
438444 } else if static_sources. len ( ) > 1 {
439- report_candidates ( & mut err, static_sources) ;
445+ report_candidates ( span , & mut err, static_sources) ;
440446 }
441447
442448 if !unsatisfied_predicates. is_empty ( ) {
@@ -481,7 +487,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
481487 "multiple applicable items in scope" ) ;
482488 err. span_label ( span, format ! ( "multiple `{}` found" , item_name) ) ;
483489
484- report_candidates ( & mut err, sources) ;
490+ report_candidates ( span , & mut err, sources) ;
485491 err. emit ( ) ;
486492 }
487493
0 commit comments