@@ -69,13 +69,18 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
69
69
error : MethodError < ' tcx > ,
70
70
args : Option < & ' gcx [ hir:: Expr ] > ,
71
71
) {
72
+ let orig_span = span;
73
+ let mut span = span;
72
74
// Avoid suggestions when we don't know what's going on.
73
75
if rcvr_ty. references_error ( ) {
74
76
return ;
75
77
}
76
78
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
+ | {
79
84
sources. sort( ) ;
80
85
sources. dedup( ) ;
81
86
// Dynamic limit to avoid hiding just one candidate, which is silly.
@@ -293,9 +298,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
293
298
err. emit ( ) ;
294
299
return ;
295
300
} else {
301
+ span = item_name. span ;
296
302
let mut err = struct_span_err ! (
297
303
tcx. sess,
298
- item_name . span,
304
+ span,
299
305
E0599 ,
300
306
"no {} named `{}` found for type `{}` in the current scope" ,
301
307
item_kind,
@@ -305,7 +311,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
305
311
if let Some ( suggestion) = suggestion {
306
312
// enum variant
307
313
err. span_suggestion (
308
- item_name . span ,
314
+ span,
309
315
"did you mean" ,
310
316
suggestion. to_string ( ) ,
311
317
Applicability :: MaybeIncorrect ,
@@ -392,7 +398,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
392
398
}
393
399
} else {
394
400
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 ) ;
396
402
}
397
403
398
404
if self . is_fn_ty ( & rcvr_ty, span) {
@@ -434,9 +440,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
434
440
self . ty_to_string( actual) , item_name) ) ;
435
441
}
436
442
437
- report_candidates ( & mut err, static_sources) ;
443
+ report_candidates ( span , & mut err, static_sources) ;
438
444
} else if static_sources. len ( ) > 1 {
439
- report_candidates ( & mut err, static_sources) ;
445
+ report_candidates ( span , & mut err, static_sources) ;
440
446
}
441
447
442
448
if !unsatisfied_predicates. is_empty ( ) {
@@ -481,7 +487,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
481
487
"multiple applicable items in scope" ) ;
482
488
err. span_label ( span, format ! ( "multiple `{}` found" , item_name) ) ;
483
489
484
- report_candidates ( & mut err, sources) ;
490
+ report_candidates ( span , & mut err, sources) ;
485
491
err. emit ( ) ;
486
492
}
487
493
0 commit comments