Skip to content

Commit

Permalink
Test that the unused_macros lint works correctly if rules are malformed
Browse files Browse the repository at this point in the history
The unused_macro_rules lint had a bug where it would regard all rules of
a macro as unused if one rule were malformed. This bug doesn't exist
with the unused_macros lint. To ensure it doesn't appear in the future,
we add a test for it.
  • Loading branch information
est31 committed Jun 9, 2022
1 parent 777e136 commit 787e24c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/test/ui/lint/unused/unused-macros-malformed-rule.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#![deny(unused_macros)]

macro_rules! foo { //~ ERROR: unused macro definition
(v) => {};
() => 0; //~ ERROR: macro rhs must be delimited
}

macro_rules! bar {
(v) => {};
() => 0; //~ ERROR: macro rhs must be delimited
}

fn main() {
bar!(v);
}
26 changes: 26 additions & 0 deletions src/test/ui/lint/unused/unused-macros-malformed-rule.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
error: macro rhs must be delimited
--> $DIR/unused-macros-malformed-rule.rs:5:11
|
LL | () => 0;
| ^

error: macro rhs must be delimited
--> $DIR/unused-macros-malformed-rule.rs:10:11
|
LL | () => 0;
| ^

error: unused macro definition: `foo`
--> $DIR/unused-macros-malformed-rule.rs:3:14
|
LL | macro_rules! foo {
| ^^^
|
note: the lint level is defined here
--> $DIR/unused-macros-malformed-rule.rs:1:9
|
LL | #![deny(unused_macros)]
| ^^^^^^^^^^^^^

error: aborting due to 3 previous errors

0 comments on commit 787e24c

Please sign in to comment.