Skip to content

Commit cb2d987

Browse files
committed
Add tests for assertion_on_constants macro check
1 parent 446e2ec commit cb2d987

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

tests/ui/assertions_on_constants.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
macro_rules! assert_const {
2+
($len:expr) => {
3+
assert!($len > 0);
4+
debug_assert!($len < 0);
5+
};
6+
}
7+
18
fn main() {
29
assert!(true);
310
assert!(false);
@@ -9,4 +16,8 @@ fn main() {
916

1017
const C: bool = false;
1118
assert!(C);
19+
20+
debug_assert!(true);
21+
assert_const!(3);
22+
assert_const!(-1);
1223
}
Lines changed: 16 additions & 7 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:9:5
33
|
44
LL | assert!(true);
55
| ^^^^^^^^^^^^^^
@@ -8,44 +8,53 @@ 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:10: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:11: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:12: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:15: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:18:5
4444
|
4545
LL | assert!(C);
4646
| ^^^^^^^^^^^
4747
|
4848
= help: use panic!() or unreachable!()
4949

50-
error: aborting due to 6 previous errors
50+
error: assert!(true) will be optimized out by the compiler
51+
--> $DIR/assertions_on_constants.rs:20:5
52+
|
53+
LL | debug_assert!(true);
54+
| ^^^^^^^^^^^^^^^^^^^^
55+
|
56+
= help: remove it
57+
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
58+
59+
error: aborting due to 7 previous errors
5160

0 commit comments

Comments
 (0)