mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-02 19:53:46 +00:00
25 lines
662 B
Rust
25 lines
662 B
Rust
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() {}
|