From 598d653cd5d127c70245c0e4871edb80813b9cb4 Mon Sep 17 00:00:00 2001 From: The 8472 Date: Sat, 12 Oct 2024 19:35:37 +0200 Subject: [PATCH] add UI tests for additional niches in fat pointers with usize metadata --- tests/ui/structs-enums/type-sizes.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/ui/structs-enums/type-sizes.rs b/tests/ui/structs-enums/type-sizes.rs index f49ce33841af3..564896f3396d6 100644 --- a/tests/ui/structs-enums/type-sizes.rs +++ b/tests/ui/structs-enums/type-sizes.rs @@ -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; @@ -238,6 +244,12 @@ struct VecDummy { len: usize, } + +struct DynTail { + a: usize, + b: [u8] +} + pub fn main() { assert_eq!(size_of::(), 1 as usize); assert_eq!(size_of::(), 4 as usize); @@ -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::>>(), size_of::<&'static str>()); + assert_eq!(size_of::>>(), size_of::<&'static DynTail>()); }