]> git.lizzy.rs Git - rust.git/blob - src/test/ui/packed/packed-struct-address-of-element.rs
make unaligned_refereces future-incompat lint warn-by-default, and remove the safe_pa...
[rust.git] / src / test / ui / packed / packed-struct-address-of-element.rs
1 // run-pass
2 #![allow(dead_code)]
3 #![deny(unaligned_references)]
4 #![feature(raw_ref_op)]
5 // ignore-emscripten weird assertion?
6
7 #[repr(packed)]
8 struct Foo1 {
9     bar: u8,
10     baz: usize
11 }
12
13 #[repr(packed(2))]
14 struct Foo2 {
15     bar: u8,
16     baz: usize
17 }
18
19 #[repr(C, packed(4))]
20 struct Foo4C {
21     bar: u8,
22     baz: usize
23 }
24
25 pub fn main() {
26     let foo = Foo1 { bar: 1, baz: 2 };
27     let brw = &raw const foo.baz;
28     unsafe { assert_eq!(brw.read_unaligned(), 2); }
29
30     let foo = Foo2 { bar: 1, baz: 2 };
31     let brw = &raw const foo.baz;
32     unsafe { assert_eq!(brw.read_unaligned(), 2); }
33
34     let mut foo = Foo4C { bar: 1, baz: 2 };
35     let brw = &raw mut foo.baz;
36     unsafe { assert_eq!(brw.read_unaligned(), 2); }
37 }