summaryrefslogtreecommitdiffstats
path: root/tests/ui/unsafe/issue-45087-unreachable-unsafe.rs
blob: 3e3da667c0b0883bb0636cc460c6e4dd0e8c4acc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Verify that unreachable code undergoes unsafety checks.
// revisions: mir thir
// [thir]compile-flags: -Z thir-unsafeck

fn main() {
    return;
    *(1 as *mut u32) = 42;
    //~^ ERROR dereference of raw pointer is unsafe
}

fn panic() -> ! {
    panic!();
}

fn f(a: *mut u32) {
    panic();
    *a = 1;
    //~^ ERROR dereference of raw pointer is unsafe
}

enum Void {}

fn uninhabited() -> Void {
    panic!();
}

fn g(b: *mut u32) {
    uninhabited();
    *b = 1;
    //~^ ERROR dereference of raw pointer is unsafe
}