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 //{{{ some more tests ==========================================================
204 macro_rules! test_block {
205 (< $($b:block)* >) => {}
210 test_block!(<{1}{2}>);
212 macro_rules! test_ty {
213 ($($t:ty),* $(,)*) => {}
221 macro_rules! test_path {
222 ($($t:path),* $(,)*) => {}
228 test_path!(std::u8,);
229 test_path!(any, super, super::super::self::path, X<Y>::Z<'a, T=U>);
231 macro_rules! test_meta_block {
232 ($($m:meta)* $b:block) => {};
235 test_meta_block!(windows {});