]> git.proxmox.com Git - rustc.git/blame - src/test/ui/packed/packed-struct-address-of-element.rs
New upstream version 1.62.1+dfsg1
[rustc.git] / src / test / ui / packed / packed-struct-address-of-element.rs
CommitLineData
dfeec247
XL
1// run-pass
2#![allow(dead_code)]
dfeec247
XL
3#![feature(raw_ref_op)]
4// ignore-emscripten weird assertion?
5
6#[repr(packed)]
7struct Foo1 {
8 bar: u8,
9 baz: usize
10}
11
12#[repr(packed(2))]
13struct Foo2 {
14 bar: u8,
15 baz: usize
16}
17
18#[repr(C, packed(4))]
19struct Foo4C {
20 bar: u8,
21 baz: usize
22}
23
24pub fn main() {
25 let foo = Foo1 { bar: 1, baz: 2 };
26 let brw = &raw const foo.baz;
27 unsafe { assert_eq!(brw.read_unaligned(), 2); }
28
29 let foo = Foo2 { bar: 1, baz: 2 };
30 let brw = &raw const foo.baz;
31 unsafe { assert_eq!(brw.read_unaligned(), 2); }
32
33 let mut foo = Foo4C { bar: 1, baz: 2 };
34 let brw = &raw mut foo.baz;
35 unsafe { assert_eq!(brw.read_unaligned(), 2); }
36}