]> git.lizzy.rs Git - rust.git/blob - src/test/ui/packed/packed-struct-borrow-element.rs
make unaligned_refereces future-incompat lint warn-by-default, and remove the safe_pa...
[rust.git] / src / test / ui / packed / packed-struct-borrow-element.rs
1 // run-pass (note: this is spec-UB, but it works for now)
2 #![allow(dead_code)]
3 // ignore-emscripten weird assertion?
4
5 #[repr(packed)]
6 struct Foo1 {
7     bar: u8,
8     baz: usize
9 }
10
11 #[repr(packed(2))]
12 struct Foo2 {
13     bar: u8,
14     baz: usize
15 }
16
17 #[repr(C, packed(4))]
18 struct Foo4C {
19     bar: u8,
20     baz: usize
21 }
22
23 pub fn main() {
24     let foo = Foo1 { bar: 1, baz: 2 };
25     let brw = &foo.baz; //~WARN reference to packed field is unaligned
26     //~^ previously accepted
27     assert_eq!(*brw, 2);
28
29     let foo = Foo2 { bar: 1, baz: 2 };
30     let brw = &foo.baz; //~WARN reference to packed field is unaligned
31     //~^ previously accepted
32     assert_eq!(*brw, 2);
33
34     let foo = Foo4C { bar: 1, baz: 2 };
35     let brw = &foo.baz; //~WARN reference to packed field is unaligned
36     //~^ previously accepted
37     assert_eq!(*brw, 2);
38 }