Skip to content

Commit ef7a3c6

Browse files
committed
Add tests for assertion_on_constants macro check
1 parent 07d2a7c commit ef7a3c6

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

tests/ui/assertions_on_constants.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
macro_rules! assert_const {
2+
($len:expr) => {
3+
assert!($len > 0);
4+
}
5+
}
6+
17
fn main() {
28
assert!(true);
39
assert!(false);
@@ -9,4 +15,7 @@ fn main() {
915

1016
const C: bool = false;
1117
assert!(C);
18+
19+
assert_const!(3);
20+
assert_const!(-1);
1221
}

tests/ui/assertions_on_constants.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: assert!(true) will be optimized out by the compiler
2-
--> $DIR/assertions_on_constants.rs:2:5
2+
--> $DIR/assertions_on_constants.rs:8:5
33
|
44
LL | assert!(true);
55
| ^^^^^^^^^^^^^^
@@ -8,39 +8,39 @@ LL | assert!(true);
88
= help: remove it
99

1010
error: assert!(false) should probably be replaced
11-
--> $DIR/assertions_on_constants.rs:3:5
11+
--> $DIR/assertions_on_constants.rs:9:5
1212
|
1313
LL | assert!(false);
1414
| ^^^^^^^^^^^^^^^
1515
|
1616
= help: use panic!() or unreachable!()
1717

1818
error: assert!(true) will be optimized out by the compiler
19-
--> $DIR/assertions_on_constants.rs:4:5
19+
--> $DIR/assertions_on_constants.rs:10:5
2020
|
2121
LL | assert!(true, "true message");
2222
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2323
|
2424
= help: remove it
2525

2626
error: assert!(false) should probably be replaced
27-
--> $DIR/assertions_on_constants.rs:5:5
27+
--> $DIR/assertions_on_constants.rs:11:5
2828
|
2929
LL | assert!(false, "false message");
3030
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3131
|
3232
= help: use panic!() or unreachable!()
3333

3434
error: assert!(const: true) will be optimized out by the compiler
35-
--> $DIR/assertions_on_constants.rs:8:5
35+
--> $DIR/assertions_on_constants.rs:14:5
3636
|
3737
LL | assert!(B);
3838
| ^^^^^^^^^^^
3939
|
4040
= help: remove it
4141

4242
error: assert!(const: false) should probably be replaced
43-
--> $DIR/assertions_on_constants.rs:11:5
43+
--> $DIR/assertions_on_constants.rs:17:5
4444
|
4545
LL | assert!(C);
4646
| ^^^^^^^^^^^

0 commit comments

Comments
 (0)