summaryrefslogtreecommitdiffstats
path: root/src/test/ui/consts/control-flow/feature-gate-const-if-match.rs
blob: cb66bc75309b63447612744c4a239e29380f01e0 (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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// check-pass

const _: i32 = if true { 5 } else { 6 };

const _: i32 = if let Some(true) = Some(false) { 0 } else { 1 };

const _: i32 = match 1 {
    2 => 3,
    4 => 5,
    _ => 0,
};

static FOO: i32 = {
    let x = if true { 0 } else { 1 };
    let x = match x {
        0 => 1,
        _ => 0,
    };
    if let Some(x) = Some(x) { x } else { 1 }
};

static mut BAR: i32 = {
    let x = if true { 0 } else { 1 };
    let x = match x {
        0 => 1,
        _ => 0,
    };
    if let Some(x) = Some(x) { x } else { 1 }
};

const fn if_() -> i32 {
    if true { 5 } else { 6 }
}

const fn if_let(a: Option<bool>) -> i32 {
    if let Some(true) = a { 0 } else { 1 }
}

const fn match_(i: i32) -> i32 {
    match i {
        i if i > 10 => i,
        1 => 2,
        _ => 0,
    }
}

pub trait Foo {
    const IF: i32 = if true { 5 } else { 6 };
    const IF_LET: i32 = if let Some(true) = None { 5 } else { 6 };
    const MATCH: i32 = match 0 {
        1 => 2,
        _ => 0,
    };
}

impl Foo for () {
    const IF: i32 = if true { 5 } else { 6 };
    const IF_LET: i32 = if let Some(true) = None { 5 } else { 6 };
    const MATCH: i32 = match 0 {
        1 => 2,
        _ => 0,
    };
}

fn non_const_outside() {
    const fn const_inside(y: bool) -> i32 {
        let x = if y { 0 } else { 1 };
        let x = match x {
            0 => 1,
            _ => 0,
        };
        if let Some(x) = Some(x) { x } else { 1 }
    }
}

const fn const_outside() {
    fn non_const_inside(y: bool) -> i32 {
        let x = if y { 0 } else { 1 };
        let x = match x {
            0 => 1,
            _ => 0,
        };
        if let Some(x) = Some(x) { x } else { 1 }
    }
}

fn main() {
    let _ = [0; {
        let x = if false { 0 } else { 1 };
        let x = match x {
            0 => 1,
            _ => 0,
        };
        if let Some(x) = Some(x) { x } else { 1 }
    }];
}