@@ -73,7 +73,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
73
73
} )
74
74
. or_else ( || {
75
75
self . give_name_if_anonymous_region_appears_in_output (
76
- infcx. tcx , mir, mir_def_id, fr, counter, diag)
76
+ infcx, mir, mir_def_id, fr, counter, diag)
77
77
} )
78
78
. unwrap_or_else ( || span_bug ! ( mir. span, "can't make a name for free region {:?}" , fr) )
79
79
}
@@ -577,38 +577,51 @@ impl<'tcx> RegionInferenceContext<'tcx> {
577
577
/// or be early bound (named, not in argument).
578
578
fn give_name_if_anonymous_region_appears_in_output (
579
579
& self ,
580
- tcx : TyCtxt < ' _ , ' _ , ' tcx > ,
580
+ infcx : & InferCtxt < ' _ , ' _ , ' tcx > ,
581
581
mir : & Mir < ' tcx > ,
582
582
mir_def_id : DefId ,
583
583
fr : RegionVid ,
584
584
counter : & mut usize ,
585
585
diag : & mut DiagnosticBuilder < ' _ > ,
586
586
) -> Option < InternedString > {
587
+ let tcx = infcx. tcx ;
588
+
587
589
let return_ty = self . universal_regions . unnormalized_output_ty ;
588
590
debug ! (
589
591
"give_name_if_anonymous_region_appears_in_output: return_ty = {:?}" ,
590
592
return_ty
591
593
) ;
592
- if !tcx. any_free_region_meets ( & return_ty, |r| r. to_region_vid ( ) == fr) {
594
+ if !infcx . tcx . any_free_region_meets ( & return_ty, |r| r. to_region_vid ( ) == fr) {
593
595
return None ;
594
596
}
595
597
596
- let mir_node_id = tcx. hir . as_local_node_id ( mir_def_id) . expect ( "non-local mir" ) ;
597
- let args_span = if let hir:: ExprKind :: Closure ( _, _, _, span, _)
598
+ let type_name = with_highlight_region ( fr, * counter, || {
599
+ infcx. extract_type_name ( & return_ty)
600
+ } ) ;
601
+
602
+ let mir_node_id = tcx. hir . as_local_node_id ( mir_def_id) . expect ( "non-local mir" ) ;
603
+
604
+ let ( return_span, mir_description) = if let hir:: ExprKind :: Closure ( _, _, _, span, gen_move)
598
605
= tcx. hir . expect_expr ( mir_node_id) . node
599
606
{
600
- span
607
+ (
608
+ tcx. sess . codemap ( ) . end_point ( span) ,
609
+ if gen_move. is_some ( ) { " of generator" } else { " of closure" }
610
+ )
601
611
} else {
602
- mir. span
612
+ // unreachable?
613
+ ( mir. span , "" )
603
614
} ;
604
615
605
- let region_name = self . synthesize_region_name ( counter) ;
606
616
diag. span_label (
607
- args_span ,
608
- format ! ( "lifetime `{}` appears in return type " , region_name ) ,
617
+ return_span ,
618
+ format ! ( "return type{} is {} " , mir_description , type_name ) ,
609
619
) ;
610
620
611
- Some ( region_name)
621
+ // This counter value will already have been used, so this function will increment it
622
+ // so the next value will be used next and return the region name that would have been
623
+ // used.
624
+ Some ( self . synthesize_region_name ( counter) )
612
625
}
613
626
614
627
/// Create a synthetic region named `'1`, incrementing the
0 commit comments