2 #![allow(unused_macro_rules)]
4 //{{{ issue 40569 ==============================================================
6 macro_rules! my_struct {
7 ($(#[$meta:meta])* $ident:ident) => {
8 $(#[$meta])* struct $ident;
12 my_struct!(#[derive(Debug, PartialEq)] Foo40569);
15 assert_eq!(Foo40569, Foo40569);
20 //{{{ issue 26444 ==============================================================
22 macro_rules! foo_26444 {
23 ($($beginning:ident),*; $middle:ident; $($end:ident),*) => {
24 stringify!($($beginning,)* $middle $(,$end)*)
29 assert_eq!("a, b, c, d, e", foo_26444!(a, b; c; d, e));
30 assert_eq!("f", foo_26444!(; f ;));
33 macro_rules! pat_26444 {
34 ($fname:ident $($arg:pat)* =) => {}
37 pat_26444!(foo 1 2 5...7 =);
38 pat_26444!(bar Some(ref x) Ok(ref mut y) &(w, z) =);
42 //{{{ issue 40984 ==============================================================
44 macro_rules! thread_local_40984 {
46 ($(#[$attr:meta])* $vis:vis static $name:ident: $t:ty = $init:expr; $($rest:tt)*) => {
47 thread_local_40984!($($rest)*);
49 ($(#[$attr:meta])* $vis:vis static $name:ident: $t:ty = $init:expr) => {};
57 pub static BAR: String = String::from("bar");
59 // look at these restrictions!!
60 pub(crate) static BAZ: usize = 0;
61 pub(in foo) static QUUX: usize = 0;
66 //{{{ issue 35650 ==============================================================
70 std::mem::size_of::<$ty>()
78 assert_eq!(size!(u64), 8);
79 assert_eq!(size!(5), 5);
84 //{{{ issue 27832 ==============================================================
88 ( $t:tt $j:tt ) => ();
99 ( $t:tt $u:tt ) => ();
109 //{{{ issue 39964 ==============================================================
111 macro_rules! foo_39964 {
120 //{{{ issue 34030 ==============================================================
122 macro_rules! foo_34030 {
123 ($($t:ident),* /) => {};
132 //{{{ issue 24189 ==============================================================
134 macro_rules! foo_24189 {
136 pub enum $name:ident {
137 $( #[$attr:meta] )* $var:ident
152 macro_rules! serializable {
154 $(#[$struct_meta:meta])*
155 pub struct $name:ident {
157 $(#[$field_meta:meta])*
158 $field:ident: $type_:ty
181 macro_rules! foo_24189_c {
182 ( $( > )* $x:ident ) => { };
187 let _ = Foo24189::Baz;
188 let _ = Tester { name: "".to_owned() };
193 //{{{ issue 50903 ==============================================================
195 macro_rules! foo_50903 {
196 ($($lif:lifetime ,)* #) => {};
199 foo_50903!('a, 'b, #);
205 //{{{ issue 51477 ==============================================================
207 macro_rules! foo_51477 {
208 ($lifetime:lifetime) => {
209 "last token is lifetime"
212 "last token is other"
214 ($first:tt $($rest:tt)*) => {
215 foo_51477!($($rest)*)
220 assert_eq!("last token is lifetime", foo_51477!('a));
221 assert_eq!("last token is other", foo_51477!(@));
222 assert_eq!("last token is lifetime", foo_51477!(@ {} 'a));
227 //{{{ some more tests ==========================================================
229 macro_rules! test_block {
230 (< $($b:block)* >) => {}
235 test_block!(<{1}{2}>);
237 macro_rules! test_ty {
238 ($($t:ty),* $(,)*) => {}
246 macro_rules! test_path {
247 ($($t:path),* $(,)*) => {}
253 test_path!(std::ops,);
254 test_path!(any, super, super::super::self::path, X<Y>::Z<'a, T=U>);
256 macro_rules! test_lifetime {
257 (1. $($l:lifetime)* $($b:block)*) => {};
258 (2. $($b:block)* $($l:lifetime)*) => {};
261 test_lifetime!(1. 'a 'b {} {});
262 test_lifetime!(2. {} {} 'a 'b);