File: diverging-place-match.rs

package info (click to toggle)
rustc 1.87.0%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 925,564 kB
  • sloc: xml: 158,127; python: 36,039; javascript: 19,761; sh: 19,737; cpp: 18,981; ansic: 13,133; asm: 4,376; makefile: 710; perl: 29; lisp: 28; ruby: 19; sql: 11
file content (74 lines) | stat: -rw-r--r-- 1,616 bytes parent folder | download | duplicates (14)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#![feature(never_type)]

fn not_a_read() -> ! {
    unsafe {
    //~^ ERROR mismatched types
        let x: *const ! = 0 as _;
        let _: ! = *x;
        // Since `*x` "diverges" in HIR, but doesn't count as a read in MIR, this
        // is unsound since we act as if it diverges but it doesn't.
    }
}

fn not_a_read_implicit() -> ! {
    unsafe {
    //~^ ERROR mismatched types
        let x: *const ! = 0 as _;
        let _ = *x;
    }
}

fn not_a_read_guide_coercion() -> ! {
    unsafe {
        //~^ ERROR mismatched types
        let x: *const ! = 0 as _;
        let _: () = *x;
        //~^ ERROR mismatched types
    }
}

fn empty_match() -> ! {
    unsafe {
    //~^ ERROR mismatched types
        let x: *const ! = 0 as _;
        match *x { _ => {} };
    }
}

fn field_projection() -> ! {
    unsafe {
    //~^ ERROR mismatched types
        let x: *const (!, ()) = 0 as _;
        let _ = (*x).0;
        // ^ I think this is still UB, but because of the inbounds projection.
    }
}

fn covered_arm() -> ! {
    unsafe {
    //~^ ERROR mismatched types
        let x: *const ! = 0 as _;
        let (_ | 1i32) = *x;
        //~^ ERROR mismatched types
    }
}

// FIXME: This *could* be considered a read of `!`, but we're not that sophisticated..
fn uncovered_arm() -> ! {
    unsafe {
    //~^ ERROR mismatched types
        let x: *const ! = 0 as _;
        let (1i32 | _) = *x;
        //~^ ERROR mismatched types
    }
}

fn coerce_ref_binding() -> ! {
    unsafe {
        let x: *const ! = 0 as _;
        let ref _x: () = *x;
        //~^ ERROR mismatched types
    }
}

fn main() {}