@@ -65,6 +65,7 @@ impl<'tcx> MirPass<'tcx> for Validator {
65
65
storage_liveness,
66
66
place_cache : Vec :: new ( ) ,
67
67
value_cache : Vec :: new ( ) ,
68
+ is_generator : tcx. generator_kind ( def_id) . is_some ( ) ,
68
69
}
69
70
. visit_body ( body) ;
70
71
}
@@ -117,6 +118,7 @@ struct TypeChecker<'a, 'tcx> {
117
118
storage_liveness : ResultsCursor < ' a , ' tcx , MaybeStorageLive > ,
118
119
place_cache : Vec < PlaceRef < ' tcx > > ,
119
120
value_cache : Vec < u128 > ,
121
+ is_generator : bool ,
120
122
}
121
123
122
124
impl < ' a , ' tcx > TypeChecker < ' a , ' tcx > {
@@ -323,16 +325,8 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
323
325
}
324
326
& ty:: Generator ( def_id, substs, _) => {
325
327
let f_ty = if let Some ( var) = parent_ty. variant_index {
326
- let gen_body = if def_id == self . body . source . def_id ( ) {
327
- self . body
328
- } else {
329
- self . tcx . optimized_mir ( def_id)
330
- } ;
331
-
332
- let Some ( layout) = gen_body. generator_layout ( ) else {
333
- self . fail ( location, format ! ( "No generator layout for {:?}" , parent_ty) ) ;
334
- return ;
335
- } ;
328
+ let generator_info = self . tcx . mir_generator_info ( def_id) ;
329
+ let layout = & generator_info. generator_layout ;
336
330
337
331
let Some ( & local) = layout. variant_fields [ var] . get ( f) else {
338
332
fail_out_of_bounds ( self , location) ;
@@ -836,10 +830,10 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
836
830
}
837
831
}
838
832
TerminatorKind :: Yield { resume, drop, .. } => {
839
- if self . body . generator . is_none ( ) {
833
+ if ! self . is_generator {
840
834
self . fail ( location, "`Yield` cannot appear outside generator bodies" ) ;
841
835
}
842
- if self . mir_phase >= MirPhase :: Runtime ( RuntimePhase :: Initial ) {
836
+ if self . mir_phase >= MirPhase :: Runtime ( RuntimePhase :: GeneratorsLowered ) {
843
837
self . fail ( location, "`Yield` should have been replaced by generator lowering" ) ;
844
838
}
845
839
self . check_edge ( location, * resume, EdgeKind :: Normal ) ;
@@ -878,10 +872,10 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
878
872
}
879
873
}
880
874
TerminatorKind :: GeneratorDrop => {
881
- if self . body . generator . is_none ( ) {
875
+ if ! self . is_generator {
882
876
self . fail ( location, "`GeneratorDrop` cannot appear outside generator bodies" ) ;
883
877
}
884
- if self . mir_phase >= MirPhase :: Runtime ( RuntimePhase :: Initial ) {
878
+ if self . mir_phase >= MirPhase :: Runtime ( RuntimePhase :: GeneratorsLowered ) {
885
879
self . fail (
886
880
location,
887
881
"`GeneratorDrop` should have been replaced by generator lowering" ,
0 commit comments