Skip to content

Commit bd48522

Browse files
committed
fix tests, and use variants to test debug and release builds together
1 parent ad4b3f3 commit bd48522

28 files changed

+872
-768
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// build-pass
22
// ignore-pass (emit codegen-time warnings and verify that they are indeed warnings and not errors)
33

4-
#![warn(const_err)]
4+
#![warn(const_err, panic)]
55

66
fn main() {
77
&{ [1, 2, 3][4] };
8-
//~^ WARN index out of bounds
8+
//~^ WARN operation will panic
99
//~| WARN reaching this expression at runtime will panic or abort
1010
//~| WARN erroneous constant used [const_err]
1111
}

src/test/ui/consts/array-literal-index-oob.stderr

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
warning: index out of bounds: the len is 3 but the index is 4
1+
warning: this operation will panic at runtime
22
--> $DIR/array-literal-index-oob.rs:7:8
33
|
44
LL | &{ [1, 2, 3][4] };
5-
| ^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^ index out of bounds: the len is 3 but the index is 4
66
|
77
note: the lint level is defined here
8-
--> $DIR/array-literal-index-oob.rs:4:9
8+
--> $DIR/array-literal-index-oob.rs:4:20
99
|
10-
LL | #![warn(const_err)]
11-
| ^^^^^^^^^
10+
LL | #![warn(const_err, panic)]
11+
| ^^^^^
1212

1313
warning: reaching this expression at runtime will panic or abort
1414
--> $DIR/array-literal-index-oob.rs:7:8
@@ -17,6 +17,12 @@ LL | &{ [1, 2, 3][4] };
1717
| ---^^^^^^^^^^^^--
1818
| |
1919
| indexing out of bounds: the len is 3 but the index is 4
20+
|
21+
note: the lint level is defined here
22+
--> $DIR/array-literal-index-oob.rs:4:9
23+
|
24+
LL | #![warn(const_err, panic)]
25+
| ^^^^^^^^^
2026

2127
warning: erroneous constant used
2228
--> $DIR/array-literal-index-oob.rs:7:5
Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,48 @@
1-
error: this expression will panic at runtime
2-
--> $DIR/const-err2.rs:18:13
1+
error: this arithmetic operation will overflow
2+
--> $DIR/const-err2.rs:19:13
33
|
44
LL | let a = -std::i8::MIN;
55
| ^^^^^^^^^^^^^ attempt to negate with overflow
66
|
7-
note: the lint level is defined here
8-
--> $DIR/const-err2.rs:11:9
9-
|
10-
LL | #![deny(const_err)]
11-
| ^^^^^^^^^
7+
= note: `#[deny(overflow)]` on by default
128

13-
error: this expression will panic at runtime
14-
--> $DIR/const-err2.rs:20:18
9+
error: this arithmetic operation will overflow
10+
--> $DIR/const-err2.rs:21:18
1511
|
1612
LL | let a_i128 = -std::i128::MIN;
1713
| ^^^^^^^^^^^^^^^ attempt to negate with overflow
1814

19-
error: this expression will panic at runtime
20-
--> $DIR/const-err2.rs:22:13
15+
error: this arithmetic operation will overflow
16+
--> $DIR/const-err2.rs:23:13
2117
|
2218
LL | let b = 200u8 + 200u8 + 200u8;
2319
| ^^^^^^^^^^^^^ attempt to add with overflow
2420

25-
error: this expression will panic at runtime
26-
--> $DIR/const-err2.rs:24:18
21+
error: this arithmetic operation will overflow
22+
--> $DIR/const-err2.rs:25:18
2723
|
2824
LL | let b_i128 = std::i128::MIN - std::i128::MAX;
2925
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to subtract with overflow
3026

31-
error: this expression will panic at runtime
32-
--> $DIR/const-err2.rs:26:13
27+
error: this arithmetic operation will overflow
28+
--> $DIR/const-err2.rs:27:13
3329
|
3430
LL | let c = 200u8 * 4;
3531
| ^^^^^^^^^ attempt to multiply with overflow
3632

37-
error: this expression will panic at runtime
38-
--> $DIR/const-err2.rs:28:13
33+
error: this arithmetic operation will overflow
34+
--> $DIR/const-err2.rs:29:13
3935
|
4036
LL | let d = 42u8 - (42u8 + 1);
4137
| ^^^^^^^^^^^^^^^^^ attempt to subtract with overflow
4238

43-
error: index out of bounds: the len is 1 but the index is 1
44-
--> $DIR/const-err2.rs:30:14
39+
error: this operation will panic at runtime
40+
--> $DIR/const-err2.rs:31:14
4541
|
4642
LL | let _e = [5u8][1];
47-
| ^^^^^^^^
43+
| ^^^^^^^^ index out of bounds: the len is 1 but the index is 1
44+
|
45+
= note: `#[deny(panic)]` on by default
4846

