1 // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
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.
15 macro_rules! foo { () => {
25 macro_rules! m { ($m1:ident, $m2:ident, $x:ident) => {
26 macro_rules! $m1 { () => { ($x, x) } }
28 macro_rules! $m2 { () => { ($x, x) } }
35 assert_eq!(m2!(), (2, 0));
36 assert_eq!(m3!(), (2, 1));
40 assert_eq!(m4!(), (4, 0));
41 assert_eq!(m5!(), (4, 1));
46 ($f:ident : |$x:ident| $e:expr) => {
47 pub fn $f() -> (i32, i32) {
58 fn interpolated_pattern() {
61 ($p:pat, $e:expr) => {
63 assert_eq!((x, $e), (0, 1));
70 fn patterns_in_macro_generated_macros() {
73 ($a:expr, $b:expr) => {
88 assert_eq!(n!(), (2, 1));
95 ($p:pat, $e:expr) => {
96 for result in &[Ok(1), Err(1)] {
98 $p => { assert_eq!(($e, x), (1, 0)); }
99 Err(x) => { assert_eq!(($e, x), (2, 1)); }
111 macro_rules! m { () => { break 'a; } }
119 assert_eq!(foo::f(), (0, 11));
120 interpolated_pattern();
121 patterns_in_macro_generated_macros();