@@ -65,6 +65,7 @@ impl<'tcx> MirPass<'tcx> for Validator {
6565 storage_liveness,
6666 place_cache : Vec :: new ( ) ,
6767 value_cache : Vec :: new ( ) ,
68+ is_generator : tcx. generator_kind ( def_id) . is_some ( ) ,
6869 }
6970 . visit_body ( body) ;
7071 }
@@ -117,6 +118,7 @@ struct TypeChecker<'a, 'tcx> {
117118 storage_liveness : ResultsCursor < ' a , ' tcx , MaybeStorageLive > ,
118119 place_cache : Vec < PlaceRef < ' tcx > > ,
119120 value_cache : Vec < u128 > ,
121+ is_generator : bool ,
120122}
121123
122124impl < ' a , ' tcx > TypeChecker < ' a , ' tcx > {
@@ -323,16 +325,8 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
323325 }
324326 & ty:: Generator ( def_id, substs, _) => {
325327 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 ;
336330
337331 let Some ( & local) = layout. variant_fields [ var] . get ( f) else {
338332 fail_out_of_bounds ( self , location) ;
@@ -836,10 +830,10 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
836830 }
837831 }
838832 TerminatorKind :: Yield { resume, drop, .. } => {
839- if self . body . generator . is_none ( ) {
833+ if ! self . is_generator {
840834 self . fail ( location, "`Yield` cannot appear outside generator bodies" ) ;
841835 }
842- if self . mir_phase >= MirPhase :: Runtime ( RuntimePhase :: Initial ) {
836+ if self . mir_phase >= MirPhase :: Runtime ( RuntimePhase :: GeneratorsLowered ) {
843837 self . fail ( location, "`Yield` should have been replaced by generator lowering" ) ;
844838 }
845839 self . check_edge ( location, * resume, EdgeKind :: Normal ) ;
@@ -878,10 +872,10 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
878872 }
879873 }
880874 TerminatorKind :: GeneratorDrop => {
881- if self . body . generator . is_none ( ) {
875+ if ! self . is_generator {
882876 self . fail ( location, "`GeneratorDrop` cannot appear outside generator bodies" ) ;
883877 }
884- if self . mir_phase >= MirPhase :: Runtime ( RuntimePhase :: Initial ) {
878+ if self . mir_phase >= MirPhase :: Runtime ( RuntimePhase :: GeneratorsLowered ) {
885879 self . fail (
886880 location,
887881 "`GeneratorDrop` should have been replaced by generator lowering" ,
0 commit comments