Skip to content

Commit 0cd9c16

Browse files
committed
Fix condition and tests' flags
1 parent 8e9825a commit 0cd9c16

File tree

9 files changed

+75
-141
lines changed

9 files changed

+75
-141
lines changed

src/librustc_mir/transform/const_prop.rs

+1
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
413413
// We check overflow in debug mode already
414414
// so should only check in release mode.
415415
if !oflo_check
416+
&& prim.layout.ty.is_signed()
416417
&& prim.to_bits()? == (1 << (prim.layout.size.bits() - 1)) {
417418
throw_panic!(OverflowNeg)
418419
}

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

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#![feature(rustc_attrs)]
77
#![allow(exceeding_bitshifts)]
8+
// compile-flags: -C overflow-checks=on -O
9+
810
#![deny(const_err)]
911

1012
fn black_box<T>(_: T) {

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

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
1-
error: this expression will panic at runtime
2-
--> $DIR/const-err2.rs:15:13
1+
error: attempt to negate with overflow
2+
--> $DIR/const-err2.rs:17:13
33
|
44
LL | let a = -std::i8::MIN;
5-
| ^^^^^^^^^^^^^ attempt to negate with overflow
5+
| ^^^^^^^^^^^^^
66
|
77
note: lint level defined here
8-
--> $DIR/const-err2.rs:8:9
8+
--> $DIR/const-err2.rs:10:9
99
|
1010
LL | #![deny(const_err)]
1111
| ^^^^^^^^^
1212

13-
error: this expression will panic at runtime
14-
--> $DIR/const-err2.rs:17:13
13+
error: attempt to add with overflow
14+
--> $DIR/const-err2.rs:19:13
1515
|
1616
LL | let b = 200u8 + 200u8 + 200u8;
17-
| ^^^^^^^^^^^^^ attempt to add with overflow
17+
| ^^^^^^^^^^^^^
1818

19-
error: this expression will panic at runtime
20-
--> $DIR/const-err2.rs:19:13
19+
error: attempt to multiply with overflow
20+
--> $DIR/const-err2.rs:21:13
2121
|
2222
LL | let c = 200u8 * 4;
23-
| ^^^^^^^^^ attempt to multiply with overflow
23+
| ^^^^^^^^^
2424

25-
error: this expression will panic at runtime
26-
--> $DIR/const-err2.rs:21:13
25+
error: attempt to subtract with overflow
26+
--> $DIR/const-err2.rs:23:13
2727
|
2828
LL | let d = 42u8 - (42u8 + 1);
29-
| ^^^^^^^^^^^^^^^^^ attempt to subtract with overflow
29+
| ^^^^^^^^^^^^^^^^^
3030

3131
error: index out of bounds: the len is 1 but the index is 1
32-
--> $DIR/const-err2.rs:23:14
32+
--> $DIR/const-err2.rs:25:14
3333
|
3434
LL | let _e = [5u8][1];
3535
| ^^^^^^^^

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
// compile-flags: -O
1+
// compile-flags: -C overflow-checks=on -O
22

33
#![deny(const_err)]
44

55
fn main() {
66
println!("{}", 0u32 - 1);
7+
//~^ ERROR attempt to subtract with overflow
78
let _x = 0u32 - 1;
8-
//~^ ERROR this expression will panic at runtime [const_err]
9+
//~^ ERROR attempt to subtract with overflow
910
println!("{}", 1/(1-1));
1011
//~^ ERROR attempt to divide by zero [const_err]
1112
//~| ERROR reaching this expression at runtime will panic or abort [const_err]
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,68 @@
1-
error: this expression will panic at runtime
2-
--> $DIR/promoted_errors.rs:7:14
1+
error: attempt to subtract with overflow
2+
--> $DIR/promoted_errors.rs:6:20
33
|
4-
LL | let _x = 0u32 - 1;
5-
| ^^^^^^^^ attempt to subtract with overflow
4+
LL | println!("{}", 0u32 - 1);
5+
| ^^^^^^^^
66
|
77
note: lint level defined here
88
--> $DIR/promoted_errors.rs:3:9
99
|
1010
LL | #![deny(const_err)]
1111
| ^^^^^^^^^
1212

13+
error: attempt to subtract with overflow
14+
--> $DIR/promoted_errors.rs:8:14
15+
|
16+
LL | let _x = 0u32 - 1;
17+
| ^^^^^^^^
18+
1319
error: attempt to divide by zero
14-
--> $DIR/promoted_errors.rs:9:20
20+
--> $DIR/promoted_errors.rs:10:20
1521
|
1622
LL | println!("{}", 1/(1-1));
1723
| ^^^^^^^
1824

1925
error: reaching this expression at runtime will panic or abort
20-
--> $DIR/promoted_errors.rs:9:20
26+
--> $DIR/promoted_errors.rs:10:20
2127
|
2228
LL | println!("{}", 1/(1-1));
2329
| ^^^^^^^ attempt to divide by zero
2430

2531
error: attempt to divide by zero
26-
--> $DIR/promoted_errors.rs:12:14
32+
--> $DIR/promoted_errors.rs:13:14
2733
|
2834
LL | let _x = 1/(1-1);
2935
| ^^^^^^^
3036

3137
error: this expression will panic at runtime
32-
--> $DIR/promoted_errors.rs:12:14
38+
--> $DIR/promoted_errors.rs:13:14
3339
|
3440
LL | let _x = 1/(1-1);
3541
| ^^^^^^^ attempt to divide by zero
3642

3743
error: attempt to divide by zero
38-
--> $DIR/promoted_errors.rs:15:20
44+
--> $DIR/promoted_errors.rs:16:20
3945
|
4046
LL | println!("{}", 1/(false as u32));
4147
| ^^^^^^^^^^^^^^^^
4248

4349
error: reaching this expression at runtime will panic or abort
44-
--> $DIR/promoted_errors.rs:15:20
50+
--> $DIR/promoted_errors.rs:16:20
4551
|
4652
LL | println!("{}", 1/(false as u32));
4753
| ^^^^^^^^^^^^^^^^ attempt to divide by zero
4854

4955
error: attempt to divide by zero
50-
--> $DIR/promoted_errors.rs:18:14
56+
--> $DIR/promoted_errors.rs:19:14
5157
|
5258
LL | let _x = 1/(false as u32);
5359
| ^^^^^^^^^^^^^^^^
5460

5561
error: this expression will panic at runtime
56-
--> $DIR/promoted_errors.rs:18:14
62+
--> $DIR/promoted_errors.rs:19:14
5763
|
5864
LL | let _x = 1/(false as u32);
5965
| ^^^^^^^^^^^^^^^^ attempt to divide by zero
6066

61-
error: aborting due to 9 previous errors
67+
error: aborting due to 10 previous errors
6268

src/test/ui/consts/issue-64059.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
// compile-flags: -C overflow-checks=on -O
2+
// run-pass
3+
14
fn main() {
25
let _ = -(-0.0);
3-
//~^ ERROR: this expression will panic at runtime
46
}

src/test/ui/consts/issue-64059.stderr

-10
This file was deleted.

src/test/ui/issues/issue-8460-const.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// compile-flags: -C overflow-checks=on -O
2+
13
#![deny(const_err)]
24

35
use std::{isize, i8, i16, i32, i64};
@@ -6,19 +8,14 @@ use std::thread;
68
fn main() {
79
assert!(thread::spawn(move|| { isize::MIN / -1; }).join().is_err());
810
//~^ ERROR attempt to divide with overflow
9-
//~| ERROR this expression will panic at runtime
1011
assert!(thread::spawn(move|| { i8::MIN / -1; }).join().is_err());
1112
//~^ ERROR attempt to divide with overflow
12-
//~| ERROR this expression will panic at runtime
1313
assert!(thread::spawn(move|| { i16::MIN / -1; }).join().is_err());
1414
//~^ ERROR attempt to divide with overflow
15-
//~| ERROR this expression will panic at runtime
1615
assert!(thread::spawn(move|| { i32::MIN / -1; }).join().is_err());
1716
//~^ ERROR attempt to divide with overflow
18-
//~| ERROR this expression will panic at runtime
1917
assert!(thread::spawn(move|| { i64::MIN / -1; }).join().is_err());
2018
//~^ ERROR attempt to divide with overflow
21-
//~| ERROR this expression will panic at runtime
2219
assert!(thread::spawn(move|| { 1isize / 0; }).join().is_err());
2320
//~^ ERROR attempt to divide by zero
2421
//~| ERROR this expression will panic at runtime
@@ -36,19 +33,14 @@ fn main() {
3633
//~| ERROR this expression will panic at runtime
3734
assert!(thread::spawn(move|| { isize::MIN % -1; }).join().is_err());
3835
//~^ ERROR attempt to calculate the remainder with overflow
39-
//~| ERROR this expression will panic at runtime
4036
assert!(thread::spawn(move|| { i8::MIN % -1; }).join().is_err());
4137
//~^ ERROR attempt to calculate the remainder with overflow
42-
//~| ERROR this expression will panic at runtime
4338
assert!(thread::spawn(move|| { i16::MIN % -1; }).join().is_err());
4439
//~^ ERROR attempt to calculate the remainder with overflow
45-
//~| ERROR this expression will panic at runtime
4640
assert!(thread::spawn(move|| { i32::MIN % -1; }).join().is_err());
4741
//~^ ERROR attempt to calculate the remainder with overflow
48-
//~| ERROR this expression will panic at runtime
4942
assert!(thread::spawn(move|| { i64::MIN % -1; }).join().is_err());
5043
//~^ ERROR attempt to calculate the remainder with overflow
51-
//~| ERROR this expression will panic at runtime
5244
assert!(thread::spawn(move|| { 1isize % 0; }).join().is_err());
5345
//~^ ERROR attempt to calculate the remainder with a divisor of zero
5446
//~| ERROR this expression will panic at runtime

0 commit comments

Comments
 (0)