blob: 79c68fd254137558c915ab587b2b6f589469fc77 (
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
|
// run-pass
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), )*
_ => None
}
}
}
}
enum_number!(Change {
Down = -1,
None = 0,
Up = 1,
});
fn main() {
if let Some(Change::Down) = foo(-1) {} else { panic!() }
}
|