about summary refs log tree commit diff
path: root/tests/mir-opt/uninhabited_not_read.rs
blob: 15769cdd75b3fdbff5273b734ea4038c4659ed10 (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
// skip-filecheck

//@ edition: 2021
// In ed 2021 and below, we don't fallback `!` to `()`.
// This would introduce a `! -> ()` coercion which would
// be UB if we didn't disallow this explicitly.

#![feature(never_type)]

// EMIT_MIR uninhabited_not_read.main.SimplifyLocals-final.after.mir
fn main() {
    // With a type annotation
    unsafe {
        let x = 3u8;
        let x: *const ! = &x as *const u8 as *const _;
        let _: ! = *x;
    }

    // Without a type annotation, make sure we don't implicitly coerce `!` to `()`
    // when we do the noop `*x`.
    unsafe {
        let x = 3u8;
        let x: *const ! = &x as *const u8 as *const _;
        let _ = *x;
    }
}