]> git.lizzy.rs Git - rust.git/blob - src/test/ui/unsafe/union-modification.rs
Rollup merge of #103033 - alyssais:pkg-config, r=joshtriplett
[rust.git] / src / test / ui / unsafe / union-modification.rs
1 // run-pass
2 // revisions: mir thir
3 // [thir]compile-flags: -Z thir-unsafeck
4
5 union Foo {
6     bar: i8,
7     _blah: isize,
8     _zst: (),
9 }
10
11 struct FooHolder {
12     inner_foo: Foo
13 }
14
15 fn do_nothing(_x: &mut Foo) {}
16
17 pub fn main() {
18     let mut foo = Foo { bar: 5 };
19     do_nothing(&mut foo);
20     foo.bar = 6;
21     unsafe { foo.bar += 1; }
22     assert_eq!(unsafe { foo.bar }, 7);
23     unsafe {
24         let Foo { bar: inner } = foo;
25         assert_eq!(inner, 7);
26     }
27
28     let foo = Foo { bar: 5 };
29     let foo = if let 3 = if let true = true { 3 } else { 4 } { foo } else { foo };
30
31     let (_foo2, _random) = (foo, 42);
32
33     let mut foo_holder = FooHolder { inner_foo: Foo { bar: 5 } };
34     foo_holder.inner_foo.bar = 4;
35     assert_eq!(unsafe { foo_holder.inner_foo.bar }, 4);
36     drop(foo_holder);
37 }