@@ -696,6 +696,17 @@ pub enum Primitive {
696696}
697697
698698impl Primitive {
699+ pub fn pref_pos < C : HasDataLayout > ( self , cx : & C ) -> LayoutPositionPref {
700+ let dl = cx. data_layout ( ) ;
701+
702+ match self {
703+ Int ( i, _) => LayoutPositionPref :: new ( i. size ( ) , i. align ( dl) ) ,
704+ F32 => LayoutPositionPref :: new ( Size :: from_bits ( 32 ) , dl. f32_align ) ,
705+ F64 => LayoutPositionPref :: new ( Size :: from_bits ( 64 ) , dl. f64_align ) ,
706+ Pointer => dl. pointer_pos
707+ }
708+ }
709+
699710 pub fn size < C : HasDataLayout > ( self , cx : & C ) -> Size {
700711 let dl = cx. data_layout ( ) ;
701712
@@ -1069,9 +1080,7 @@ pub struct LayoutDetails {
10691080impl LayoutDetails {
10701081 pub fn scalar < C : HasDataLayout > ( cx : & C , scalar : Scalar ) -> Self {
10711082 let largest_niche = Niche :: from_scalar ( cx, Size :: ZERO , scalar. clone ( ) ) ;
1072- let size = scalar. value . size ( cx) ;
1073- let align = scalar. value . align ( cx) ;
1074- let pref_pos = LayoutPositionPref :: new ( size, align) ;
1083+ let pref_pos = scalar. value . pref_pos ( cx) ;
10751084 LayoutDetails {
10761085 variants : Variants :: Single { index : VariantIdx :: new ( 0 ) } ,
10771086 fields : FieldPlacement :: Union ( 0 ) ,
0 commit comments