@@ -1403,7 +1403,6 @@ impl AddressSpace {
14031403#[ derive( Clone , Copy , PartialEq , Eq , Hash , Debug ) ]
14041404#[ cfg_attr( feature = "nightly" , derive( HashStable_Generic ) ) ]
14051405pub enum BackendRepr {
1406- Uninhabited ,
14071406 Scalar ( Scalar ) ,
14081407 ScalarPair ( Scalar , Scalar ) ,
14091408 Vector {
@@ -1422,10 +1421,9 @@ impl BackendRepr {
14221421 #[ inline]
14231422 pub fn is_unsized ( & self ) -> bool {
14241423 match * self {
1425- BackendRepr :: Uninhabited
1426- | BackendRepr :: Scalar ( _)
1427- | BackendRepr :: ScalarPair ( ..)
1428- | BackendRepr :: Vector { .. } => false ,
1424+ BackendRepr :: Scalar ( _) | BackendRepr :: ScalarPair ( ..) | BackendRepr :: Vector { .. } => {
1425+ false
1426+ }
14291427 BackendRepr :: Memory { sized } => !sized,
14301428 }
14311429 }
@@ -1444,12 +1442,6 @@ impl BackendRepr {
14441442 }
14451443 }
14461444
1447- /// Returns `true` if this is an uninhabited type
1448- #[ inline]
1449- pub fn is_uninhabited ( & self ) -> bool {
1450- matches ! ( * self , BackendRepr :: Uninhabited )
1451- }
1452-
14531445 /// Returns `true` if this is a scalar type
14541446 #[ inline]
14551447 pub fn is_scalar ( & self ) -> bool {
@@ -1470,7 +1462,7 @@ impl BackendRepr {
14701462 BackendRepr :: Vector { element, count } => {
14711463 cx. data_layout ( ) . vector_align ( element. size ( cx) * count)
14721464 }
1473- BackendRepr :: Uninhabited | BackendRepr :: Memory { .. } => return None ,
1465+ BackendRepr :: Memory { .. } => return None ,
14741466 } )
14751467 }
14761468
@@ -1491,7 +1483,7 @@ impl BackendRepr {
14911483 // to make the size a multiple of align (e.g. for vectors of size 3).
14921484 ( element. size ( cx) * count) . align_to ( self . inherent_align ( cx) ?. abi )
14931485 }
1494- BackendRepr :: Uninhabited | BackendRepr :: Memory { .. } => return None ,
1486+ BackendRepr :: Memory { .. } => return None ,
14951487 } )
14961488 }
14971489
@@ -1505,9 +1497,7 @@ impl BackendRepr {
15051497 BackendRepr :: Vector { element, count } => {
15061498 BackendRepr :: Vector { element : element. to_union ( ) , count }
15071499 }
1508- BackendRepr :: Uninhabited | BackendRepr :: Memory { .. } => {
1509- BackendRepr :: Memory { sized : true }
1510- }
1500+ BackendRepr :: Memory { .. } => BackendRepr :: Memory { sized : true } ,
15111501 }
15121502 }
15131503
@@ -1703,6 +1693,11 @@ pub struct LayoutData<FieldIdx: Idx, VariantIdx: Idx> {
17031693 /// The leaf scalar with the largest number of invalid values
17041694 /// (i.e. outside of its `valid_range`), if it exists.
17051695 pub largest_niche : Option < Niche > ,
1696+ /// Is this type known to be uninhabted?
1697+ ///
1698+ /// This is separate from BackendRepr, because an uninhabited return type may require special
1699+ /// consideration based on its size or other attributes.
1700+ pub uninhabited : bool ,
17061701
17071702 pub align : AbiAndPrefAlign ,
17081703 pub size : Size ,
@@ -1734,14 +1729,14 @@ impl<FieldIdx: Idx, VariantIdx: Idx> LayoutData<FieldIdx, VariantIdx> {
17341729 /// Returns `true` if this is an aggregate type (including a ScalarPair!)
17351730 pub fn is_aggregate ( & self ) -> bool {
17361731 match self . backend_repr {
1737- BackendRepr :: Uninhabited | BackendRepr :: Scalar ( _) | BackendRepr :: Vector { .. } => false ,
1732+ BackendRepr :: Scalar ( _) | BackendRepr :: Vector { .. } => false ,
17381733 BackendRepr :: ScalarPair ( ..) | BackendRepr :: Memory { .. } => true ,
17391734 }
17401735 }
17411736
17421737 /// Returns `true` if this is an uninhabited type
17431738 pub fn is_uninhabited ( & self ) -> bool {
1744- self . backend_repr . is_uninhabited ( )
1739+ self . uninhabited
17451740 }
17461741
17471742 pub fn scalar < C : HasDataLayout > ( cx : & C , scalar : Scalar ) -> Self {
@@ -1777,6 +1772,7 @@ impl<FieldIdx: Idx, VariantIdx: Idx> LayoutData<FieldIdx, VariantIdx> {
17771772 fields : FieldsShape :: Primitive ,
17781773 backend_repr : BackendRepr :: Scalar ( scalar) ,
17791774 largest_niche,
1775+ uninhabited : false ,
17801776 size,
17811777 align,
17821778 max_repr_align : None ,
@@ -1801,6 +1797,7 @@ where
18011797 backend_repr,
18021798 fields,
18031799 largest_niche,
1800+ uninhabited,
18041801 variants,
18051802 max_repr_align,
18061803 unadjusted_abi_align,
@@ -1812,6 +1809,7 @@ where
18121809 . field ( "abi" , backend_repr)
18131810 . field ( "fields" , fields)
18141811 . field ( "largest_niche" , largest_niche)
1812+ . field ( "uninhabited" , uninhabited)
18151813 . field ( "variants" , variants)
18161814 . field ( "max_repr_align" , max_repr_align)
18171815 . field ( "unadjusted_abi_align" , unadjusted_abi_align)
@@ -1876,7 +1874,6 @@ impl<FieldIdx: Idx, VariantIdx: Idx> LayoutData<FieldIdx, VariantIdx> {
18761874 BackendRepr :: Scalar ( _) | BackendRepr :: ScalarPair ( ..) | BackendRepr :: Vector { .. } => {
18771875 false
18781876 }
1879- BackendRepr :: Uninhabited => self . size . bytes ( ) == 0 ,
18801877 BackendRepr :: Memory { sized } => sized && self . size . bytes ( ) == 0 ,
18811878 }
18821879 }
0 commit comments