rust/tests/ui/macros/macro-pat-neg-lit.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

26 lines
498 B
Rust
Raw Normal View History

//@ 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!() }
}