Skip to content

Commit 35c9e5f

Browse files
committed
Fix const_err with -(-0.0)
1 parent d0677b9 commit 35c9e5f

File tree

4 files changed

+13
-27
lines changed

4 files changed

+13
-27
lines changed

src/librustc_mir/transform/const_prop.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::cell::Cell;
66
use rustc::hir::def::DefKind;
77
use rustc::mir::{
88
AggregateKind, Constant, Location, Place, PlaceBase, Body, Operand, Rvalue,
9-
Local, NullOp, UnOp, StatementKind, Statement, LocalKind, Static, StaticKind,
9+
Local, NullOp, StatementKind, Statement, LocalKind, Static, StaticKind,
1010
TerminatorKind, Terminator, ClearCrossCrate, SourceInfo, BinOp, ProjectionElem,
1111
SourceScope, SourceScopeLocalData, LocalDecl,
1212
};
@@ -407,18 +407,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
407407
let arg = self.eval_operand(arg, source_info)?;
408408
let val = self.use_ecx(source_info, |this| {
409409
let prim = this.ecx.read_immediate(arg)?;
410-
match op {
411-
UnOp::Neg => {
412-
// Need to do overflow check here: For actual CTFE, MIR
413-
// generation emits code that does this before calling the op.
414-
if prim.to_bits()? == (1 << (prim.layout.size.bits() - 1)) {
415-
throw_panic!(OverflowNeg)
416-
}
417-
}
418-
UnOp::Not => {
419-
// Cannot overflow
420-
}
421-
}
422410
// Now run the actual operation.
423411
this.ecx.unary_op(op, prim)
424412
})?;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ fn black_box<T>(_: T) {
1313

1414
fn main() {
1515
let a = -std::i8::MIN;
16-
//~^ ERROR const_err
1716
let b = 200u8 + 200u8 + 200u8;
1817
//~^ ERROR const_err
1918
let c = 200u8 * 4;

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

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: this expression will panic at runtime
2-
--> $DIR/const-err2.rs:15:13
2+
--> $DIR/const-err2.rs:16:13
33
|
4-
LL | let a = -std::i8::MIN;
5-
| ^^^^^^^^^^^^^ attempt to negate with overflow
4+
LL | let b = 200u8 + 200u8 + 200u8;
5+
| ^^^^^^^^^^^^^ attempt to add with overflow
66
|
77
note: lint level defined here
88
--> $DIR/const-err2.rs:8:9
@@ -11,28 +11,22 @@ LL | #![deny(const_err)]
1111
| ^^^^^^^^^
1212

1313
error: this expression will panic at runtime
14-
--> $DIR/const-err2.rs:17:13
15-
|
16-
LL | let b = 200u8 + 200u8 + 200u8;
17-
| ^^^^^^^^^^^^^ attempt to add with overflow
18-
19-
error: this expression will panic at runtime
20-
--> $DIR/const-err2.rs:19:13
14+
--> $DIR/const-err2.rs:18:13
2115
|
2216
LL | let c = 200u8 * 4;
2317
| ^^^^^^^^^ attempt to multiply with overflow
2418

2519
error: this expression will panic at runtime
26-
--> $DIR/const-err2.rs:21:13
20+
--> $DIR/const-err2.rs:20:13
2721
|
2822
LL | let d = 42u8 - (42u8 + 1);
2923
| ^^^^^^^^^^^^^^^^^ attempt to subtract with overflow
3024

3125
error: index out of bounds: the len is 1 but the index is 1
32-
--> $DIR/const-err2.rs:23:14
26+
--> $DIR/const-err2.rs:22:14
3327
|
3428
LL | let _e = [5u8][1];
3529
| ^^^^^^^^
3630

37-
error: aborting due to 5 previous errors
31+
error: aborting due to 4 previous errors
3832

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// run-pass
2+
3+
fn main() {
4+
let _ = -(-0.0);
5+
}

0 commit comments

Comments
 (0)