@@ -397,13 +397,49 @@ impl<'tcx> PlaceBuilder<'tcx> {
397
397
. all_fields ( )
398
398
. nth ( field_idx)
399
399
. unwrap_or_else ( || {
400
- bug ! ( "expected to take field idx {:?} of fields of {:?}" , field_idx, adt_def)
400
+ bug ! (
401
+ "expected to take field with idx {:?} of fields of {:?}" ,
402
+ field_idx,
403
+ adt_def
404
+ )
401
405
} )
402
406
. ty ( cx. tcx , substs) ,
403
407
ty:: Tuple ( elems) => elems. iter ( ) . nth ( field_idx) . unwrap_or_else ( || {
404
- bug ! ( "expected to take field idx {:?} of {:?}" , field_idx, elems)
408
+ bug ! ( "expected to take field with idx {:?} of {:?}" , field_idx, elems)
405
409
} ) ,
406
- _ => return None ,
410
+ ty:: Closure ( _, substs) => {
411
+ let substs = substs. as_closure ( ) ;
412
+ let Some ( f_ty) = substs. upvar_tys ( ) . nth ( field_idx) else {
413
+ bug ! ( "expected to take field with idx {:?} of {:?}" , field_idx, substs. upvar_tys( ) . collect:: <Vec <_>>( ) ) ;
414
+ } ;
415
+
416
+ f_ty
417
+ }
418
+ & ty:: Generator ( def_id, substs, _) => {
419
+ if let Some ( var) = variant_index {
420
+ let gen_body = cx. tcx . optimized_mir ( def_id) ;
421
+ let Some ( layout) = gen_body. generator_layout ( ) else {
422
+ bug ! ( "No generator layout for {:?}" , base_ty) ;
423
+ } ;
424
+
425
+ let Some ( & local) = layout. variant_fields [ var] . get ( field) else {
426
+ bug ! ( "expected to take field {:?} of {:?}" , field, layout. variant_fields[ var] ) ;
427
+ } ;
428
+
429
+ let Some ( & f_ty) = layout. field_tys . get ( local) else {
430
+ bug ! ( "expected to get element for {:?} in {:?}" , local, layout. field_tys) ;
431
+ } ;
432
+
433
+ f_ty
434
+ } else {
435
+ let Some ( f_ty) = substs. as_generator ( ) . prefix_tys ( ) . nth ( field. index ( ) ) else {
436
+ bug ! ( "expected to take index {:?} in {:?}" , field. index( ) , substs. as_generator( ) . prefix_tys( ) . collect:: <Vec <_>>( ) ) ;
437
+ } ;
438
+
439
+ f_ty
440
+ }
441
+ }
442
+ _ => bug ! ( "couldn't create field type, unexpected base type: {:?}" , base_ty) ,
407
443
} ;
408
444
409
445
Some ( cx. tcx . normalize_erasing_regions ( cx. param_env , field_ty) )
0 commit comments