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