2013-04-10 23:47:53 +10:00
|
|
|
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2018-08-30 14:18:55 +02:00
|
|
|
// run-pass
|
2018-03-16 11:42:42 -07:00
|
|
|
// ignore-emscripten weird assertion?
|
2015-03-22 13:13:15 -07:00
|
|
|
|
2018-02-04 22:10:28 +11:00
|
|
|
#![feature(repr_packed)]
|
|
|
|
|
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 };
|
2017-09-27 14:23:45 +03:00
|
|
|
let brw = unsafe { &foo.baz };
|
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 };
|
|
|
|
let brw = unsafe { &foo.baz };
|
|
|
|
assert_eq!(*brw, 2);
|
|
|
|
|
|
|
|
let foo = Foo4C { bar: 1, baz: 2 };
|
|
|
|
let brw = unsafe { &foo.baz };
|
2013-04-10 23:47:53 +10:00
|
|
|
assert_eq!(*brw, 2);
|
|
|
|
}
|