@@ -1403,7 +1403,6 @@ impl AddressSpace {
1403
1403
#[ derive( Clone , Copy , PartialEq , Eq , Hash , Debug ) ]
1404
1404
#[ cfg_attr( feature = "nightly" , derive( HashStable_Generic ) ) ]
1405
1405
pub enum BackendRepr {
1406
- Uninhabited ,
1407
1406
Scalar ( Scalar ) ,
1408
1407
ScalarPair ( Scalar , Scalar ) ,
1409
1408
Vector {
@@ -1422,10 +1421,9 @@ impl BackendRepr {
1422
1421
#[ inline]
1423
1422
pub fn is_unsized ( & self ) -> bool {
1424
1423
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
+ }
1429
1427
BackendRepr :: Memory { sized } => !sized,
1430
1428
}
1431
1429
}
@@ -1444,12 +1442,6 @@ impl BackendRepr {
1444
1442
}
1445
1443
}
1446
1444
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
-
1453
1445
/// Returns `true` if this is a scalar type
1454
1446
#[ inline]
1455
1447
pub fn is_scalar ( & self ) -> bool {
@@ -1470,7 +1462,7 @@ impl BackendRepr {
1470
1462
BackendRepr :: Vector { element, count } => {
1471
1463
cx. data_layout ( ) . vector_align ( element. size ( cx) * count)
1472
1464
}
1473
- BackendRepr :: Uninhabited | BackendRepr :: Memory { .. } => return None ,
1465
+ BackendRepr :: Memory { .. } => return None ,
1474
1466
} )
1475
1467
}
1476
1468
@@ -1491,7 +1483,7 @@ impl BackendRepr {
1491
1483
// to make the size a multiple of align (e.g. for vectors of size 3).
1492
1484
( element. size ( cx) * count) . align_to ( self . inherent_align ( cx) ?. abi )
1493
1485
}
1494
- BackendRepr :: Uninhabited | BackendRepr :: Memory { .. } => return None ,
1486
+ BackendRepr :: Memory { .. } => return None ,
1495
1487
} )
1496
1488
}
1497
1489
@@ -1505,9 +1497,7 @@ impl BackendRepr {
1505
1497
BackendRepr :: Vector { element, count } => {
1506
1498
BackendRepr :: Vector { element : element. to_union ( ) , count }
1507
1499
}
1508
- BackendRepr :: Uninhabited | BackendRepr :: Memory { .. } => {
1509
- BackendRepr :: Memory { sized : true }
1510
- }
1500
+ BackendRepr :: Memory { .. } => BackendRepr :: Memory { sized : true } ,
1511
1501
}
1512
1502
}
1513
1503
@@ -1703,6 +1693,11 @@ pub struct LayoutData<FieldIdx: Idx, VariantIdx: Idx> {
1703
1693
/// The leaf scalar with the largest number of invalid values
1704
1694
/// (i.e. outside of its `valid_range`), if it exists.
1705
1695
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 ,
1706
1701
1707
1702
pub align : AbiAndPrefAlign ,
1708
1703
pub size : Size ,
@@ -1734,14 +1729,14 @@ impl<FieldIdx: Idx, VariantIdx: Idx> LayoutData<FieldIdx, VariantIdx> {
1734
1729
/// Returns `true` if this is an aggregate type (including a ScalarPair!)
1735
1730
pub fn is_aggregate ( & self ) -> bool {
1736
1731
match self . backend_repr {
1737
- BackendRepr :: Uninhabited | BackendRepr :: Scalar ( _) | BackendRepr :: Vector { .. } => false ,
1732
+ BackendRepr :: Scalar ( _) | BackendRepr :: Vector { .. } => false ,
1738
1733
BackendRepr :: ScalarPair ( ..) | BackendRepr :: Memory { .. } => true ,
1739
1734
}
1740
1735
}
1741
1736
1742
1737
/// Returns `true` if this is an uninhabited type
1743
1738
pub fn is_uninhabited ( & self ) -> bool {
1744
- self . backend_repr . is_uninhabited ( )
1739
+ self . uninhabited
1745
1740
}
1746
1741
1747
1742
pub fn scalar < C : HasDataLayout > ( cx : & C , scalar : Scalar ) -> Self {
@@ -1777,6 +1772,7 @@ impl<FieldIdx: Idx, VariantIdx: Idx> LayoutData<FieldIdx, VariantIdx> {
1777
1772
fields : FieldsShape :: Primitive ,
1778
1773
backend_repr : BackendRepr :: Scalar ( scalar) ,
1779
1774
largest_niche,
1775
+ uninhabited : false ,
1780
1776
size,
1781
1777
align,
1782
1778
max_repr_align : None ,
@@ -1801,6 +1797,7 @@ where
1801
1797
backend_repr,
1802
1798
fields,
1803
1799
largest_niche,
1800
+ uninhabited,
1804
1801
variants,
1805
1802
max_repr_align,
1806
1803
unadjusted_abi_align,
@@ -1812,6 +1809,7 @@ where
1812
1809
. field ( "abi" , backend_repr)
1813
1810
. field ( "fields" , fields)
1814
1811
. field ( "largest_niche" , largest_niche)
1812
+ . field ( "uninhabited" , uninhabited)
1815
1813
. field ( "variants" , variants)
1816
1814
. field ( "max_repr_align" , max_repr_align)
1817
1815
. field ( "unadjusted_abi_align" , unadjusted_abi_align)
@@ -1876,7 +1874,6 @@ impl<FieldIdx: Idx, VariantIdx: Idx> LayoutData<FieldIdx, VariantIdx> {
1876
1874
BackendRepr :: Scalar ( _) | BackendRepr :: ScalarPair ( ..) | BackendRepr :: Vector { .. } => {
1877
1875
false
1878
1876
}
1879
- BackendRepr :: Uninhabited => self . size . bytes ( ) == 0 ,
1880
1877
BackendRepr :: Memory { sized } => sized && self . size . bytes ( ) == 0 ,
1881
1878
}
1882
1879
}
0 commit comments