]> git.lizzy.rs Git - rust.git/blob - tests/ui/lint/unused/unused-macro-rules-decl.rs
Auto merge of #106503 - cjgillot:remap-nofilter, r=oli-obk
[rust.git] / tests / ui / lint / unused / unused-macro-rules-decl.rs
1 #![feature(decl_macro)]
2 #![deny(unused_macro_rules)]
3 // To make sure we are not hitting this
4 #![deny(unused_macros)]
5
6 // Most simple case
7 macro num {
8     (one) => { 1 },
9     (two) => { 2 }, //~ ERROR: 2nd rule of macro
10     (three) => { 3 },
11     (four) => { 4 }, //~ ERROR: 4th rule of macro
12 }
13 const _NUM: u8 = num!(one) + num!(three);
14
15 // Check that allowing the lint works
16 #[allow(unused_macro_rules)]
17 macro num_allowed {
18     (one) => { 1 },
19     (two) => { 2 },
20     (three) => { 3 },
21     (four) => { 4 },
22 }
23 const _NUM_ALLOWED: u8 = num_allowed!(one) + num_allowed!(three);
24
25 // Check that macro calls inside the macro trigger as usage
26 macro num_rec {
27     (one) => { 1 },
28     (two) => {
29         num_rec!(one) + num_rec!(one)
30     },
31     (three) => { //~ ERROR: 3rd rule of macro
32         num_rec!(one) + num_rec!(two)
33     },
34     (four) => {
35         num_rec!(two) + num_rec!(two)
36     },
37 }
38 const _NUM_RECURSIVE: u8 = num_rec!(four);
39
40 // No error if the macro is public
41 pub macro num_public {
42     (one) => { 1 },
43     (two) => { 2 },
44     (three) => { 3 },
45     (four) => { 4 },
46 }
47 const _NUM_PUBLIC: u8 = num_public!(one) + num_public!(three);
48
49 fn main() {}