@@ -142,6 +142,7 @@ macro_rules! make_value_visitor {
142
142
self . walk_value( v)
143
143
}
144
144
/// Visit the given value as a union. No automatic recursion can happen here.
145
+ /// Also called for the fields of a generator, which may or may not be initialized.
145
146
#[ inline( always) ]
146
147
fn visit_union( & mut self , _v: Self :: V ) -> EvalResult <' tcx>
147
148
{
@@ -291,17 +292,28 @@ macro_rules! make_value_visitor {
291
292
// use that as an unambiguous signal for detecting primitives. Make sure
292
293
// we did not miss any primitive.
293
294
debug_assert!( fields > 0 ) ;
294
- self . visit_union( v) ? ;
295
+ self . visit_union( v)
295
296
} ,
296
297
layout:: FieldPlacement :: Arbitrary { ref offsets, .. } => {
297
- // FIXME: We collect in a vec because otherwise there are lifetime errors:
298
- // Projecting to a field needs (mutable!) access to `ecx`.
299
- let fields: Vec <EvalResult <' tcx, Self :: V >> =
300
- ( 0 ..offsets. len( ) ) . map( |i| {
301
- v. project_field( self . ecx( ) , i as u64 )
302
- } )
303
- . collect( ) ;
304
- self . visit_aggregate( v, fields. into_iter( ) ) ?;
298
+ // Special handling needed for generators: All but the first field
299
+ // (which is the state) are actually implicitly `MaybeUninit`, i.e.,
300
+ // they may or may not be initialized, so we cannot visit them.
301
+ match v. layout( ) . ty. sty {
302
+ ty:: Generator ( ..) => {
303
+ let field = v. project_field( self . ecx( ) , 0 ) ?;
304
+ self . visit_aggregate( v, std:: iter:: once( Ok ( field) ) )
305
+ }
306
+ _ => {
307
+ // FIXME: We collect in a vec because otherwise there are lifetime
308
+ // errors: Projecting to a field needs access to `ecx`.
309
+ let fields: Vec <EvalResult <' tcx, Self :: V >> =
310
+ ( 0 ..offsets. len( ) ) . map( |i| {
311
+ v. project_field( self . ecx( ) , i as u64 )
312
+ } )
313
+ . collect( ) ;
314
+ self . visit_aggregate( v, fields. into_iter( ) )
315
+ }
316
+ }
305
317
} ,
306
318
layout:: FieldPlacement :: Array { .. } => {
307
319
// Let's get an mplace first.
@@ -317,10 +329,9 @@ macro_rules! make_value_visitor {
317
329
. map( |f| f. and_then( |f| {
318
330
Ok ( Value :: from_mem_place( f) )
319
331
} ) ) ;
320
- self . visit_aggregate( v, iter) ? ;
332
+ self . visit_aggregate( v, iter)
321
333
}
322
334
}
323
- Ok ( ( ) )
324
335
}
325
336
}
326
337
}
0 commit comments