@@ -605,6 +605,12 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
605605 }
606606
607607 ty:: Generator ( def_id, ref substs, _) => {
608+ // FIXME(tmandry): For fields that are repeated in multiple
609+ // variants in the GeneratorLayout, we need code to ensure that
610+ // the offset of these fields never change. Right now this is
611+ // not an issue since every variant has every field, but once we
612+ // optimize this we have to be more careful.
613+
608614 let discr_index = substs. prefix_tys ( def_id, tcx) . count ( ) ;
609615 let prefix_tys = substs. prefix_tys ( def_id, tcx)
610616 . chain ( iter:: once ( substs. discr_ty ( tcx) ) ) ;
@@ -1691,7 +1697,7 @@ impl<'a, 'tcx, C> TyLayoutMethods<'tcx, C> for Ty<'tcx>
16911697
16921698 fn field ( this : TyLayout < ' tcx > , cx : & C , i : usize ) -> C :: TyLayout {
16931699 let tcx = cx. tcx ( ) ;
1694- let handle_discriminant = |discr : & Scalar | -> C :: TyLayout {
1700+ let discr_layout = |discr : & Scalar | -> C :: TyLayout {
16951701 let layout = LayoutDetails :: scalar ( cx, discr. clone ( ) ) ;
16961702 MaybeResult :: from_ok ( TyLayout {
16971703 details : tcx. intern_layout ( layout) ,
@@ -1781,7 +1787,7 @@ impl<'a, 'tcx, C> TyLayoutMethods<'tcx, C> for Ty<'tcx>
17811787 }
17821788 Variants :: Multiple { ref discr, discr_index, .. } => {
17831789 if i == discr_index {
1784- return handle_discriminant ( discr) ;
1790+ return discr_layout ( discr) ;
17851791 }
17861792 substs. prefix_tys ( def_id, tcx) . nth ( i) . unwrap ( )
17871793 }
@@ -1805,7 +1811,7 @@ impl<'a, 'tcx, C> TyLayoutMethods<'tcx, C> for Ty<'tcx>
18051811 // Discriminant field for enums (where applicable).
18061812 Variants :: Multiple { ref discr, .. } => {
18071813 assert_eq ! ( i, 0 ) ;
1808- return handle_discriminant ( discr) ;
1814+ return discr_layout ( discr) ;
18091815 }
18101816 }
18111817 }
0 commit comments