2018-09-25 21:51:35 +00:00
|
|
|
#![allow(dead_code)]
|
2018-03-16 18:42:42 +00:00
|
|
|
// ignore-emscripten weird assertion?
|
2015-03-22 20:13:15 +00:00
|
|
|
|
2014-05-27 06:56:52 +00:00
|
|
|
#[repr(packed)]
|
2018-02-04 11:10:28 +00:00
|
|
|
struct Foo1 {
|
|
|
|
bar: u8,
|
|
|
|
baz: usize
|
|
|
|
}
|
|
|
|
|
|
|
|
#[repr(packed(2))]
|
|
|
|
struct Foo2 {
|
|
|
|
bar: u8,
|
|
|
|
baz: usize
|
|
|
|
}
|
|
|
|
|
|
|
|
#[repr(C, packed(4))]
|
|
|
|
struct Foo4C {
|
2013-04-10 13:47:53 +00:00
|
|
|
bar: u8,
|
2015-03-26 00:06:52 +00:00
|
|
|
baz: usize
|
2013-04-10 13:47:53 +00:00
|
|
|
}
|
|
|
|
|
2013-09-25 07:43:37 +00:00
|
|
|
pub fn main() {
|
2018-02-04 11:10:28 +00:00
|
|
|
let foo = Foo1 { bar: 1, baz: 2 };
|
2022-09-30 12:54:30 +00:00
|
|
|
let brw = &foo.baz; //~ERROR reference to packed field is unaligned
|
2018-02-04 11:10:28 +00:00
|
|
|
assert_eq!(*brw, 2);
|
2013-04-10 13:47:53 +00:00
|
|
|
|
2018-02-04 11:10:28 +00:00
|
|
|
let foo = Foo2 { bar: 1, baz: 2 };
|
2022-09-30 12:54:30 +00:00
|
|
|
let brw = &foo.baz; //~ERROR reference to packed field is unaligned
|
2018-02-04 11:10:28 +00:00
|
|
|
assert_eq!(*brw, 2);
|
2013-04-10 13:47:53 +00:00
|
|
|
}
|