File tree 8 files changed +195
-43
lines changed
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
1
3
#![ deny( unused_macros) ]
2
4
3
5
// 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
6
11
}
12
+ const _NUM: u8 = num ! ( one) + num ! ( three) ;
7
13
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 } ;
15
21
}
16
- create_macro ! ( ) ;
22
+ const _NUM_ALLOWED : u8 = num_allowed ! ( one ) + num_allowed ! ( three ) ;
17
23
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) ;
22
36
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 } ;
27
44
}
45
+ const _NUM_EXPORTED: u8 = num_exported ! ( one) + num_exported ! ( three) ;
28
46
29
47
fn 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
3
3
|
4
- LL | macro_rules! unused {
5
- | ^^^^^^
4
+ LL | (four) => { 4 };
5
+ | ^^^^^^
6
6
|
7
7
note: the lint level is defined here
8
8
--> $DIR/unused-macro-rules.rs:1:9
9
9
|
10
- LL | #![deny(unused_macros )]
11
- | ^^^^^^^^^^^^^
10
+ LL | #![deny(unused_macro_rules )]
11
+ | ^^^^^^^^^^^^^^^^^^
12
12
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
15
15
|
16
- LL | macro_rules! m {
17
- | ^
16
+ LL | (two) => { 2 };
17
+ | ^^^^ ^
18
18
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
21
21
|
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
+ | ^^^^^^^
30
24
31
25
error: aborting due to 3 previous errors
32
26
Original file line number Diff line number Diff line change 1
1
#![ feature( decl_macro) ]
2
2
#![ deny( unused_macros) ]
3
+ // To make sure we are not hitting this
4
+ #![ deny( unused_macro_rules) ]
3
5
4
6
// Most simple case
5
7
macro unused { //~ ERROR: unused macro definition
Original file line number Diff line number Diff line change 1
1
error: unused macro definition: `unused`
2
- --> $DIR/unused-macro .rs:5 :7
2
+ --> $DIR/unused-macros-decl .rs:7 :7
3
3
|
4
4
LL | macro unused {
5
5
| ^^^^^^
6
6
|
7
7
note: the lint level is defined here
8
- --> $DIR/unused-macro .rs:2:9
8
+ --> $DIR/unused-macros-decl .rs:2:9
9
9
|
10
10
LL | #![deny(unused_macros)]
11
11
| ^^^^^^^^^^^^^
12
12
13
13
error: unused macro definition: `unused`
14
- --> $DIR/unused-macro .rs:15 :11
14
+ --> $DIR/unused-macros-decl .rs:17 :11
15
15
|
16
16
LL | macro unused {
17
17
| ^^^^^^
18
18
|
19
19
note: the lint level is defined here
20
- --> $DIR/unused-macro .rs:14 :12
20
+ --> $DIR/unused-macros-decl .rs:16 :12
21
21
|
22
22
LL | #[deny(unused_macros)]
23
23
| ^^^^^^^^^^^^^
24
24
25
25
error: unused macro definition: `unused`
26
- --> $DIR/unused-macro .rs:21 :22
26
+ --> $DIR/unused-macros-decl .rs:23 :22
27
27
|
28
28
LL | pub(crate) macro unused {
29
29
| ^^^^^^
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