1 // Copyright 2017 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.
11 #![feature(macro_vis_matcher)]
13 //{{{ issue 40569 ==============================================================
15 macro_rules! my_struct {
16 ($(#[$meta:meta])* $ident:ident) => {
17 $(#[$meta])* struct $ident;
21 my_struct!(#[derive(Debug, PartialEq)] Foo40569);
24 assert_eq!(Foo40569, Foo40569);
29 //{{{ issue 26444 ==============================================================
31 macro_rules! foo_26444 {
32 ($($beginning:ident),*; $middle:ident; $($end:ident),*) => {
33 stringify!($($beginning,)* $middle $(,$end)*)
38 assert_eq!("a , b , c , d , e", foo_26444!(a, b; c; d, e));
39 assert_eq!("f", foo_26444!(; f ;));
42 macro_rules! pat_26444 {
43 ($fname:ident $($arg:pat)* =) => {}
46 pat_26444!(foo 1 2 5...7 =);
47 pat_26444!(bar Some(ref x) Ok(ref mut y) &(w, z) =);
51 //{{{ issue 40984 ==============================================================
53 macro_rules! thread_local_40984 {
55 ($(#[$attr:meta])* $vis:vis static $name:ident: $t:ty = $init:expr; $($rest:tt)*) => {
56 thread_local_40984!($($rest)*);
58 ($(#[$attr:meta])* $vis:vis static $name:ident: $t:ty = $init:expr) => {};
66 pub static BAR: String = String::from("bar");
68 // look at these restrictions!!
69 pub(crate) static BAZ: usize = 0;
70 pub(in foo) static QUUX: usize = 0;
75 //{{{ issue 35650 ==============================================================
79 std::mem::size_of::<$ty>()
87 assert_eq!(size!(u64), 8);
88 assert_eq!(size!(5), 5);
93 //{{{ issue 27832 ==============================================================
97 ( $t:tt $j:tt ) => ();
108 ( $t:tt $u:tt ) => ();
118 //{{{ issue 39964 ==============================================================
120 macro_rules! foo_39964 {
129 //{{{ issue 34030 ==============================================================
131 macro_rules! foo_34030 {
132 ($($t:ident),* /) => {};
141 //{{{ issue 24189 ==============================================================
143 macro_rules! foo_24189 {
145 pub enum $name:ident {
146 $( #[$attr:meta] )* $var:ident
161 macro_rules! serializable {
163 $(#[$struct_meta:meta])*
164 pub struct $name:ident {
166 $(#[$field_meta:meta])*
167 $field:ident: $type_:ty
190 macro_rules! foo_24189_c {
191 ( $( > )* $x:ident ) => { };
196 let _ = Foo24189::Baz;
197 let _ = Tester { name: "".to_owned() };
202 //{{{ issue 50903 ==============================================================
204 macro_rules! foo_50903 {
205 ($($lif:lifetime ,)* #) => {};
208 foo_50903!('a, 'b, #);
214 //{{{ issue 51477 ==============================================================
216 macro_rules! foo_51477 {
217 ($lifetime:lifetime) => {
218 "last token is lifetime"
221 "last token is other"
223 ($first:tt $($rest:tt)*) => {
224 foo_51477!($($rest)*)
229 assert_eq!("last token is lifetime", foo_51477!('a));
230 assert_eq!("last token is other", foo_51477!(@));
231 assert_eq!("last token is lifetime", foo_51477!(@ {} 'a));
236 //{{{ some more tests ==========================================================
238 macro_rules! test_block {
239 (< $($b:block)* >) => {}
244 test_block!(<{1}{2}>);
246 macro_rules! test_ty {
247 ($($t:ty),* $(,)*) => {}
255 macro_rules! test_path {
256 ($($t:path),* $(,)*) => {}
262 test_path!(std::u8,);
263 test_path!(any, super, super::super::self::path, X<Y>::Z<'a, T=U>);
265 macro_rules! test_meta_block {
266 ($($m:meta)* $b:block) => {};
269 test_meta_block!(windows {});
271 macro_rules! test_lifetime {
272 (1. $($l:lifetime)* $($b:block)*) => {};
273 (2. $($b:block)* $($l:lifetime)*) => {};
276 test_lifetime!(1. 'a 'b {} {});
277 test_lifetime!(2. {} {} 'a 'b);