diff options
| author | Ralf Jung <post@ralfj.de> | 2023-08-29 08:58:21 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2023-08-29 08:58:21 +0200 |
| commit | 0360b6740b3d4b53af6250da4a1881fc02651988 (patch) | |
| tree | f2fa376e310a48964987d5a713bd26434d487db0 | |
| parent | a517049d8cd49b1a81249f68cdf24ecbadaf7e0d (diff) | |
| download | rust-0360b6740b3d4b53af6250da4a1881fc02651988.tar.gz rust-0360b6740b3d4b53af6250da4a1881fc02651988.zip | |
add is_1zst helper method
| -rw-r--r-- | compiler/rustc_abi/src/lib.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/compiler/rustc_abi/src/lib.rs b/compiler/rustc_abi/src/lib.rs index 7f2cab3eb11..571aaf631bd 100644 --- a/compiler/rustc_abi/src/lib.rs +++ b/compiler/rustc_abi/src/lib.rs @@ -1660,15 +1660,25 @@ pub struct PointeeInfo { impl LayoutS { /// Returns `true` if the layout corresponds to an unsized type. + #[inline] pub fn is_unsized(&self) -> bool { self.abi.is_unsized() } + #[inline] pub fn is_sized(&self) -> bool { self.abi.is_sized() } + /// Returns `true` if the type is sized and a 1-ZST (meaning it has size 0 and alignment 1). + pub fn is_1zst(&self) -> bool { + self.is_sized() && self.size.bytes() == 0 && self.align.abi.bytes() == 1 + } + /// Returns `true` if the type is a ZST and not unsized. + /// + /// Note that this does *not* imply that the type is irrelevant for layout! It can still have + /// non-trivial alignment constraints. You probably want to use `is_1zst` instead. pub fn is_zst(&self) -> bool { match self.abi { Abi::Scalar(_) | Abi::ScalarPair(..) | Abi::Vector { .. } => false, |
