rust/src/test/ui/macros/macro-interpolation.rs

22 lines
479 B
Rust
Raw Normal View History

// run-pass
macro_rules! overly_complicated {
($fnname:ident, $arg:ident, $ty:ty, $body:block, $val:expr, $pat:pat, $res:path) =>
({
2012-08-20 12:23:37 -07:00
fn $fnname($arg: $ty) -> Option<$ty> $body
2012-08-06 12:34:08 -07:00
match $fnname($val) {
2012-08-20 12:23:37 -07:00
Some($pat) => {
2012-08-01 14:34:35 -07:00
$res
}
_ => { panic!(); }
2012-08-01 14:34:35 -07:00
}
})
2012-08-01 14:34:35 -07:00
}
pub fn main() {
assert!(overly_complicated!(f, x, Option<usize>, { return Some(x); },
Some(8), Some(y), y) == 8)
2012-08-01 14:34:35 -07:00
}