@@ -313,11 +313,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
313313 pub fn emit_inference_failure_err (
314314 & self ,
315315 body_id : Option < hir:: BodyId > ,
316- span : Span ,
316+ failure_span : Span ,
317317 arg : GenericArg < ' tcx > ,
318318 // FIXME(#94483): Either use this or remove it.
319319 _impl_candidates : Vec < ty:: TraitRef < ' tcx > > ,
320320 error_code : TypeAnnotationNeeded ,
321+ should_label_span : bool ,
321322 ) -> DiagnosticBuilder < ' tcx , ErrorGuaranteed > {
322323 let arg = self . resolve_vars_if_possible ( arg) ;
323324 let arg_data = self . extract_inference_diagnostics_data ( arg, None ) ;
@@ -326,7 +327,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
326327 // If we don't have any typeck results we're outside
327328 // of a body, so we won't be able to get better info
328329 // 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) ;
330331 } ;
331332 let typeck_results = typeck_results. borrow ( ) ;
332333 let typeck_results = & typeck_results;
@@ -338,7 +339,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
338339 }
339340
340341 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)
342343 } ;
343344
344345 let error_code = error_code. into ( ) ;
@@ -347,6 +348,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
347348 & format ! ( "type annotations needed{}" , kind. ty_msg( self ) ) ,
348349 error_code,
349350 ) ;
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+
350356 match kind {
351357 InferSourceKind :: LetBinding { insert_span, pattern_name, ty } => {
352358 let suggestion_msg = if let Some ( name) = pattern_name {
0 commit comments