@@ -1404,7 +1404,6 @@ impl AddressSpace {
14041404#[ derive( Clone , Copy , PartialEq , Eq , Hash , Debug ) ]
14051405#[ cfg_attr( feature = "nightly" , derive( HashStable_Generic ) ) ]
14061406pub enum BackendRepr {
1407- Uninhabited ,
14081407 Scalar ( Scalar ) ,
14091408 ScalarPair ( Scalar , Scalar ) ,
14101409 Vector {
@@ -1423,10 +1422,9 @@ impl BackendRepr {
14231422 #[ inline]
14241423 pub fn is_unsized ( & self ) -> bool {
14251424 match * self {
1426- BackendRepr :: Uninhabited
1427- | BackendRepr :: Scalar ( _)
1428- | BackendRepr :: ScalarPair ( ..)
1429- | BackendRepr :: Vector { .. } => false ,
1425+ BackendRepr :: Scalar ( _) | BackendRepr :: ScalarPair ( ..) | BackendRepr :: Vector { .. } => {
1426+ false
1427+ }
14301428 BackendRepr :: Memory { sized } => !sized,
14311429 }
14321430 }
@@ -1445,12 +1443,6 @@ impl BackendRepr {
14451443 }
14461444 }
14471445
1448- /// Returns `true` if this is an uninhabited type
1449- #[ inline]
1450- pub fn is_uninhabited ( & self ) -> bool {
1451- matches ! ( * self , BackendRepr :: Uninhabited )
1452- }
1453-
14541446 /// Returns `true` if this is a scalar type
14551447 #[ inline]
14561448 pub fn is_scalar ( & self ) -> bool {
@@ -1471,7 +1463,7 @@ impl BackendRepr {
14711463 BackendRepr :: Vector { element, count } => {
14721464 cx. data_layout ( ) . vector_align ( element. size ( cx) * count)
14731465 }
1474- BackendRepr :: Uninhabited | BackendRepr :: Memory { .. } => return None ,
1466+ BackendRepr :: Memory { .. } => return None ,
14751467 } )
14761468 }
14771469
@@ -1492,7 +1484,7 @@ impl BackendRepr {
14921484 // to make the size a multiple of align (e.g. for vectors of size 3).
14931485 ( element. size ( cx) * count) . align_to ( self . inherent_align ( cx) ?. abi )
14941486 }
1495- BackendRepr :: Uninhabited | BackendRepr :: Memory { .. } => return None ,
1487+ BackendRepr :: Memory { .. } => return None ,
14961488 } )
14971489 }
14981490
@@ -1506,9 +1498,7 @@ impl BackendRepr {
15061498 BackendRepr :: Vector { element, count } => {
15071499 BackendRepr :: Vector { element : element. to_union ( ) , count }
15081500 }
1509- BackendRepr :: Uninhabited | BackendRepr :: Memory { .. } => {
1510- BackendRepr :: Memory { sized : true }
1511- }
1501+ BackendRepr :: Memory { .. } => BackendRepr :: Memory { sized : true } ,
15121502 }
15131503 }
15141504
@@ -1704,6 +1694,11 @@ pub struct LayoutData<FieldIdx: Idx, VariantIdx: Idx> {
17041694 /// The leaf scalar with the largest number of invalid values
17051695 /// (i.e. outside of its `valid_range`), if it exists.
17061696 pub largest_niche : Option < Niche > ,
1697+ /// Is this type known to be uninhabted?
1698+ ///
1699+ /// This is separate from BackendRepr because uninhabited return types can affect ABI,
1700+ /// especially in the case of by-pointer struct returns, which allocate stack even when unused.
1701+ pub uninhabited : bool ,
17071702
17081703 pub align : AbiAndPrefAlign ,
17091704 pub size : Size ,
@@ -1735,14 +1730,14 @@ impl<FieldIdx: Idx, VariantIdx: Idx> LayoutData<FieldIdx, VariantIdx> {
17351730 /// Returns `true` if this is an aggregate type (including a ScalarPair!)
17361731 pub fn is_aggregate ( & self ) -> bool {
17371732 match self . backend_repr {
1738- BackendRepr :: Uninhabited | BackendRepr :: Scalar ( _) | BackendRepr :: Vector { .. } => false ,
1733+ BackendRepr :: Scalar ( _) | BackendRepr :: Vector { .. } => false ,
17391734 BackendRepr :: ScalarPair ( ..) | BackendRepr :: Memory { .. } => true ,
17401735 }
17411736 }
17421737
17431738 /// Returns `true` if this is an uninhabited type
17441739 pub fn is_uninhabited ( & self ) -> bool {
1745- self . backend_repr . is_uninhabited ( )
1740+ self . uninhabited
17461741 }
17471742
17481743 pub fn scalar < C : HasDataLayout > ( cx : & C , scalar : Scalar ) -> Self {
@@ -1778,6 +1773,7 @@ impl<FieldIdx: Idx, VariantIdx: Idx> LayoutData<FieldIdx, VariantIdx> {
17781773 fields : FieldsShape :: Primitive ,
17791774 backend_repr : BackendRepr :: Scalar ( scalar) ,
17801775 largest_niche,
1776+ uninhabited : false ,
17811777 size,
17821778 align,
17831779 max_repr_align : None ,
@@ -1802,6 +1798,7 @@ where
18021798 backend_repr,
18031799 fields,
18041800 largest_niche,
1801+ uninhabited,
18051802 variants,
18061803 max_repr_align,
18071804 unadjusted_abi_align,
@@ -1813,6 +1810,7 @@ where
18131810 . field ( "abi" , backend_repr)
18141811 . field ( "fields" , fields)
18151812 . field ( "largest_niche" , largest_niche)
1813+ . field ( "uninhabited" , uninhabited)
18161814 . field ( "variants" , variants)
18171815 . field ( "max_repr_align" , max_repr_align)
18181816 . field ( "unadjusted_abi_align" , unadjusted_abi_align)
@@ -1877,7 +1875,6 @@ impl<FieldIdx: Idx, VariantIdx: Idx> LayoutData<FieldIdx, VariantIdx> {
18771875 BackendRepr :: Scalar ( _) | BackendRepr :: ScalarPair ( ..) | BackendRepr :: Vector { .. } => {
18781876 false
18791877 }
1880- BackendRepr :: Uninhabited => self . size . bytes ( ) == 0 ,
18811878 BackendRepr :: Memory { sized } => sized && self . size . bytes ( ) == 0 ,
18821879 }
18831880 }
0 commit comments