@@ -34,6 +34,7 @@ crate enum RegionNameSource {
34
34
MatchedAdtAndSegment ( Span ) ,
35
35
AnonRegionFromUpvar ( Span , String ) ,
36
36
AnonRegionFromOutput ( Span , String , String ) ,
37
+ AnonRegionFromYieldTy ( Span , String ) ,
37
38
}
38
39
39
40
impl RegionName {
@@ -48,7 +49,8 @@ impl RegionName {
48
49
RegionNameSource :: MatchedHirTy ( ..) |
49
50
RegionNameSource :: MatchedAdtAndSegment ( ..) |
50
51
RegionNameSource :: AnonRegionFromUpvar ( ..) |
51
- RegionNameSource :: AnonRegionFromOutput ( ..) => false ,
52
+ RegionNameSource :: AnonRegionFromOutput ( ..) |
53
+ RegionNameSource :: AnonRegionFromYieldTy ( ..) => false ,
52
54
}
53
55
}
54
56
@@ -105,6 +107,12 @@ impl RegionName {
105
107
format ! ( "return type{} is {}" , mir_description, type_name) ,
106
108
) ;
107
109
} ,
110
+ RegionNameSource :: AnonRegionFromYieldTy ( span, type_name) => {
111
+ diag. span_label (
112
+ * span,
113
+ format ! ( "yield type is {}" , type_name) ,
114
+ ) ;
115
+ }
108
116
RegionNameSource :: Static => { } ,
109
117
}
110
118
}
@@ -170,6 +178,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
170
178
self . give_name_if_anonymous_region_appears_in_output (
171
179
infcx, mir, mir_def_id, fr, counter,
172
180
)
181
+ } )
182
+ . or_else ( || {
183
+ self . give_name_if_anonymous_region_appears_in_yield_ty (
184
+ infcx, mir, mir_def_id, fr, counter,
185
+ )
173
186
} ) ;
174
187
175
188
debug ! ( "give_region_a_name: gave name {:?}" , value) ;
@@ -676,10 +689,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
676
689
"give_name_if_anonymous_region_appears_in_output: return_ty = {:?}" ,
677
690
return_ty
678
691
) ;
679
- if !infcx
680
- . tcx
681
- . any_free_region_meets ( & return_ty, |r| r. to_region_vid ( ) == fr)
682
- {
692
+ if !tcx. any_free_region_meets ( & return_ty, |r| r. to_region_vid ( ) == fr) {
683
693
return None ;
684
694
}
685
695
@@ -724,6 +734,57 @@ impl<'tcx> RegionInferenceContext<'tcx> {
724
734
} )
725
735
}
726
736
737
+ fn give_name_if_anonymous_region_appears_in_yield_ty (
738
+ & self ,
739
+ infcx : & InferCtxt < ' _ , ' _ , ' tcx > ,
740
+ mir : & Mir < ' tcx > ,
741
+ mir_def_id : DefId ,
742
+ fr : RegionVid ,
743
+ counter : & mut usize ,
744
+ ) -> Option < RegionName > {
745
+ // Note: generators from `async fn` yield `()`, so we don't have to
746
+ // worry about them here.
747
+ let yield_ty = self . universal_regions . yield_ty ?;
748
+ debug ! (
749
+ "give_name_if_anonymous_region_appears_in_yield_ty: yield_ty = {:?}" ,
750
+ yield_ty,
751
+ ) ;
752
+
753
+ let tcx = infcx. tcx ;
754
+
755
+ if !tcx. any_free_region_meets ( & yield_ty, |r| r. to_region_vid ( ) == fr) {
756
+ return None ;
757
+ }
758
+
759
+ let mut highlight = RegionHighlightMode :: default ( ) ;
760
+ highlight. highlighting_region_vid ( fr, * counter) ;
761
+ let type_name = infcx. extract_type_name ( & yield_ty, Some ( highlight) ) ;
762
+
763
+ let mir_node_id = tcx. hir ( ) . as_local_node_id ( mir_def_id) . expect ( "non-local mir" ) ;
764
+
765
+ let yield_span = match tcx. hir ( ) . get ( mir_node_id) {
766
+ hir:: Node :: Expr ( hir:: Expr {
767
+ node : hir:: ExprKind :: Closure ( _, _, _, span, _) ,
768
+ ..
769
+ } ) => (
770
+ tcx. sess . source_map ( ) . end_point ( * span)
771
+ ) ,
772
+ _ => mir. span ,
773
+ } ;
774
+
775
+ debug ! (
776
+ "give_name_if_anonymous_region_appears_in_yield_ty: \
777
+ type_name = {:?}, yield_span = {:?}",
778
+ yield_span,
779
+ type_name,
780
+ ) ;
781
+
782
+ Some ( RegionName {
783
+ name : self . synthesize_region_name ( counter) ,
784
+ source : RegionNameSource :: AnonRegionFromYieldTy ( yield_span, type_name) ,
785
+ } )
786
+ }
787
+
727
788
/// Creates a synthetic region named `'1`, incrementing the
728
789
/// counter.
729
790
fn synthesize_region_name ( & self , counter : & mut usize ) -> InternedString {
0 commit comments