Skip to content

Commit db42eb3

Browse files
committed
Wrap NonZero::new_unchecked call in the print_type_sizes test in a const
1 parent e36dc78 commit db42eb3

File tree

2 files changed

+3
-22
lines changed

2 files changed

+3
-22
lines changed

tests/ui/print_type_sizes/niche-filling.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ pub struct NestedNonZero {
5555

5656
impl Default for NestedNonZero {
5757
fn default() -> Self {
58-
NestedNonZero { pre: 0, val: unsafe { NonZero::new_unchecked(1) }, post: 0 }
58+
// Wrap the new_unchecked call in a const so that compilation doesn't encounter the type
59+
// size of fmt::Arguments (which contains pointers) via the UB check that is in new_unchecked.
60+
NestedNonZero { pre: 0, val: const { unsafe { NonZero::new_unchecked(1) } }, post: 0 }
5961
}
6062
}
6163

tests/ui/print_type_sizes/niche-filling.stdout

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,7 @@
1-
print-type-size type: `std::fmt::Arguments<'_>`: 48 bytes, alignment: 8 bytes
2-
print-type-size field `.pieces`: 16 bytes
3-
print-type-size field `.args`: 16 bytes
4-
print-type-size field `.fmt`: 16 bytes
51
print-type-size type: `std::panic::Location<'_>`: 24 bytes, alignment: 8 bytes
62
print-type-size field `.file`: 16 bytes
73
print-type-size field `.line`: 4 bytes
84
print-type-size field `.col`: 4 bytes
9-
print-type-size type: `core::fmt::rt::Argument<'_>`: 16 bytes, alignment: 8 bytes
10-
print-type-size field `.ty`: 16 bytes
11-
print-type-size type: `core::fmt::rt::ArgumentType<'_>`: 16 bytes, alignment: 8 bytes
12-
print-type-size variant `Placeholder`: 16 bytes
13-
print-type-size field `.value`: 8 bytes
14-
print-type-size field `.formatter`: 8 bytes
15-
print-type-size field `._lifetime`: 0 bytes
16-
print-type-size variant `Count`: 10 bytes
17-
print-type-size padding: 8 bytes
18-
print-type-size field `.0`: 2 bytes, alignment: 2 bytes
19-
print-type-size type: `std::option::Option<&[core::fmt::rt::Placeholder]>`: 16 bytes, alignment: 8 bytes
20-
print-type-size variant `Some`: 16 bytes
21-
print-type-size field `.0`: 16 bytes
22-
print-type-size variant `None`: 0 bytes
235
print-type-size type: `IndirectNonZero`: 12 bytes, alignment: 4 bytes
246
print-type-size field `.nested`: 8 bytes
257
print-type-size field `.post`: 2 bytes
@@ -56,8 +38,6 @@ print-type-size field `.val`: 4 bytes
5638
print-type-size field `.post`: 2 bytes
5739
print-type-size field `.pre`: 1 bytes
5840
print-type-size end padding: 1 bytes
59-
print-type-size type: `std::ptr::NonNull<()>`: 8 bytes, alignment: 8 bytes
60-
print-type-size field `.pointer`: 8 bytes
6141
print-type-size type: `Enum4<(), char, (), ()>`: 4 bytes, alignment: 4 bytes
6242
print-type-size variant `Two`: 4 bytes
6343
print-type-size field `.0`: 4 bytes
@@ -140,4 +120,3 @@ print-type-size discriminant: 1 bytes
140120
print-type-size variant `Less`: 0 bytes
141121
print-type-size variant `Equal`: 0 bytes
142122
print-type-size variant `Greater`: 0 bytes
143-
print-type-size type: `std::marker::PhantomData<&()>`: 0 bytes, alignment: 1 bytes

0 commit comments

Comments
 (0)