2018-08-30 12:18:55 +00:00
|
|
|
// run-pass
|
2015-03-22 20:13:15 +00:00
|
|
|
|
2015-01-02 22:44:21 +00:00
|
|
|
macro_rules! higher_order {
|
2014-10-12 11:42:41 +00:00
|
|
|
(subst $lhs:tt => $rhs:tt) => ({
|
2015-01-02 22:44:21 +00:00
|
|
|
macro_rules! anon { $lhs => $rhs }
|
2015-02-18 10:42:01 +00:00
|
|
|
anon!(1_usize, 2_usize, "foo")
|
2014-10-12 11:42:41 +00:00
|
|
|
});
|
2015-01-02 22:44:21 +00:00
|
|
|
}
|
2013-06-27 23:53:40 +00:00
|
|
|
|
2016-07-19 20:16:23 +00:00
|
|
|
macro_rules! outer {
|
|
|
|
($x:expr; $fragment:ident) => {
|
|
|
|
macro_rules! inner { ($y:$fragment) => { $x + $y } }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-27 23:53:40 +00:00
|
|
|
fn main() {
|
2014-10-12 11:42:41 +00:00
|
|
|
let val = higher_order!(subst ($x:expr, $y:expr, $foo:expr) => (($x + $y, $foo)));
|
|
|
|
assert_eq!(val, (3, "foo"));
|
2016-07-19 20:16:23 +00:00
|
|
|
|
|
|
|
outer!(2; expr);
|
|
|
|
assert_eq!(inner!(3), 5);
|
2013-06-27 23:53:40 +00:00
|
|
|
}
|