]> git.lizzy.rs Git - rust.git/blob - src/test/ui/unsafe/issue-47412.rs
Rollup merge of #103033 - alyssais:pkg-config, r=joshtriplett
[rust.git] / src / test / ui / unsafe / issue-47412.rs
1 // revisions: mir thir
2 // [thir]compile-flags: -Z thir-unsafeck
3
4 #[derive(Copy, Clone)]
5 enum Void {}
6
7 // Tests that we detect unsafe places (specifically, union fields and
8 // raw pointer dereferences), even when they're matched on while having
9 // an uninhabited type (equivalent to `std::intrinsics::unreachable()`).
10
11 fn union_field() {
12     union Union { unit: (), void: Void }
13     let u = Union { unit: () };
14     match u.void {}
15     //~^ ERROR access to union field is unsafe
16 }
17
18 fn raw_ptr_deref() {
19     let ptr = std::ptr::null::<Void>();
20     match *ptr {}
21     //~^ ERROR dereference of raw pointer is unsafe
22 }
23
24 fn main() {}