]> git.lizzy.rs Git - rust.git/blob - tests/ui/packed-struct/packed-struct-transmute.rs
Rollup merge of #106648 - Nilstrieb:poly-cleanup, r=compiler-errors
[rust.git] / tests / ui / packed-struct / packed-struct-transmute.rs
1 // This assumes the packed and non-packed structs are different sizes.
2
3 // the error points to the start of the file, not the line with the
4 // transmute
5
6 // normalize-stderr-test "\d+ bits" -> "N bits"
7 // error-pattern: cannot transmute between types of different sizes, or dependently-sized types
8
9 use std::mem;
10
11 #[repr(packed)]
12 struct Foo {
13     bar: u8,
14     baz: usize
15 }
16
17 #[derive(Debug)]
18 struct Oof {
19     rab: u8,
20     zab: usize
21 }
22
23 fn main() {
24     let foo = Foo { bar: 1, baz: 10 };
25     unsafe {
26         let oof: Oof = mem::transmute(foo);
27         println!("{:?}", oof);
28     }
29 }