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