@@ -9,6 +9,7 @@ use rustc_abi::{
9
9
use rustc_hashes:: Hash64 ;
10
10
use rustc_index:: IndexVec ;
11
11
use rustc_middle:: bug;
12
+ use rustc_middle:: mir:: CoroutineSavedLocal ;
12
13
use rustc_middle:: query:: Providers ;
13
14
use rustc_middle:: ty:: layout:: {
14
15
FloatExt , HasTyCtxt , IntegerExt , LayoutCx , LayoutError , LayoutOf , TyAndLayout ,
@@ -410,28 +411,25 @@ fn layout_of_uncached<'tcx>(
410
411
return Err ( error ( cx, LayoutError :: Unknown ( ty) ) ) ;
411
412
} ;
412
413
413
- let local_layouts = info
414
+ let local_layouts: IndexVec < _ , _ > = info
414
415
. field_tys
415
416
. iter ( )
416
417
. map ( |local| {
417
418
let field_ty = EarlyBinder :: bind ( local. ty ) ;
418
419
let uninit_ty = Ty :: new_maybe_uninit ( tcx, field_ty. instantiate ( tcx, args) ) ;
419
420
cx. spanned_layout_of ( uninit_ty, local. source_info . span )
420
421
} )
421
- . try_collect :: < IndexVec < _ , _ > > ( ) ?;
422
-
423
- let prefix_layouts = args
424
- . as_coroutine ( )
425
- . prefix_tys ( )
426
- . iter ( )
427
- . map ( |ty| cx. layout_of ( ty) )
428
- . try_collect :: < IndexVec < _ , _ > > ( ) ?;
422
+ . try_collect ( ) ?;
429
423
424
+ let relocated_upvars = IndexVec :: from_fn_n (
425
+ |local : CoroutineSavedLocal | info. relocated_upvars . get ( & local) . copied ( ) ,
426
+ info. field_tys . len ( ) ,
427
+ ) ;
430
428
let layout = cx
431
429
. calc
432
430
. coroutine (
433
431
& local_layouts,
434
- prefix_layouts ,
432
+ & relocated_upvars ,
435
433
& info. variant_fields ,
436
434
& info. storage_conflicts ,
437
435
|tag| TyAndLayout {
@@ -826,7 +824,11 @@ fn variant_info_for_coroutine<'tcx>(
826
824
. then ( || Symbol :: intern ( & field_layout. ty . to_string ( ) ) ) ,
827
825
}
828
826
} )
829
- . chain ( upvar_fields. iter ( ) . copied ( ) )
827
+ . chain (
828
+ if variant_idx == FIRST_VARIANT { & upvar_fields[ ..] } else { & [ ] }
829
+ . iter ( )
830
+ . copied ( ) ,
831
+ )
830
832
. collect ( ) ;
831
833
832
834
// If the variant has no state-specific fields, then it's the size of the upvars.
0 commit comments