summaryrefslogtreecommitdiffstats
path: root/tests/ui/unsafe/access_union_field.rs
blob: 5c4e695df58f23a3cc29e90484a84ca1684e5dcb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// revisions: mir thir
// [thir]compile-flags: -Z thir-unsafeck

#![allow(unused_variables)]

union Foo {
    bar: i8,
    baz: u8,
}

fn main() {
    let foo = Foo { bar: 5 };
    let a = foo.bar; //~ ERROR access to union field is unsafe and requires unsafe function or block
    let b = foo.baz; //~ ERROR access to union field is unsafe and requires unsafe function or block
}