@@ -32,6 +32,7 @@ crate enum RegionNameSource {
3232 MatchedAdtAndSegment ( Span ) ,
3333 AnonRegionFromUpvar ( Span , String ) ,
3434 AnonRegionFromOutput ( Span , String , String ) ,
35+ AnonRegionFromYieldTy ( Span , String ) ,
3536}
3637
3738impl RegionName {
@@ -46,7 +47,8 @@ impl RegionName {
4647 RegionNameSource :: MatchedHirTy ( ..) |
4748 RegionNameSource :: MatchedAdtAndSegment ( ..) |
4849 RegionNameSource :: AnonRegionFromUpvar ( ..) |
49- RegionNameSource :: AnonRegionFromOutput ( ..) => false ,
50+ RegionNameSource :: AnonRegionFromOutput ( ..) |
51+ RegionNameSource :: AnonRegionFromYieldTy ( ..) => false ,
5052 }
5153 }
5254
@@ -103,6 +105,12 @@ impl RegionName {
103105 format ! ( "return type{} is {}" , mir_description, type_name) ,
104106 ) ;
105107 } ,
108+ RegionNameSource :: AnonRegionFromYieldTy ( span, type_name) => {
109+ diag. span_label (
110+ * span,
111+ format ! ( "yield type is {}" , type_name) ,
112+ ) ;
113+ }
106114 RegionNameSource :: Static => { } ,
107115 }
108116 }
@@ -167,6 +175,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
167175 self . give_name_if_anonymous_region_appears_in_output (
168176 infcx, mir, mir_def_id, fr, counter,
169177 )
178+ } )
179+ . or_else ( || {
180+ self . give_name_if_anonymous_region_appears_in_yield_ty (
181+ infcx, mir, mir_def_id, fr, counter,
182+ )
170183 } ) ;
171184
172185 debug ! ( "give_region_a_name: gave name {:?}" , value) ;
@@ -673,10 +686,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
673686 "give_name_if_anonymous_region_appears_in_output: return_ty = {:?}" ,
674687 return_ty
675688 ) ;
676- if !infcx
677- . tcx
678- . any_free_region_meets ( & return_ty, |r| r. to_region_vid ( ) == fr)
679- {
689+ if !tcx. any_free_region_meets ( & return_ty, |r| r. to_region_vid ( ) == fr) {
680690 return None ;
681691 }
682692
@@ -721,6 +731,57 @@ impl<'tcx> RegionInferenceContext<'tcx> {
721731 } )
722732 }
723733
734+ fn give_name_if_anonymous_region_appears_in_yield_ty (
735+ & self ,
736+ infcx : & InferCtxt < ' _ , ' _ , ' tcx > ,
737+ mir : & Mir < ' tcx > ,
738+ mir_def_id : DefId ,
739+ fr : RegionVid ,
740+ counter : & mut usize ,
741+ ) -> Option < RegionName > {
742+ // Note: generators from `async fn` yield `()`, so we don't have to
743+ // worry about them here.
744+ let yield_ty = self . universal_regions . yield_ty ?;
745+ debug ! (
746+ "give_name_if_anonymous_region_appears_in_yield_ty: yield_ty = {:?}" ,
747+ yield_ty,
748+ ) ;
749+
750+ let tcx = infcx. tcx ;
751+
752+ if !tcx. any_free_region_meets ( & yield_ty, |r| r. to_region_vid ( ) == fr) {
753+ return None ;
754+ }
755+
756+ let mut highlight = RegionHighlightMode :: default ( ) ;
757+ highlight. highlighting_region_vid ( fr, * counter) ;
758+ let type_name = infcx. extract_type_name ( & yield_ty, Some ( highlight) ) ;
759+
760+ let mir_node_id = tcx. hir ( ) . as_local_node_id ( mir_def_id) . expect ( "non-local mir" ) ;
761+
762+ let yield_span = match tcx. hir ( ) . get ( mir_node_id) {
763+ hir:: Node :: Expr ( hir:: Expr {
764+ node : hir:: ExprKind :: Closure ( _, _, _, span, _) ,
765+ ..
766+ } ) => (
767+ tcx. sess . source_map ( ) . end_point ( * span)
768+ ) ,
769+ _ => mir. span ,
770+ } ;
771+
772+ debug ! (
773+ "give_name_if_anonymous_region_appears_in_yield_ty: \
774+ type_name = {:?}, yield_span = {:?}",
775+ yield_span,
776+ type_name,
777+ ) ;
778+
779+ Some ( RegionName {
780+ name : self . synthesize_region_name ( counter) ,
781+ source : RegionNameSource :: AnonRegionFromYieldTy ( yield_span, type_name) ,
782+ } )
783+ }
784+
724785 /// Creates a synthetic region named `'1`, incrementing the
725786 /// counter.
726787 fn synthesize_region_name ( & self , counter : & mut usize ) -> InternedString {
0 commit comments