Add tests
Also rename the test files for the unused_macros lint to avoid confusion. The test files now follow a <lint_name><-maybe-decl>.rs scheme.
This commit is contained in:
parent
5646e9a172
commit
d76a9394ba
8 changed files with 195 additions and 43 deletions
49
src/test/ui/lint/unused/unused-macro-rules-decl.rs
Normal file
49
src/test/ui/lint/unused/unused-macro-rules-decl.rs
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
#![feature(decl_macro)]
|
||||||
|
#![deny(unused_macro_rules)]
|
||||||
|
// To make sure we are not hitting this
|
||||||
|
#![deny(unused_macros)]
|
||||||
|
|
||||||
|
// Most simple case
|
||||||
|
macro num {
|
||||||
|
(one) => { 1 },
|
||||||
|
(two) => { 2 }, //~ ERROR: 2nd rule of macro
|
||||||
|
(three) => { 3 },
|
||||||
|
(four) => { 4 }, //~ ERROR: 4th rule of macro
|
||||||
|
}
|
||||||
|
const _NUM: u8 = num!(one) + num!(three);
|
||||||
|
|
||||||
|
// Check that allowing the lint works
|
||||||
|
#[allow(unused_macro_rules)]
|
||||||
|
macro num_allowed {
|
||||||
|
(one) => { 1 },
|
||||||
|
(two) => { 2 },
|
||||||
|
(three) => { 3 },
|
||||||
|
(four) => { 4 },
|
||||||
|
}
|
||||||
|
const _NUM_ALLOWED: u8 = num_allowed!(one) + num_allowed!(three);
|
||||||
|
|
||||||
|
// Check that macro calls inside the macro trigger as usage
|
||||||
|
macro num_rec {
|
||||||
|
(one) => { 1 },
|
||||||
|
(two) => {
|
||||||
|
num_rec!(one) + num_rec!(one)
|
||||||
|
},
|
||||||
|
(three) => { //~ ERROR: 3rd rule of macro
|
||||||
|
num_rec!(one) + num_rec!(two)
|
||||||
|
},
|
||||||
|
(four) => {
|
||||||
|
num_rec!(two) + num_rec!(two)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
const _NUM_RECURSIVE: u8 = num_rec!(four);
|
||||||
|
|
||||||
|
// No error if the macro is public
|
||||||
|
pub macro num_public {
|
||||||
|
(one) => { 1 },
|
||||||
|
(two) => { 2 },
|
||||||
|
(three) => { 3 },
|
||||||
|
(four) => { 4 },
|
||||||
|
}
|
||||||
|
const _NUM_PUBLIC: u8 = num_public!(one) + num_public!(three);
|
||||||
|
|
||||||
|
fn main() {}
|
26
src/test/ui/lint/unused/unused-macro-rules-decl.stderr
Normal file
26
src/test/ui/lint/unused/unused-macro-rules-decl.stderr
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
error: 4th rule of macro `num` is never used
|
||||||
|
--> $DIR/unused-macro-rules-decl.rs:11:5
|
||||||
|
|
|
||||||
|
LL | (four) => { 4 },
|
||||||
|
| ^^^^^^
|
||||||
|
|
|
||||||
|
note: the lint level is defined here
|
||||||
|
--> $DIR/unused-macro-rules-decl.rs:2:9
|
||||||
|
|
|
||||||
|
LL | #![deny(unused_macro_rules)]
|
||||||
|
| ^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: 2nd rule of macro `num` is never used
|
||||||
|
--> $DIR/unused-macro-rules-decl.rs:9:5
|
||||||
|
|
|
||||||
|
LL | (two) => { 2 },
|
||||||
|
| ^^^^^
|
||||||
|
|
||||||
|
error: 3rd rule of macro `num_rec` is never used
|
||||||
|
--> $DIR/unused-macro-rules-decl.rs:31:5
|
||||||
|
|
|
||||||
|
LL | (three) => {
|
||||||
|
| ^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to 3 previous errors
|
||||||
|
|
|
@ -1,29 +1,47 @@
|
||||||
|
#![deny(unused_macro_rules)]
|
||||||
|
// To make sure we are not hitting this
|
||||||
#![deny(unused_macros)]
|
#![deny(unused_macros)]
|
||||||
|
|
||||||
// Most simple case
|
// Most simple case
|
||||||
macro_rules! unused { //~ ERROR: unused macro definition
|
macro_rules! num {
|
||||||
() => {};
|
(one) => { 1 };
|
||||||
|
(two) => { 2 }; //~ ERROR: 2nd rule of macro
|
||||||
|
(three) => { 3 };
|
||||||
|
(four) => { 4 }; //~ ERROR: 4th rule of macro
|
||||||
}
|
}
|
||||||
|
const _NUM: u8 = num!(one) + num!(three);
|
||||||
|
|
||||||
// Test macros created by macros
|
// Check that allowing the lint works
|
||||||
macro_rules! create_macro {
|
#[allow(unused_macro_rules)]
|
||||||
() => {
|
macro_rules! num_allowed {
|
||||||
macro_rules! m { //~ ERROR: unused macro definition
|
(one) => { 1 };
|
||||||
() => {};
|
(two) => { 2 };
|
||||||
}
|
(three) => { 3 };
|
||||||
|
(four) => { 4 };
|
||||||
|
}
|
||||||
|
const _NUM_ALLOWED: u8 = num_allowed!(one) + num_allowed!(three);
|
||||||
|
|
||||||
|
// Check that macro calls inside the macro trigger as usage
|
||||||
|
macro_rules! num_rec {
|
||||||
|
(one) => { 1 };
|
||||||
|
(two) => {
|
||||||
|
num_rec!(one) + num_rec!(one)
|
||||||
};
|
};
|
||||||
|
(three) => { //~ ERROR: 3rd rule of macro
|
||||||
|
num_rec!(one) + num_rec!(two)
|
||||||
|
};
|
||||||
|
(four) => { num_rec!(two) + num_rec!(two) };
|
||||||
}
|
}
|
||||||
create_macro!();
|
const _NUM_RECURSIVE: u8 = num_rec!(four);
|
||||||
|
|
||||||
#[allow(unused_macros)]
|
// No error if the macro is being exported
|
||||||
mod bar {
|
#[macro_export]
|
||||||
// Test that putting the #[deny] close to the macro's definition
|
macro_rules! num_exported {
|
||||||
// works.
|
(one) => { 1 };
|
||||||
|
(two) => { 2 };
|
||||||
#[deny(unused_macros)]
|
(three) => { 3 };
|
||||||
macro_rules! unused { //~ ERROR: unused macro definition
|
(four) => { 4 };
|
||||||
() => {};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
const _NUM_EXPORTED: u8 = num_exported!(one) + num_exported!(three);
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -1,32 +1,26 @@
|
||||||
error: unused macro definition: `unused`
|
error: 4th rule of macro `num` is never used
|
||||||
--> $DIR/unused-macro-rules.rs:4:14
|
--> $DIR/unused-macro-rules.rs:10:5
|
||||||
|
|
|
|
||||||
LL | macro_rules! unused {
|
LL | (four) => { 4 };
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
|
|
|
|
||||||
note: the lint level is defined here
|
note: the lint level is defined here
|
||||||
--> $DIR/unused-macro-rules.rs:1:9
|
--> $DIR/unused-macro-rules.rs:1:9
|
||||||
|
|
|
|
||||||
LL | #![deny(unused_macros)]
|
LL | #![deny(unused_macro_rules)]
|
||||||
| ^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: unused macro definition: `m`
|
error: 2nd rule of macro `num` is never used
|
||||||
--> $DIR/unused-macro-rules.rs:11:22
|
--> $DIR/unused-macro-rules.rs:8:5
|
||||||
|
|
|
|
||||||
LL | macro_rules! m {
|
LL | (two) => { 2 };
|
||||||
| ^
|
| ^^^^^
|
||||||
|
|
||||||
error: unused macro definition: `unused`
|
error: 3rd rule of macro `num_rec` is never used
|
||||||
--> $DIR/unused-macro-rules.rs:24:18
|
--> $DIR/unused-macro-rules.rs:30:5
|
||||||
|
|
|
|
||||||
LL | macro_rules! unused {
|
LL | (three) => {
|
||||||
| ^^^^^^
|
| ^^^^^^^
|
||||||
|
|
|
||||||
note: the lint level is defined here
|
|
||||||
--> $DIR/unused-macro-rules.rs:23:12
|
|
||||||
|
|
|
||||||
LL | #[deny(unused_macros)]
|
|
||||||
| ^^^^^^^^^^^^^
|
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
error: aborting due to 3 previous errors
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#![feature(decl_macro)]
|
#![feature(decl_macro)]
|
||||||
#![deny(unused_macros)]
|
#![deny(unused_macros)]
|
||||||
|
// To make sure we are not hitting this
|
||||||
|
#![deny(unused_macro_rules)]
|
||||||
|
|
||||||
// Most simple case
|
// Most simple case
|
||||||
macro unused { //~ ERROR: unused macro definition
|
macro unused { //~ ERROR: unused macro definition
|
|
@ -1,29 +1,29 @@
|
||||||
error: unused macro definition: `unused`
|
error: unused macro definition: `unused`
|
||||||
--> $DIR/unused-macro.rs:5:7
|
--> $DIR/unused-macros-decl.rs:7:7
|
||||||
|
|
|
|
||||||
LL | macro unused {
|
LL | macro unused {
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
|
|
|
|
||||||
note: the lint level is defined here
|
note: the lint level is defined here
|
||||||
--> $DIR/unused-macro.rs:2:9
|
--> $DIR/unused-macros-decl.rs:2:9
|
||||||
|
|
|
|
||||||
LL | #![deny(unused_macros)]
|
LL | #![deny(unused_macros)]
|
||||||
| ^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: unused macro definition: `unused`
|
error: unused macro definition: `unused`
|
||||||
--> $DIR/unused-macro.rs:15:11
|
--> $DIR/unused-macros-decl.rs:17:11
|
||||||
|
|
|
|
||||||
LL | macro unused {
|
LL | macro unused {
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
|
|
|
|
||||||
note: the lint level is defined here
|
note: the lint level is defined here
|
||||||
--> $DIR/unused-macro.rs:14:12
|
--> $DIR/unused-macros-decl.rs:16:12
|
||||||
|
|
|
|
||||||
LL | #[deny(unused_macros)]
|
LL | #[deny(unused_macros)]
|
||||||
| ^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: unused macro definition: `unused`
|
error: unused macro definition: `unused`
|
||||||
--> $DIR/unused-macro.rs:21:22
|
--> $DIR/unused-macros-decl.rs:23:22
|
||||||
|
|
|
|
||||||
LL | pub(crate) macro unused {
|
LL | pub(crate) macro unused {
|
||||||
| ^^^^^^
|
| ^^^^^^
|
31
src/test/ui/lint/unused/unused-macros.rs
Normal file
31
src/test/ui/lint/unused/unused-macros.rs
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
#![deny(unused_macros)]
|
||||||
|
// To make sure we are not hitting this
|
||||||
|
#![deny(unused_macro_rules)]
|
||||||
|
|
||||||
|
// Most simple case
|
||||||
|
macro_rules! unused { //~ ERROR: unused macro definition
|
||||||
|
() => {};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test macros created by macros
|
||||||
|
macro_rules! create_macro {
|
||||||
|
() => {
|
||||||
|
macro_rules! m { //~ ERROR: unused macro definition
|
||||||
|
() => {};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
create_macro!();
|
||||||
|
|
||||||
|
#[allow(unused_macros)]
|
||||||
|
mod bar {
|
||||||
|
// Test that putting the #[deny] close to the macro's definition
|
||||||
|
// works.
|
||||||
|
|
||||||
|
#[deny(unused_macros)]
|
||||||
|
macro_rules! unused { //~ ERROR: unused macro definition
|
||||||
|
() => {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
32
src/test/ui/lint/unused/unused-macros.stderr
Normal file
32
src/test/ui/lint/unused/unused-macros.stderr
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
error: unused macro definition: `unused`
|
||||||
|
--> $DIR/unused-macros.rs:6:14
|
||||||
|
|
|
||||||
|
LL | macro_rules! unused {
|
||||||
|
| ^^^^^^
|
||||||
|
|
|
||||||
|
note: the lint level is defined here
|
||||||
|
--> $DIR/unused-macros.rs:1:9
|
||||||
|
|
|
||||||
|
LL | #![deny(unused_macros)]
|
||||||
|
| ^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: unused macro definition: `m`
|
||||||
|
--> $DIR/unused-macros.rs:13:22
|
||||||
|
|
|
||||||
|
LL | macro_rules! m {
|
||||||
|
| ^
|
||||||
|
|
||||||
|
error: unused macro definition: `unused`
|
||||||
|
--> $DIR/unused-macros.rs:26:18
|
||||||
|
|
|
||||||
|
LL | macro_rules! unused {
|
||||||
|
| ^^^^^^
|
||||||
|
|
|
||||||
|
note: the lint level is defined here
|
||||||
|
--> $DIR/unused-macros.rs:25:12
|
||||||
|
|
|
||||||
|
LL | #[deny(unused_macros)]
|
||||||
|
| ^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to 3 previous errors
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue