@@ -146,6 +146,22 @@ impl<'tcx> MirSource<'tcx> {
146146    } 
147147} 
148148
149+ #[ derive( Clone ,  TyEncodable ,  TyDecodable ,  Debug ,  HashStable ,  TypeFoldable ) ]  
150+ pub  struct  GeneratorInfo < ' tcx >  { 
151+     /// The yield type of the function, if it is a generator. 
152+      pub  yield_ty :  Option < Ty < ' tcx > > , 
153+ 
154+     /// Generator drop glue. 
155+      pub  generator_drop :  Option < Body < ' tcx > > , 
156+ 
157+     /// The layout of a generator. Produced by the state transformation. 
158+      pub  generator_layout :  Option < GeneratorLayout < ' tcx > > , 
159+ 
160+     /// If this is a generator then record the type of source expression that caused this generator 
161+      /// to be created. 
162+      pub  generator_kind :  GeneratorKind , 
163+ } 
164+ 
149165/// The lowered representation of a single function. 
150166#[ derive( Clone ,  TyEncodable ,  TyDecodable ,  Debug ,  HashStable ,  TypeFoldable ) ]  
151167pub  struct  Body < ' tcx >  { 
@@ -166,18 +182,7 @@ pub struct Body<'tcx> {
166182     /// and used for debuginfo. Indexed by a `SourceScope`. 
167183     pub  source_scopes :  IndexVec < SourceScope ,  SourceScopeData < ' tcx > > , 
168184
169-     /// The yield type of the function, if it is a generator. 
170-      pub  yield_ty :  Option < Ty < ' tcx > > , 
171- 
172-     /// Generator drop glue. 
173-      pub  generator_drop :  Option < Box < Body < ' tcx > > > , 
174- 
175-     /// The layout of a generator. Produced by the state transformation. 
176-      pub  generator_layout :  Option < GeneratorLayout < ' tcx > > , 
177- 
178-     /// If this is a generator then record the type of source expression that caused this generator 
179-      /// to be created. 
180-      pub  generator_kind :  Option < GeneratorKind > , 
185+     pub  generator :  Option < Box < GeneratorInfo < ' tcx > > > , 
181186
182187    /// Declarations of locals. 
183188     /// 
@@ -259,10 +264,14 @@ impl<'tcx> Body<'tcx> {
259264            source, 
260265            basic_blocks, 
261266            source_scopes, 
262-             yield_ty :  None , 
263-             generator_drop :  None , 
264-             generator_layout :  None , 
265-             generator_kind, 
267+             generator :  generator_kind. map ( |generator_kind| { 
268+                 Box :: new ( GeneratorInfo  { 
269+                     yield_ty :  None , 
270+                     generator_drop :  None , 
271+                     generator_layout :  None , 
272+                     generator_kind, 
273+                 } ) 
274+             } ) , 
266275            local_decls, 
267276            user_type_annotations, 
268277            arg_count, 
@@ -289,16 +298,13 @@ impl<'tcx> Body<'tcx> {
289298            source :  MirSource :: item ( DefId :: local ( CRATE_DEF_INDEX ) ) , 
290299            basic_blocks, 
291300            source_scopes :  IndexVec :: new ( ) , 
292-             yield_ty :  None , 
293-             generator_drop :  None , 
294-             generator_layout :  None , 
301+             generator :  None , 
295302            local_decls :  IndexVec :: new ( ) , 
296303            user_type_annotations :  IndexVec :: new ( ) , 
297304            arg_count :  0 , 
298305            spread_arg :  None , 
299306            span :  DUMMY_SP , 
300307            required_consts :  Vec :: new ( ) , 
301-             generator_kind :  None , 
302308            var_debug_info :  Vec :: new ( ) , 
303309            is_polymorphic :  false , 
304310            predecessor_cache :  PredecessorCache :: new ( ) , 
@@ -480,6 +486,26 @@ impl<'tcx> Body<'tcx> {
480486    pub  fn  dominators ( & self )  -> Dominators < BasicBlock >  { 
481487        dominators ( self ) 
482488    } 
489+ 
490+     #[ inline]  
491+     pub  fn  yield_ty ( & self )  -> Option < Ty < ' tcx > >  { 
492+         self . generator . as_ref ( ) . and_then ( |generator| generator. yield_ty ) 
493+     } 
494+ 
495+     #[ inline]  
496+     pub  fn  generator_layout ( & self )  -> Option < & GeneratorLayout < ' tcx > >  { 
497+         self . generator . as_ref ( ) . and_then ( |generator| generator. generator_layout . as_ref ( ) ) 
498+     } 
499+ 
500+     #[ inline]  
501+     pub  fn  generator_drop ( & self )  -> Option < & Body < ' tcx > >  { 
502+         self . generator . as_ref ( ) . and_then ( |generator| generator. generator_drop . as_ref ( ) ) 
503+     } 
504+ 
505+     #[ inline]  
506+     pub  fn  generator_kind ( & self )  -> Option < GeneratorKind >  { 
507+         self . generator . as_ref ( ) . map ( |generator| generator. generator_kind ) 
508+     } 
483509} 
484510
485511#[ derive( Copy ,  Clone ,  PartialEq ,  Eq ,  Debug ,  TyEncodable ,  TyDecodable ,  HashStable ) ]  
0 commit comments