@@ -9,6 +9,7 @@ use rustc_abi::{
99use rustc_hashes:: Hash64 ;
1010use rustc_index:: IndexVec ;
1111use rustc_middle:: bug;
12+ use rustc_middle:: mir:: CoroutineSavedLocal ;
1213use rustc_middle:: query:: Providers ;
1314use rustc_middle:: ty:: layout:: {
1415 FloatExt , HasTyCtxt , IntegerExt , LayoutCx , LayoutError , LayoutOf , TyAndLayout ,
@@ -382,28 +383,25 @@ fn layout_of_uncached<'tcx>(
382383 return Err ( error ( cx, LayoutError :: Unknown ( ty) ) ) ;
383384 } ;
384385
385- let local_layouts = info
386+ let local_layouts: IndexVec < _ , _ > = info
386387 . field_tys
387388 . iter ( )
388389 . map ( |local| {
389390 let field_ty = EarlyBinder :: bind ( local. ty ) ;
390391 let uninit_ty = Ty :: new_maybe_uninit ( tcx, field_ty. instantiate ( tcx, args) ) ;
391392 cx. spanned_layout_of ( uninit_ty, local. source_info . span )
392393 } )
393- . try_collect :: < IndexVec < _ , _ > > ( ) ?;
394-
395- let prefix_layouts = args
396- . as_coroutine ( )
397- . prefix_tys ( )
398- . iter ( )
399- . map ( |ty| cx. layout_of ( ty) )
400- . try_collect :: < IndexVec < _ , _ > > ( ) ?;
394+ . try_collect ( ) ?;
401395
396+ let relocated_upvars = IndexVec :: from_fn_n (
397+ |local : CoroutineSavedLocal | info. relocated_upvars . get ( & local) . copied ( ) ,
398+ info. field_tys . len ( ) ,
399+ ) ;
402400 let layout = cx
403401 . calc
404402 . coroutine (
405403 & local_layouts,
406- prefix_layouts ,
404+ & relocated_upvars ,
407405 & info. variant_fields ,
408406 & info. storage_conflicts ,
409407 |tag| TyAndLayout {
@@ -798,7 +796,11 @@ fn variant_info_for_coroutine<'tcx>(
798796 . then ( || Symbol :: intern ( & field_layout. ty . to_string ( ) ) ) ,
799797 }
800798 } )
801- . chain ( upvar_fields. iter ( ) . copied ( ) )
799+ . chain (
800+ if variant_idx == FIRST_VARIANT { & upvar_fields[ ..] } else { & [ ] }
801+ . iter ( )
802+ . copied ( ) ,
803+ )
802804 . collect ( ) ;
803805
804806 // If the variant has no state-specific fields, then it's the size of the upvars.
0 commit comments