about summary refs log tree commit diff
path: root/tests/mir-opt/building/match/never_patterns.rs
blob: 8b52440da4c3dc89a15f271133b56ac9e7bd3024 (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
32
33
34
35
36
37
38
39
40
41
42
43
44
#![feature(never_patterns)]
#![allow(incomplete_features)]

enum Void {}

// EMIT_MIR never_patterns.opt1.SimplifyCfg-initial.after.mir
fn opt1(res: &Result<u32, Void>) -> &u32 {
    // CHECK-LABEL: fn opt1(
    // CHECK: bb0: {
    // CHECK-NOT: {{bb.*}}: {
    // CHECK: return;
    match res {
        Ok(x) => x,
        Err(!),
    }
}

// EMIT_MIR never_patterns.opt2.SimplifyCfg-initial.after.mir
fn opt2(res: &Result<u32, Void>) -> &u32 {
    // CHECK-LABEL: fn opt2(
    // CHECK: bb0: {
    // CHECK-NOT: {{bb.*}}: {
    // CHECK: return;
    match res {
        Ok(x) | Err(!) => x,
    }
}

// EMIT_MIR never_patterns.opt3.SimplifyCfg-initial.after.mir
fn opt3(res: &Result<u32, Void>) -> &u32 {
    // CHECK-LABEL: fn opt3(
    // CHECK: bb0: {
    // CHECK-NOT: {{bb.*}}: {
    // CHECK: return;
    match res {
        Err(!) | Ok(x) => x,
    }
}

fn main() {
    assert_eq!(opt1(&Ok(0)), &0);
    assert_eq!(opt2(&Ok(0)), &0);
    assert_eq!(opt3(&Ok(0)), &0);
}