Wrap NonZero::new_unchecked call in the print_type_sizes test in a const

This commit is contained in:
Ben Kimock 2025-05-26 22:12:02 -04:00
parent e36dc78edd
commit 6d0e04d6f3
2 changed files with 8 additions and 30 deletions

View file

@ -55,7 +55,14 @@ pub struct NestedNonZero {
impl Default for NestedNonZero {
fn default() -> Self {
NestedNonZero { pre: 0, val: unsafe { NonZero::new_unchecked(1) }, post: 0 }
// Ideally we'd call NonZero::new_unchecked, but this test is supposed
// to be target-independent and NonZero::new_unchecked is #[track_caller]
// (see #129658) so mentioning that function pulls in std::panic::Location
// which contains a &str, whose layout is target-dependent.
const ONE: NonZero<u32> = const {
unsafe { std::mem::transmute(1u32) }
};
NestedNonZero { pre: 0, val: ONE, post: 0 }
}
}

View file

@ -1,25 +1,3 @@
print-type-size type: `std::fmt::Arguments<'_>`: 48 bytes, alignment: 8 bytes
print-type-size field `.pieces`: 16 bytes
print-type-size field `.args`: 16 bytes
print-type-size field `.fmt`: 16 bytes
print-type-size type: `std::panic::Location<'_>`: 24 bytes, alignment: 8 bytes
print-type-size field `.file`: 16 bytes
print-type-size field `.line`: 4 bytes
print-type-size field `.col`: 4 bytes
print-type-size type: `core::fmt::rt::Argument<'_>`: 16 bytes, alignment: 8 bytes
print-type-size field `.ty`: 16 bytes
print-type-size type: `core::fmt::rt::ArgumentType<'_>`: 16 bytes, alignment: 8 bytes
print-type-size variant `Placeholder`: 16 bytes
print-type-size field `.value`: 8 bytes
print-type-size field `.formatter`: 8 bytes
print-type-size field `._lifetime`: 0 bytes
print-type-size variant `Count`: 10 bytes
print-type-size padding: 8 bytes
print-type-size field `.0`: 2 bytes, alignment: 2 bytes
print-type-size type: `std::option::Option<&[core::fmt::rt::Placeholder]>`: 16 bytes, alignment: 8 bytes
print-type-size variant `Some`: 16 bytes
print-type-size field `.0`: 16 bytes
print-type-size variant `None`: 0 bytes
print-type-size type: `IndirectNonZero`: 12 bytes, alignment: 4 bytes
print-type-size field `.nested`: 8 bytes
print-type-size field `.post`: 2 bytes
@ -56,8 +34,6 @@ print-type-size field `.val`: 4 bytes
print-type-size field `.post`: 2 bytes
print-type-size field `.pre`: 1 bytes
print-type-size end padding: 1 bytes
print-type-size type: `std::ptr::NonNull<()>`: 8 bytes, alignment: 8 bytes
print-type-size field `.pointer`: 8 bytes
print-type-size type: `Enum4<(), char, (), ()>`: 4 bytes, alignment: 4 bytes
print-type-size variant `Two`: 4 bytes
print-type-size field `.0`: 4 bytes
@ -96,10 +72,6 @@ print-type-size type: `core::num::niche_types::NonZeroU32Inner`: 4 bytes, alignm
print-type-size field `.0`: 4 bytes
print-type-size type: `std::num::NonZero<u32>`: 4 bytes, alignment: 4 bytes
print-type-size field `.0`: 4 bytes
print-type-size type: `std::option::Option<std::num::NonZero<u32>>`: 4 bytes, alignment: 4 bytes
print-type-size variant `Some`: 4 bytes
print-type-size field `.0`: 4 bytes
print-type-size variant `None`: 0 bytes
print-type-size type: `Enum4<(), (), (), MyOption<u8>>`: 2 bytes, alignment: 1 bytes
print-type-size variant `Four`: 2 bytes
print-type-size field `.0`: 2 bytes
@ -140,4 +112,3 @@ print-type-size discriminant: 1 bytes
print-type-size variant `Less`: 0 bytes
print-type-size variant `Equal`: 0 bytes
print-type-size variant `Greater`: 0 bytes
print-type-size type: `std::marker::PhantomData<&()>`: 0 bytes, alignment: 1 bytes