Skip to content

Commit

Permalink
add UI tests for additional niches in fat pointers with usize metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
the8472 committed Oct 12, 2024
1 parent 819ad3f commit 598d653
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/ui/structs-enums/type-sizes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
#![feature(pointer_is_aligned_to)]
#![feature(strict_provenance)]


//! Tests type sizes, niches and field orderings.
//! Many asserts in this file are desirable optimizations, not guarantees.
//! Some of them are not even optimal, future layout improvements may break them.

use std::mem::size_of;
use std::num::NonZero;
use std::ptr;
Expand Down Expand Up @@ -238,6 +244,12 @@ struct VecDummy {
len: usize,
}


struct DynTail {
a: usize,
b: [u8]
}

pub fn main() {
assert_eq!(size_of::<u8>(), 1 as usize);
assert_eq!(size_of::<u32>(), 4 as usize);
Expand Down Expand Up @@ -355,4 +367,7 @@ pub fn main() {
assert!(ptr::from_ref(&v.a).addr() > ptr::from_ref(&v.b).addr());


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

0 comments on commit 598d653

Please sign in to comment.