@@ -61,7 +61,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
61
61
|| self . suggest_into ( err, expr, expr_ty, expected)
62
62
|| self . suggest_floating_point_literal ( err, expr, expected) ;
63
63
if !suggested {
64
- self . point_at_expr_source_of_inferred_type ( err, expr, expr_ty, expected) ;
64
+ self . point_at_expr_source_of_inferred_type ( err, expr, expr_ty, expected, expr . span ) ;
65
65
}
66
66
}
67
67
@@ -222,6 +222,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
222
222
expr : & hir:: Expr < ' _ > ,
223
223
found : Ty < ' tcx > ,
224
224
expected : Ty < ' tcx > ,
225
+ mismatch_span : Span ,
225
226
) -> bool {
226
227
let map = self . tcx . hir ( ) ;
227
228
@@ -281,7 +282,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
281
282
} ,
282
283
} ;
283
284
let mut prev = eraser. fold_ty ( ty) ;
284
- let mut prev_span = None ;
285
+ let mut prev_span: Option < Span > = None ;
285
286
286
287
for binding in expr_finder. uses {
287
288
// In every expression where the binding is referenced, we will look at that
@@ -334,13 +335,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
334
335
let arg = & args[ i] ;
335
336
let arg_ty = self . node_ty ( arg. hir_id ) ;
336
337
if !arg. span . overlaps ( mismatch_span) {
337
- err. span_label (
338
- arg. span ,
339
- & format ! (
340
- "this is of type `{arg_ty}`, which causes `{ident}` to be \
341
- inferred as `{ty}`",
342
- ) ,
343
- ) ;
338
+ err. span_label (
339
+ arg. span ,
340
+ & format ! (
341
+ "this is of type `{arg_ty}`, which causes `{ident}` to be \
342
+ inferred as `{ty}`",
343
+ ) ,
344
+ ) ;
344
345
}
345
346
param_args. insert ( param_ty, ( arg, arg_ty) ) ;
346
347
}
@@ -384,12 +385,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
384
385
&& self . can_eq ( self . param_env , ty, found) . is_ok ( )
385
386
{
386
387
// We only point at the first place where the found type was inferred.
388
+ if !segment. ident . span . overlaps ( mismatch_span) {
387
389
err. span_label (
388
390
segment. ident . span ,
389
391
with_forced_trimmed_paths ! ( format!(
390
392
"here the type of `{ident}` is inferred to be `{ty}`" ,
391
393
) ) ,
392
- ) ;
394
+ ) ; }
393
395
break ;
394
396
} else if !param_args. is_empty ( ) {
395
397
break ;
@@ -408,12 +410,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
408
410
// We use the *previous* span because if the type is known *here* it means
409
411
// it was *evaluated earlier*. We don't do this for method calls because we
410
412
// evaluate the method's self type eagerly, but not in any other case.
411
- err. span_label (
412
- span,
413
- with_forced_trimmed_paths ! ( format!(
414
- "here the type of `{ident}` is inferred to be `{ty}`" ,
415
- ) ) ,
416
- ) ;
413
+ if !span. overlaps ( mismatch_span) {
414
+ err. span_label (
415
+ span,
416
+ with_forced_trimmed_paths ! ( format!(
417
+ "here the type of `{ident}` is inferred to be `{ty}`" ,
418
+ ) ) ,
419
+ ) ;
420
+ }
417
421
break ;
418
422
}
419
423
prev = ty;
0 commit comments