diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:13 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:13 +0000 |
commit | 218caa410aa38c29984be31a5229b9fa717560ee (patch) | |
tree | c54bd55eeb6e4c508940a30e94c0032fbd45d677 /src/test/ui/packed/packed-struct-size.rs | |
parent | Releasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip |
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/packed/packed-struct-size.rs')
-rw-r--r-- | src/test/ui/packed/packed-struct-size.rs | 157 |
1 files changed, 0 insertions, 157 deletions
diff --git a/src/test/ui/packed/packed-struct-size.rs b/src/test/ui/packed/packed-struct-size.rs deleted file mode 100644 index c832c7cfa..000000000 --- a/src/test/ui/packed/packed-struct-size.rs +++ /dev/null @@ -1,157 +0,0 @@ -// run-pass -#![allow(dead_code)] -#![allow(non_camel_case_types)] -#![allow(non_upper_case_globals)] - -use std::mem; - -#[repr(packed)] -struct P1S4 { - a: u8, - b: [u8; 3], -} - -#[repr(packed(2))] -struct P2S4 { - a: u8, - b: [u8; 3], -} - -#[repr(packed)] -struct P1S5 { - a: u8, - b: u32 -} - -#[repr(packed(2))] -struct P2S2 { - a: u8, - b: u8 -} - -#[repr(packed(2))] -struct P2S6 { - a: u8, - b: u32 -} - -#[repr(packed(2))] -struct P2S12 { - a: u32, - b: u64 -} - -#[repr(packed)] -struct P1S13 { - a: i64, - b: f32, - c: u8, -} - -#[repr(packed(2))] -struct P2S14 { - a: i64, - b: f32, - c: u8, -} - -#[repr(packed(4))] -struct P4S16 { - a: u8, - b: f32, - c: i64, - d: u16, -} - -#[repr(C, packed(4))] -struct P4CS20 { - a: u8, - b: f32, - c: i64, - d: u16, -} - -enum Foo { - Bar = 1, - Baz = 2 -} - -#[repr(packed)] -struct P1S3_Foo { - a: u8, - b: u16, - c: Foo -} - -#[repr(packed(2))] -struct P2_Foo { - a: Foo, -} - -#[repr(packed(2))] -struct P2S3_Foo { - a: u8, - b: u16, - c: Foo -} - -#[repr(packed)] -struct P1S7_Option { - a: f32, - b: u8, - c: u16, - d: Option<Box<f64>> -} - -#[repr(packed(2))] -struct P2_Option { - a: Option<Box<f64>> -} - -#[repr(packed(2))] -struct P2S7_Option { - a: f32, - b: u8, - c: u16, - d: Option<Box<f64>> -} - -// Placing packed structs in statics should work -static TEST_P1S4: P1S4 = P1S4 { a: 1, b: [2, 3, 4] }; -static TEST_P1S5: P1S5 = P1S5 { a: 3, b: 67 }; -static TEST_P1S3_Foo: P1S3_Foo = P1S3_Foo { a: 1, b: 2, c: Foo::Baz }; -static TEST_P2S2: P2S2 = P2S2 { a: 1, b: 2 }; -static TEST_P2S4: P2S4 = P2S4 { a: 1, b: [2, 3, 4] }; -static TEST_P2S6: P2S6 = P2S6 { a: 1, b: 2 }; -static TEST_P2S12: P2S12 = P2S12 { a: 1, b: 2 }; -static TEST_P4S16: P4S16 = P4S16 { a: 1, b: 2.0, c: 3, d: 4 }; -static TEST_P4CS20: P4CS20 = P4CS20 { a: 1, b: 2.0, c: 3, d: 4 }; - -fn align_to(value: usize, align: usize) -> usize { - (value + (align - 1)) & !(align - 1) -} - -macro_rules! check { - ($t:ty, $align:expr, $size:expr) => ({ - assert_eq!(mem::align_of::<$t>(), $align); - assert_eq!(mem::size_of::<$t>(), $size); - }); -} - -pub fn main() { - check!(P1S4, 1, 4); - check!(P1S5, 1, 5); - check!(P1S13, 1, 13); - check!(P1S3_Foo, 1, 3 + mem::size_of::<Foo>()); - check!(P1S7_Option, 1, 7 + mem::size_of::<Option<Box<f64>>>()); - - check!(P2S2, 1, 2); - check!(P2S4, 1, 4); - check!(P2S6, 2, 6); - check!(P2S12, 2, 12); - check!(P2S14, 2, 14); - check!(P4S16, 4, 16); - check!(P4CS20, 4, 20); - check!(P2S3_Foo, 2, align_to(3 + mem::size_of::<P2_Foo>(), 2)); - check!(P2S7_Option, 2, align_to(7 + mem::size_of::<P2_Option>(), 2)); -} |