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