summaryrefslogtreecommitdiffstats
path: root/tests/ui/pattern/patkind-litrange-no-expr.rs
blob: 7ef541cb58528d39a5eae25eb1199632f1a9d5a4 (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
macro_rules! enum_number {
    ($name:ident { $($variant:ident = $value:expr, )* }) => {
        enum $name {
            $($variant = $value,)*
        }

        fn foo(value: i32) -> Option<$name> {
            match value {
                $( $value => Some($name::$variant), )* // PatKind::Lit
                $( $value ..= 42 => Some($name::$variant), )* // PatKind::Range
                _ => None
            }
        }
    }
}

enum_number!(Change {
    Pos = 1,
    Neg = -1,
    Arith = 1 + 1, //~ ERROR arbitrary expressions aren't allowed in patterns
                   //~| ERROR arbitrary expressions aren't allowed in patterns
});

fn main() {}