File tree Expand file tree Collapse file tree 8 files changed +195
-43
lines changed Expand file tree Collapse file tree 8 files changed +195
-43
lines changed Original file line number Diff line number Diff line change 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 ( ) { }
Original file line number Diff line number Diff line change 1+ error: 4th rule of macro `num` is never used
2+ --> $DIR/unused-macro-rules-decl.rs:11:5
3+ |
4+ LL | (four) => { 4 },
5+ | ^^^^^^
6+ |
7+ note: the lint level is defined here
8+ --> $DIR/unused-macro-rules-decl.rs:2:9
9+ |
10+ LL | #![deny(unused_macro_rules)]
11+ | ^^^^^^^^^^^^^^^^^^
12+
13+ error: 2nd rule of macro `num` is never used
14+ --> $DIR/unused-macro-rules-decl.rs:9:5
15+ |
16+ LL | (two) => { 2 },
17+ | ^^^^^
18+
19+ error: 3rd rule of macro `num_rec` is never used
20+ --> $DIR/unused-macro-rules-decl.rs:31:5
21+ |
22+ LL | (three) => {
23+ | ^^^^^^^
24+
25+ error: aborting due to 3 previous errors
26+
Original file line number Diff line number Diff line change 1+ #![ deny( unused_macro_rules) ]
2+ // To make sure we are not hitting this
13#![ deny( unused_macros) ]
24
35// Most simple case
4- macro_rules! unused { //~ ERROR: unused macro definition
5- ( ) => { } ;
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
611}
12+ const _NUM: u8 = num ! ( one) + num ! ( three) ;
713
8- // Test macros created by macros
9- macro_rules! create_macro {
10- ( ) => {
11- macro_rules! m { //~ ERROR: unused macro definition
12- ( ) => { } ;
13- }
14- } ;
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 } ;
1521}
16- create_macro ! ( ) ;
22+ const _NUM_ALLOWED : u8 = num_allowed ! ( one ) + num_allowed ! ( three ) ;
1723
18- #[ allow( unused_macros) ]
19- mod bar {
20- // Test that putting the #[deny] close to the macro's definition
21- // works.
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) ;
2236
23- #[ deny( unused_macros) ]
24- macro_rules! unused { //~ ERROR: unused macro definition
25- ( ) => { } ;
26- }
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 } ;
2744}
45+ const _NUM_EXPORTED: u8 = num_exported ! ( one) + num_exported ! ( three) ;
2846
2947fn main ( ) { }
Original file line number Diff line number Diff line change 1- error: unused macro definition: `unused`
2- --> $DIR/unused-macro-rules.rs:4:14
1+ error: 4th rule of macro `num` is never used
2+ --> $DIR/unused-macro-rules.rs:10:5
33 |
4- LL | macro_rules! unused {
5- | ^^^^^^
4+ LL | (four) => { 4 };
5+ | ^^^^^^
66 |
77note: the lint level is defined here
88 --> $DIR/unused-macro-rules.rs:1:9
99 |
10- LL | #![deny(unused_macros )]
11- | ^^^^^^^^^^^^^
10+ LL | #![deny(unused_macro_rules )]
11+ | ^^^^^^^^^^^^^^^^^^
1212
13- error: unused macro definition: `m`
14- --> $DIR/unused-macro-rules.rs:11:22
13+ error: 2nd rule of macro `num` is never used
14+ --> $DIR/unused-macro-rules.rs:8:5
1515 |
16- LL | macro_rules! m {
17- | ^
16+ LL | (two) => { 2 };
17+ | ^^^^ ^
1818
19- error: unused macro definition: `unused`
20- --> $DIR/unused-macro-rules.rs:24:18
19+ error: 3rd rule of macro `num_rec` is never used
20+ --> $DIR/unused-macro-rules.rs:30:5
2121 |
22- LL | macro_rules! unused {
23- | ^^^^^^
24- |
25- note: the lint level is defined here
26- --> $DIR/unused-macro-rules.rs:23:12
27- |
28- LL | #[deny(unused_macros)]
29- | ^^^^^^^^^^^^^
22+ LL | (three) => {
23+ | ^^^^^^^
3024
3125error: aborting due to 3 previous errors
3226
Original file line number Diff line number Diff line change 11#![ feature( decl_macro) ]
22#![ deny( unused_macros) ]
3+ // To make sure we are not hitting this
4+ #![ deny( unused_macro_rules) ]
35
46// Most simple case
57macro unused { //~ ERROR: unused macro definition
Original file line number Diff line number Diff line change 11error: unused macro definition: `unused`
2- --> $DIR/unused-macro .rs:5 :7
2+ --> $DIR/unused-macros-decl .rs:7 :7
33 |
44LL | macro unused {
55 | ^^^^^^
66 |
77note: the lint level is defined here
8- --> $DIR/unused-macro .rs:2:9
8+ --> $DIR/unused-macros-decl .rs:2:9
99 |
1010LL | #![deny(unused_macros)]
1111 | ^^^^^^^^^^^^^
1212
1313error: unused macro definition: `unused`
14- --> $DIR/unused-macro .rs:15 :11
14+ --> $DIR/unused-macros-decl .rs:17 :11
1515 |
1616LL | macro unused {
1717 | ^^^^^^
1818 |
1919note: the lint level is defined here
20- --> $DIR/unused-macro .rs:14 :12
20+ --> $DIR/unused-macros-decl .rs:16 :12
2121 |
2222LL | #[deny(unused_macros)]
2323 | ^^^^^^^^^^^^^
2424
2525error: unused macro definition: `unused`
26- --> $DIR/unused-macro .rs:21 :22
26+ --> $DIR/unused-macros-decl .rs:23 :22
2727 |
2828LL | pub(crate) macro unused {
2929 | ^^^^^^
Original file line number Diff line number Diff line change 1+ #![ deny( unused_macros) ]
2+ // To make sure we are not hitting this
3+ #![ deny( unused_macro_rules) ]
4+
5+ // Most simple case
6+ macro_rules! unused { //~ ERROR: unused macro definition
7+ ( ) => { } ;
8+ }
9+
10+ // Test macros created by macros
11+ macro_rules! create_macro {
12+ ( ) => {
13+ macro_rules! m { //~ ERROR: unused macro definition
14+ ( ) => { } ;
15+ }
16+ } ;
17+ }
18+ create_macro ! ( ) ;
19+
20+ #[ allow( unused_macros) ]
21+ mod bar {
22+ // Test that putting the #[deny] close to the macro's definition
23+ // works.
24+
25+ #[ deny( unused_macros) ]
26+ macro_rules! unused { //~ ERROR: unused macro definition
27+ ( ) => { } ;
28+ }
29+ }
30+
31+ fn main ( ) { }
Original file line number Diff line number Diff line change 1+ error: unused macro definition: `unused`
2+ --> $DIR/unused-macros.rs:6:14
3+ |
4+ LL | macro_rules! unused {
5+ | ^^^^^^
6+ |
7+ note: the lint level is defined here
8+ --> $DIR/unused-macros.rs:1:9
9+ |
10+ LL | #![deny(unused_macros)]
11+ | ^^^^^^^^^^^^^
12+
13+ error: unused macro definition: `m`
14+ --> $DIR/unused-macros.rs:13:22
15+ |
16+ LL | macro_rules! m {
17+ | ^
18+
19+ error: unused macro definition: `unused`
20+ --> $DIR/unused-macros.rs:26:18
21+ |
22+ LL | macro_rules! unused {
23+ | ^^^^^^
24+ |
25+ note: the lint level is defined here
26+ --> $DIR/unused-macros.rs:25:12
27+ |
28+ LL | #[deny(unused_macros)]
29+ | ^^^^^^^^^^^^^
30+
31+ error: aborting due to 3 previous errors
32+
You can’t perform that action at this time.
0 commit comments