]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass/macro-of-higher-order.rs
New upstream version 1.12.0+dfsg1
[rustc.git] / src / test / run-pass / macro-of-higher-order.rs
CommitLineData
1a4d82fc 1// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
223e47cc
LB
2// file at the top-level directory of this distribution and at
3// http://rust-lang.org/COPYRIGHT.
4//
5// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8// option. This file may not be copied, modified, or distributed
9// except according to those terms.
10
c34b1796 11
1a4d82fc
JJ
12macro_rules! higher_order {
13 (subst $lhs:tt => $rhs:tt) => ({
14 macro_rules! anon { $lhs => $rhs }
85aaf69f 15 anon!(1_usize, 2_usize, "foo")
1a4d82fc 16 });
223e47cc
LB
17}
18
5bcae85e
SL
19macro_rules! outer {
20 ($x:expr; $fragment:ident) => {
21 macro_rules! inner { ($y:$fragment) => { $x + $y } }
22 }
23}
24
223e47cc 25fn main() {
1a4d82fc
JJ
26 let val = higher_order!(subst ($x:expr, $y:expr, $foo:expr) => (($x + $y, $foo)));
27 assert_eq!(val, (3, "foo"));
5bcae85e
SL
28
29 outer!(2; expr);
30 assert_eq!(inner!(3), 5);
223e47cc 31}