4947
error: aborting due to 7 previous errors
5048

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
error: this arithmetic operation will overflow
2+
--> $DIR/const-err2.rs:19:13
3+
|
4+
LL | let a = -std::i8::MIN;
5+
| ^^^^^^^^^^^^^ attempt to negate with overflow
6+
|
7+
= note: `#[deny(overflow)]` on by default
8+
9+
error: this arithmetic operation will overflow
10+
--> $DIR/const-err2.rs:21:18
11+
|
12+
LL | let a_i128 = -std::i128::MIN;
13+
| ^^^^^^^^^^^^^^^ attempt to negate with overflow
14+
15+
error: this arithmetic operation will overflow
16+
--> $DIR/const-err2.rs:23:13
17+
|
18+
LL | let b = 200u8 + 200u8 + 200u8;
19+
| ^^^^^^^^^^^^^ attempt to add with overflow
20+
21+
error: this arithmetic operation will overflow
22+
--> $DIR/const-err2.rs:25:18
23+
|
24+
LL | let b_i128 = std::i128::MIN - std::i128::MAX;
25+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to subtract with overflow
26+
27+
error: this arithmetic operation will overflow
28+
--> $DIR/const-err2.rs:27:13
29+
|
30+
LL | let c = 200u8 * 4;
31+
| ^^^^^^^^^ attempt to multiply with overflow
32+
33+
error: this arithmetic operation will overflow
34+
--> $DIR/const-err2.rs:29:13
35+
|
36+
LL | let d = 42u8 - (42u8 + 1);
37+
| ^^^^^^^^^^^^^^^^^ attempt to subtract with overflow
38+
39+
error: this operation will panic at runtime
40+
--> $DIR/const-err2.rs:31:14
41+
|
42+
LL | let _e = [5u8][1];
43+
| ^^^^^^^^ index out of bounds: the len is 1 but the index is 1
44+
|
45+
= note: `#[deny(panic)]` on by default
46+
47+
error: aborting due to 7 previous errors
48+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
error: this arithmetic operation will overflow
2+
--> $DIR/const-err2.rs:19:13
3+
|
4+
LL | let a = -std::i8::MIN;
5+
| ^^^^^^^^^^^^^ attempt to negate with overflow
6+
|
7+
= note: `#[deny(overflow)]` on by default
8+
9+
error: this arithmetic operation will overflow
10+
--> $DIR/const-err2.rs:21:18
11+
|
12+
LL | let a_i128 = -std::i128::MIN;
13+
| ^^^^^^^^^^^^^^^ attempt to negate with overflow
14+
15+
error: this arithmetic operation will overflow
16+
--> $DIR/const-err2.rs:23:13
17+
|
18+
LL | let b = 200u8 + 200u8 + 200u8;
19+
| ^^^^^^^^^^^^^ attempt to add with overflow
20+
21+
error: this arithmetic operation will overflow
22+
--> $DIR/const-err2.rs:25:18
23+
|
24+
LL | let b_i128 = std::i128::MIN - std::i128::MAX;
25+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to subtract with overflow
26+
27+
error: this arithmetic operation will overflow
28+
--> $DIR/const-err2.rs:27:13
29+
|
30+
LL | let c = 200u8 * 4;
31+
| ^^^^^^^^^ attempt to multiply with overflow
32+
33+
error: this arithmetic operation will overflow
34+
--> $DIR/const-err2.rs:29:13
35+
|
36+
LL | let d = 42u8 - (42u8 + 1);
37+
| ^^^^^^^^^^^^^^^^^ attempt to subtract with overflow
38+
39+
error: this operation will panic at runtime
40+
--> $DIR/const-err2.rs:31:14
41+
|
42+
LL | let _e = [5u8][1];
43+
| ^^^^^^^^ index out of bounds: the len is 1 but the index is 1
44+
|
45+
= note: `#[deny(panic)]` on by default
46+
47+
error: aborting due to 7 previous errors
48+

src/test/ui/consts/const-err2.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,34 @@
22
// optimized compilation and unoptimized compilation and thus would
33
// lead to different lints being emitted
44

5+
// revisions: debug opt opt_with_overflow_checks
6+
//[debug]compile-flags: -C opt-level=0
7+
//[opt]compile-flags: -O
8+
//[opt_with_overflow_checks]compile-flags: -C overflow-checks=on -O
9+
510
// build-fail
6-
// compile-flags: -O
711

812
#![feature(rustc_attrs)]
9-
#![allow(exceeding_bitshifts)]
10-
11-
#![deny(const_err)]
1213

1314
fn black_box<T>(_: T) {
1415
unimplemented!()
1516
}
1617

1718
fn main() {
1819
let a = -std::i8::MIN;
19-
//~^ ERROR const_err
20+
//~^ ERROR arithmetic operation will overflow
2021
let a_i128 = -std::i128::MIN;
21-
//~^ ERROR const_err
22+
//~^ ERROR arithmetic operation will overflow
2223
let b = 200u8 + 200u8 + 200u8;
23-
//~^ ERROR const_err
24+
//~^ ERROR arithmetic operation will overflow
2425
let b_i128 = std::i128::MIN - std::i128::MAX;
25-
//~^ ERROR const_err
26+
//~^ ERROR arithmetic operation will overflow
2627
let c = 200u8 * 4;
27-
//~^ ERROR const_err
28+
//~^ ERROR arithmetic operation will overflow
2829
let d = 42u8 - (42u8 + 1);
29-
//~^ ERROR const_err
30+
//~^ ERROR arithmetic operation will overflow
3031
let _e = [5u8][1];
31-
//~^ ERROR const_err
32+
//~^ ERROR operation will panic
3233
black_box(a);
3334
black_box(a_i128);
3435
black_box(b);

src/test/ui/consts/const-err3.rs

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/test/ui/consts/const-err3.stderr

Lines changed: 0 additions & 50 deletions
This file was deleted.

src/test/ui/consts/const-eval/index_out_of_bounds_propagated.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
fn main() {
44
let array = [std::env::args().len()];
5-
array[1]; //~ ERROR index out of bounds
5+
array[1]; //~ ERROR operation will panic
66
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error: index out of bounds: the len is 1 but the index is 1
1+
error: this operation will panic at runtime
22
--> $DIR/index_out_of_bounds_propagated.rs:5:5
33
|
44
LL | array[1];
5-
| ^^^^^^^^
5+
| ^^^^^^^^ index out of bounds: the len is 1 but the index is 1
66
|
7-
= note: `#[deny(const_err)]` on by default
7+
= note: `#[deny(panic)]` on by default
88

99
error: aborting due to previous error
1010

0 commit comments

Comments
 (0)