Skip to content

Commit 598d653

Browse files
committed
add UI tests for additional niches in fat pointers with usize metadata
1 parent 819ad3f commit 598d653

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Diff for: tests/ui/structs-enums/type-sizes.rs

+15
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
#![feature(pointer_is_aligned_to)]
88
#![feature(strict_provenance)]
99

10+
11+
//! Tests type sizes, niches and field orderings.
12+
//! Many asserts in this file are desirable optimizations, not guarantees.
13+
//! Some of them are not even optimal, future layout improvements may break them.
14+
15+
1016
use std::mem::size_of;
1117
use std::num::NonZero;
1218
use std::ptr;
@@ -238,6 +244,12 @@ struct VecDummy {
238244
len: usize,
239245
}
240246

247+
248+
struct DynTail {
249+
a: usize,
250+
b: [u8]
251+
}
252+
241253
pub fn main() {
242254
assert_eq!(size_of::<u8>(), 1 as usize);
243255
assert_eq!(size_of::<u32>(), 4 as usize);
@@ -355,4 +367,7 @@ pub fn main() {
355367
assert!(ptr::from_ref(&v.a).addr() > ptr::from_ref(&v.b).addr());
356368

357369

370+
// beyond NPO: address-space, alignment or metadata niches
371+
assert_eq!(size_of::<Option<Option<&'static str>>>(), size_of::<&'static str>());
372+
assert_eq!(size_of::<Option<Option<&'static DynTail>>>(), size_of::<&'static DynTail>());
358373
}

0 commit comments

Comments
 (0)