Skip to content

Commit 08ea23b

Browse files
committed
test: add test for in-macro double_negations warning
1 parent 05c48a3 commit 08ea23b

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

tests/ui/lint/lint-double-negations-macro.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ macro_rules! neg {
44
-$e
55
};
66
}
7+
macro_rules! bad_macro {
8+
($e: expr) => {
9+
--$e //~ WARN use of a double negation
10+
};
11+
}
712

813
fn main() {
914
neg!(-1);
15+
bad_macro!(1);
1016
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
warning: use of a double negation
2+
--> $DIR/lint-double-negations-macro.rs:9:9
3+
|
4+
LL | --$e
5+
| ^^^^
6+
...
7+
LL | bad_macro!(1);
8+
| ------------- in this macro invocation
9+
|
10+
= note: the prefix `--` could be misinterpreted as a decrement operator which exists in other languages
11+
= note: use `-= 1` if you meant to decrement the value
12+
= note: `#[warn(double_negations)]` on by default
13+
= note: this warning originates in the macro `bad_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
14+
help: add parentheses for clarity
15+
|
16+
LL | -(-$e)
17+
| + +
18+
19+
warning: 1 warning emitted
20+

0 commit comments

Comments
 (0)