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

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

66 lines
901 B
Rust
Raw Normal View History

//@ run-pass
macro_rules! mypat {
2014-05-19 22:14:23 +00:00
() => (
Some('y')
)
}
2014-05-19 22:14:23 +00:00
macro_rules! char_x {
2014-05-19 22:14:23 +00:00
() => (
'x'
)
}
2014-05-19 22:14:23 +00:00
macro_rules! some {
2014-05-19 22:14:23 +00:00
($x:pat) => (
Some($x)
)
}
2014-05-19 22:14:23 +00:00
macro_rules! indirect {
2014-05-19 22:14:23 +00:00
() => (
some!(char_x!())
)
}
2014-05-19 22:14:23 +00:00
macro_rules! ident_pat {
2014-05-19 22:14:23 +00:00
($x:ident) => (
$x
)
}
2014-05-19 22:14:23 +00:00
fn f(c: Option<char>) -> usize {
2014-05-19 22:14:23 +00:00
match c {
Some('x') => 1,
mypat!() => 2,
_ => 3,
}
}
pub fn main() {
assert_eq!(1, f(Some('x')));
assert_eq!(2, f(Some('y')));
assert_eq!(3, f(None));
2014-05-19 22:14:23 +00:00
2015-01-25 21:05:03 +00:00
assert_eq!(1, match Some('x') {
Some(char_x!()) => 1,
_ => 2,
2014-05-19 22:14:23 +00:00
});
2015-01-25 21:05:03 +00:00
assert_eq!(1, match Some('x') {
some!(char_x!()) => 1,
_ => 2,
2014-05-19 22:14:23 +00:00
});
2015-01-25 21:05:03 +00:00
assert_eq!(1, match Some('x') {
indirect!() => 1,
_ => 2,
2014-05-19 22:14:23 +00:00
});
2015-01-25 21:05:03 +00:00
assert_eq!(3, {
let ident_pat!(x) = 2;
x+1
2014-05-19 22:14:23 +00:00
});
}