proc_macro_api_tests/
lib.rs

1#![doc = include_str!("../README.md")]
2#![no_implicit_prelude]
3#![no_std]
4
5mod test_invalid_combination;
6
7#[no_link]
8extern crate proc_macro_api;
9use proc_macro_api::proc_macro_api;
10
11use ::base::dummy_api;
12
13dummy_api!(mod ,,,,,,,,,,,);
14
15proc_macro_api!();
16proc_macro_api!({});
17proc_macro_api!(::{});
18proc_macro_api!(a::{});
19proc_macro_api!(::a::{});
20proc_macro_api!(a::a::{});
21proc_macro_api!(::a::a::{});
22
23proc_macro_api! {
24    ,,,,,,,,,
25    /// a
26    /// b
27    #[allow(unused)]
28    #[proc_macro]
29    a::a::a::a::a::a::a::a::a::a::b as norm_t_full_seg_0,
30
31    /// a
32    #[allow(unused)]
33    #[proc_macro]
34    /// b
35    a::a::a::a::a::a::a::a::a::a::b as norm_t_full_seg_1,
36
37    /// a
38    #[proc_macro]
39    /// b
40    #[allow(unused)]
41    a::a::a::a::a::a::a::a::a::a::b as norm_t_full_seg_2,
42
43    /// b
44    #[allow(unused)]
45    #[proc_macro]
46    b as norm_t_empty_rest_0,
47
48    /// b
49    #[allow(unused)]
50    #[proc_macro]
51    a::b as norm_t_one_rest_0,
52
53    #[allow(unused)]
54    #[proc_macro]
55    /// b
56    a::b as norm_t_one_rest_1,
57
58    #[proc_macro]
59    /// b
60    #[allow(unused)]
61    a::b as norm_t_one_rest_2,
62
63    a::{#[fn] b as norm_t_one_rest_out_0},
64
65    a::a::{#[fn] b as norm_t_one_prv_0},
66
67    #[fn] b as norm_t_alias_fn_0,
68    #[proc_macro] b as norm_t_alias_fn_1,
69    #[at] c as norm_t_alias_at_0,
70    #[proc_macro_attribute] c as norm_t_alias_at_1,
71    #[dr(norm_t_AliasDr0)] b as norm_t_alias_dr_0,
72    #[proc_macro_derive(norm_t_AliasDr1)] b as norm_t_alias_dr_1,
73
74    a::a::a::{#[fn] b as norm_t_seg_matcher_0},
75    {#[fn] b as norm_t_seg_matcher_1},
76    ::a as _,
77    ::a::a as _,
78    ::a::a::{},
79    ::{},
80    {},,,,,,,,,
81
82    a::{a::{#[fn] b as norm_t_no_trailing_comma_0}},
83}
84
85proc_macro_api! {
86    ,,,,,,,,,
87    #[fn] ::base::b as norm_t_cc_0,
88    ::base::{#[fn] b as norm_t_cc_1},
89    ::base::a::{#[fn] b as norm_t_cc_2},
90    ::{#[fn] base::b as norm_t_cc_3},
91}
92
93mod no_as {
94    macro_rules! no_as {
95        ($name:ident) => {
96            #[inline(always)]
97            pub fn $name(_input: TokenStream) -> TokenStream {
98                let name = stringify!($name);
99
100                quote! {
101                    #name
102                }
103                .into()
104            }
105        };
106    }
107
108    macro_rules! no_as_mod {
109        ($name_0:ident, $name_1:ident $(; $($tt:tt)*)?) => {
110            use ::core::convert::Into as _;
111            use ::proc_macro::TokenStream;
112            use ::quote::quote;
113            no_as!($name_0);
114            no_as!($name_1);
115
116            $(
117            pub mod a {
118                no_as_mod!($($tt)*);
119            }
120            )?
121        };
122
123        () => {};
124    }
125
126    no_as_mod! {
127        norm_t_no_as_0, norm_t_no_as_1;
128        norm_t_no_as_2, norm_t_no_as_3;
129        norm_t_no_as_4, norm_t_no_as_5;
130        norm_t_no_as_6, norm_t_no_as_7;
131    }
132}
133
134proc_macro_api! {
135    {
136        #[fn] no_as::norm_t_no_as_0,
137        #[fn] no_as::norm_t_no_as_1,
138    },
139    {
140        #[fn] no_as::a::norm_t_no_as_2,
141        #[fn] no_as::a::norm_t_no_as_3,
142    },
143    {
144        #[fn] no_as::a::a::norm_t_no_as_4,
145        #[fn] no_as::a::a::norm_t_no_as_5,
146    },
147    no_as::a::a::a::{
148        #[fn] norm_t_no_as_6,
149        #[fn] norm_t_no_as_7,
150    },
151}
152
153proc_macro_api! {
154    {
155        #[fn]#[doc=""] b as norm_t_seg_matcher_2_0,
156        #[fn]#[doc=""] b as norm_t_seg_matcher_2_1,
157    },
158    {
159        #[fn] a::b as norm_t_seg_matcher_3_0,
160        #[fn] a::b as norm_t_seg_matcher_3_1,
161    },
162    {
163        #[fn] a::a::b as norm_t_seg_matcher_4_0,
164        #[fn] a::a::b as norm_t_seg_matcher_4_1,
165    },
166    {
167        #[fn] a::a::a::b as norm_t_seg_matcher_5_0,
168        #[fn] a::a::a::b as norm_t_seg_matcher_5_1,
169    },
170    {
171        a::{#[fn] a::a::a::b as norm_t_seg_matcher_6_0},
172        a::{#[fn] a::a::a::b as norm_t_seg_matcher_6_1},
173    },
174    {
175        a::a::{#[fn] a::a::a::b as norm_t_seg_matcher_7_0},
176        a::a::{#[fn] a::a::a::b as norm_t_seg_matcher_7_1},
177    },
178    {
179        a::a::a::{#[fn] a::a::a::b as norm_t_seg_matcher_8_0},
180        a::a::a::{#[fn] a::a::a::b as norm_t_seg_matcher_8_1},
181    },
182    {
183        a::a::a::a::{#[fn] a::a::a::b as norm_t_seg_matcher_9_0},
184        a::a::a::a::{#[fn] a::a::a::b as norm_t_seg_matcher_9_1},
185    },
186    {
187        #[fn]#[doc=""] ::b as _,
188        #[fn]#[doc=""] ::b as _,
189    },
190    {
191        #[fn] ::base::b as norm_t_seg_matcher_10_0,
192        #[fn] ::base::b as norm_t_seg_matcher_10_1,
193    },
194    {
195        #[fn] ::base::a::b as norm_t_seg_matcher_11_0,
196        #[fn] ::base::a::b as norm_t_seg_matcher_11_1,
197    },
198    {
199        ::base::{#[fn] a::a::b as norm_t_seg_matcher_12_0},
200        ::base::{#[fn] a::a::b as norm_t_seg_matcher_12_1},
201    },
202    {
203        ::base::a::{#[fn] a::a::b as norm_t_seg_matcher_13_0},
204        ::base::a::{#[fn] a::a::b as norm_t_seg_matcher_13_1},
205    },
206    {
207        ::base::a::a::{#[fn] a::a::b as norm_t_seg_matcher_14_0},
208        ::base::a::a::{#[fn] a::a::b as norm_t_seg_matcher_14_1},
209    },
210    {
211        ::{#[fn] base::a::a::a::a::a::b as norm_t_seg_matcher_15_0},
212        ::{#[fn] base::a::a::a::a::a::b as norm_t_seg_matcher_15_1},
213    },
214}
215
216#[cfg(feature = "auto_transform")]
217mod pm2 {
218    use ::base::dummy_api;
219
220    dummy_api!(pub pm2 mod ,,,,,,,,,,,);
221}
222
223#[cfg(feature = "auto_transform")]
224const PM2_B: fn(::proc_macro2::TokenStream) -> ::proc_macro2::TokenStream = pm2::b;
225
226#[cfg(feature = "auto_transform")]
227const PM2_C: fn(
228    ::proc_macro2::TokenStream,
229    ::proc_macro2::TokenStream,
230) -> ::proc_macro2::TokenStream = pm2::c;
231
232#[cfg(feature = "auto_transform")]
233proc_macro_api! {
234    #[fn] pm2::b as trans_t_trans_0,
235    #[at] pm2::c as trans_t_trans_1,
236    #[fn] PM2_B as trans_t_trans_2,
237    #[at] PM2_C as trans_t_trans_3,
238    #[fn] ::base::pm2::b as trans_t_cc_trans_0,
239    #[at] ::base::pm2::c as trans_t_cc_trans_1,
240}
241
242#[cfg(feature = "attr_tests")]
243#[cfg(not(feature = "deny_group_attr"))]
244#[cfg(not(feature = "deny_append"))]
245#[cfg(not(feature = "deny_override"))]
246#[cfg(not(feature = "with_default"))]
247proc_macro_api! {
248    /// ```no_run
249    #[cfg(feature = "attr_tests")]
250    /// let ok: i32;
251    #[cfg(not(feature = "attr_tests"))]
252    #[at]
253    {
254        /// ```
255        #[cfg(feature = "attr_tests")]
256        /// let MissingTheOuterDoc: () = 0;
257        #[cfg(feature = "attr_tests")]
258        /// ```no_run
259        /// ```
260        #[fn] b as attr_gp_ap_ov_t_global_local_0,
261
262        /// ```
263        #[cfg(feature = "attr_tests")]
264        /// let MissingTheOuterDoc: () = 0;
265        #[cfg(feature = "attr_tests")]
266        /// ```no_run
267        /// ```
268        a::c as attr_gp_ap_ov_t_global_local_1,
269    },
270
271    #[cfg(feature = "attr_tests")]
272    /// ```no_run
273    #[cfg(feature = "attr_tests")]
274    /// let ok: i32;
275    #[at]
276    {
277        #[cfg(feature = "attr_tests")]
278        /// ```
279        #[cfg(feature = "attr_tests")]
280        /// let MissingTheOuterDoc: () = 0;
281        /// ```no_run
282        /// ```
283        #[fn] b as attr_gp_ap_ov_t_global_local_0,
284
285        #[cfg(feature = "attr_tests")]
286        /// ```
287        #[cfg(feature = "attr_tests")]
288        /// let MissingTheOuterDoc: () = 0;
289        /// ```no_run
290        /// ```
291        a::c as attr_gp_ap_ov_t_global_local_1,
292    },
293
294    /// ```no_run
295    #[cfg(feature = "attr_tests")]
296    /// #![no_implicit_prelude]
297    /// fn main() {
298    /// let err: MissingTheInnerDoc;
299    /// }
300    #[cfg(feature = "attr_tests")]
301    #[at]
302    {
303        #[cfg(feature = "attr_tests")]
304        /// struct MissingTheInnerDoc;
305        #[cfg(not(feature = "attr_tests"))]
306        /// ```
307        c as attr_gp_ap_ov_t_global_local_2,
308
309        #[cfg(feature = "attr_tests")]
310        /// struct MissingTheInnerDoc;
311        #[cfg(feature = "attr_tests")]
312        /// ```
313        #[fn] a::b as attr_gp_ap_ov_t_global_local_3,
314    },
315
316    #[cfg(feature = "attr_tests")]
317    /// ```no_run
318    #[cfg(feature = "attr_tests")]
319    /// #![no_implicit_prelude]
320    /// fn main() {
321    /// let err: MissingTheInnerDoc;
322    /// }
323    #[at]
324    {
325        /// struct MissingTheInnerDoc;
326        #[cfg(feature = "attr_tests")]
327        /// ```
328        #[cfg(feature = "attr_tests")]
329        c as attr_gp_ap_ov_t_global_local_2,
330
331        /// struct MissingTheInnerDoc;
332        #[cfg(not(feature = "attr_tests"))]
333        /// ```
334        #[cfg(feature = "attr_tests")]
335        #[fn] a::b as attr_gp_ap_ov_t_global_local_3,
336    },
337}
338
339#[cfg(feature = "attr_tests")]
340#[cfg(not(feature = "deny_group_attr"))]
341#[cfg(not(feature = "deny_override"))]
342#[cfg(not(feature = "with_default"))]
343proc_macro_api! {
344    #[at] {#[fn] b as attr_gp_ov_t_override_0},
345    #[at] {#[dr(attr_gp_ov_t_Override1)] b as attr_gp_ov_t_override_1},
346    #[fn] {#[at] c as attr_gp_ov_t_override_2},
347
348    #[at] {#[fn] {b as attr_gp_ov_t_bg_proc_oth_0}},
349
350    #[at] {#[dr] {#[fn] {b as attr_gp_ov_t_call_at_bg_0}}},
351
352    #[at] {#[dr] {#[fn] b as attr_gp_ov_t_prs_fn_bg_0}},
353}
354
355#[cfg(feature = "attr_tests")]
356#[cfg(not(feature = "deny_group_attr"))]
357#[cfg(not(feature = "deny_override"))]
358#[cfg(not(feature = "deny_shadow"))]
359#[cfg(not(feature = "with_default"))]
360proc_macro_api! {
361    #[at]#[at]#[at]#[at] {#[fn] b as attr_gp_ov_sh_t_oth_proc_0},
362
363    #[at]#[at] {#[fn] b as attr_gp_ov_sh_t_bg_proc_oth_1},
364}
365
366#[cfg(feature = "attr_tests")]
367#[cfg(not(feature = "deny_group_attr"))]
368#[cfg(not(feature = "deny_append"))]
369#[cfg(not(feature = "with_default"))]
370proc_macro_api! {
371    /// ```no_run
372    #[cfg(feature = "attr_tests")]
373    /// let ok: i32;
374    #[cfg(not(feature = "attr_tests"))]
375    #[fn]
376    {
377        /// ```
378        #[cfg(feature = "attr_tests")]
379        /// let MissingTheOuterDoc: () = 0;
380        #[cfg(feature = "attr_tests")]
381        /// ```no_run
382        /// ```
383        b as attr_gp_ap_t_global_local_0,
384
385        /// ```
386        #[cfg(feature = "attr_tests")]
387        /// let MissingTheOuterDoc: () = 0;
388        #[cfg(feature = "attr_tests")]
389        /// ```no_run
390        /// ```
391        a::b as attr_gp_ap_t_global_local_1,
392    },
393
394    #[cfg(feature = "attr_tests")]
395    /// ```no_run
396    #[cfg(feature = "attr_tests")]
397    /// let ok: i32;
398    #[fn]
399    {
400        #[cfg(feature = "attr_tests")]
401        /// ```
402        #[cfg(feature = "attr_tests")]
403        /// let MissingTheOuterDoc: () = 0;
404        /// ```no_run
405        /// ```
406        b as attr_gp_ap_t_global_local_0,
407
408        #[cfg(feature = "attr_tests")]
409        /// ```
410        #[cfg(feature = "attr_tests")]
411        /// let MissingTheOuterDoc: () = 0;
412        /// ```no_run
413        /// ```
414        a::b as attr_gp_ap_t_global_local_1,
415    },
416
417    /// a
418    {
419        #[fn] b as attr_gp_ap_t_bg_proc_doc_oth_0,
420
421        /// a
422        #[fn] {b as attr_gp_ap_t_bg_proc_doc_oth_1},
423    },
424}
425
426#[cfg(feature = "attr_tests")]
427#[cfg(not(feature = "deny_group_attr"))]
428#[cfg(not(feature = "with_default"))]
429proc_macro_api! {
430    #[fn] {{b as attr_gp_t_call_at_bg_1}},
431
432    #[doc=""] {#[fn] a::b as attr_gp_t_err_ap_0},
433    #[fn] {#[doc=""] a::a::b as attr_gp_t_err_ov_0},
434}
435
436#[allow(unused)]
437macro_rules! error {
438    ($($name:ident : { $($tt:tt)* }),* $(,)?) => {$(
439        /// ```no_run
440        /// #![no_implicit_prelude]
441        /// #![no_std]
442        /// mod _a {
443        /// use ::proc_macro_api::proc_macro_api;
444        #[doc = concat!("proc_macro_api!\n{ ",
445            $(stringify!($tt), " ",)*
446        "}")]
447        /// }
448        /// fn main() {}
449        /// ```
450        #[allow(dead_code)]
451        fn $name() {}
452    )*};
453}
454
455#[cfg(feature = "non_optional_err")]
456mod nop_err;
457
458#[cfg(not(feature = "comp_err"))]
459mod comp_err;
460
461#[cfg(feature = "comp_err")]
462include!("./comp_err.rs");
463
464#[cfg(feature = "err_attr_tests")]
465mod err_attr;
466
467#[cfg(feature = "playground")]
468#[macro_use]
469mod playground;
470
471#[cfg(feature = "playground")]
472playground!();