@@ -313,11 +313,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
313
313
pub fn emit_inference_failure_err (
314
314
& self ,
315
315
body_id : Option < hir:: BodyId > ,
316
- span : Span ,
316
+ failure_span : Span ,
317
317
arg : GenericArg < ' tcx > ,
318
318
// FIXME(#94483): Either use this or remove it.
319
319
_impl_candidates : Vec < ty:: TraitRef < ' tcx > > ,
320
320
error_code : TypeAnnotationNeeded ,
321
+ should_label_span : bool ,
321
322
) -> DiagnosticBuilder < ' tcx , ErrorGuaranteed > {
322
323
let arg = self . resolve_vars_if_possible ( arg) ;
323
324
let arg_data = self . extract_inference_diagnostics_data ( arg, None ) ;
@@ -326,7 +327,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
326
327
// If we don't have any typeck results we're outside
327
328
// of a body, so we won't be able to get better info
328
329
// here.
329
- return self . bad_inference_failure_err ( span , arg_data, error_code) ;
330
+ return self . bad_inference_failure_err ( failure_span , arg_data, error_code) ;
330
331
} ;
331
332
let typeck_results = typeck_results. borrow ( ) ;
332
333
let typeck_results = & typeck_results;
@@ -338,7 +339,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
338
339
}
339
340
340
341
let Some ( InferSource { span, kind } ) = local_visitor. infer_source else {
341
- return self . bad_inference_failure_err ( span , arg_data, error_code)
342
+ return self . bad_inference_failure_err ( failure_span , arg_data, error_code)
342
343
} ;
343
344
344
345
let error_code = error_code. into ( ) ;
@@ -347,6 +348,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
347
348
& format ! ( "type annotations needed{}" , kind. ty_msg( self ) ) ,
348
349
error_code,
349
350
) ;
351
+
352
+ if should_label_span && !failure_span. overlaps ( span) {
353
+ err. span_label ( failure_span, "type must be known at this point" ) ;
354
+ }
355
+
350
356
match kind {
351
357
InferSourceKind :: LetBinding { insert_span, pattern_name, ty } => {
352
358
let suggestion_msg = if let Some ( name) = pattern_name {
0 commit comments