Skip to content

Commit b8c5053

Browse files
committed
trans: use the same messages for both MIR and old arithmetic checks.
1 parent 1447fbf commit b8c5053

17 files changed

+38
-27
lines changed

src/librustc_trans/base.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -769,12 +769,12 @@ pub fn fail_if_zero_or_overflows<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
769769
rhs: ValueRef,
770770
rhs_t: Ty<'tcx>)
771771
-> Block<'blk, 'tcx> {
772-
let (zero_text, overflow_text) = if divrem.node == hir::BiDiv {
773-
("attempted to divide by zero",
774-
"attempted to divide with overflow")
772+
use rustc_const_math::{ConstMathErr, Op};
773+
774+
let (zero_err, overflow_err) = if divrem.node == hir::BiDiv {
775+
(ConstMathErr::DivisionByZero, ConstMathErr::Overflow(Op::Div))
775776
} else {
776-
("attempted remainder with a divisor of zero",
777-
"attempted remainder with overflow")
777+
(ConstMathErr::RemainderByZero, ConstMathErr::Overflow(Op::Rem))
778778
};
779779
let debug_loc = call_info.debug_loc();
780780

@@ -802,7 +802,7 @@ pub fn fail_if_zero_or_overflows<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
802802
}
803803
};
804804
let bcx = with_cond(cx, is_zero, |bcx| {
805-
controlflow::trans_fail(bcx, call_info, InternedString::new(zero_text))
805+
controlflow::trans_fail(bcx, call_info, InternedString::new(zero_err.description()))
806806
});
807807

808808
// To quote LLVM's documentation for the sdiv instruction:
@@ -828,7 +828,8 @@ pub fn fail_if_zero_or_overflows<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
828828
C_integral(llty, min, true),
829829
debug_loc);
830830
with_cond(bcx, is_min, |bcx| {
831-
controlflow::trans_fail(bcx, call_info, InternedString::new(overflow_text))
831+
controlflow::trans_fail(bcx, call_info,
832+
InternedString::new(overflow_err.description()))
832833
})
833834
})
834835
} else {

src/librustc_trans/expr.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2220,6 +2220,8 @@ impl OverflowOpViaIntrinsic {
22202220
rhs: ValueRef,
22212221
binop_debug_loc: DebugLoc)
22222222
-> (Block<'blk, 'tcx>, ValueRef) {
2223+
use rustc_const_math::{ConstMathErr, Op};
2224+
22232225
let llfn = self.to_intrinsic(bcx, lhs_t);
22242226

22252227
let val = Call(bcx, llfn, &[lhs, rhs], binop_debug_loc);
@@ -2233,10 +2235,16 @@ impl OverflowOpViaIntrinsic {
22332235
let expected = Call(bcx, expect, &[cond, C_bool(bcx.ccx(), false)],
22342236
binop_debug_loc);
22352237

2238+
let op = match *self {
2239+
OverflowOpViaIntrinsic::Add => Op::Add,
2240+
OverflowOpViaIntrinsic::Sub => Op::Sub,
2241+
OverflowOpViaIntrinsic::Mul => Op::Mul
2242+
};
2243+
22362244
let bcx =
22372245
base::with_cond(bcx, expected, |bcx|
22382246
controlflow::trans_fail(bcx, info,
2239-
InternedString::new("arithmetic operation overflowed")));
2247+
InternedString::new(ConstMathErr::Overflow(op).description())));
22402248

22412249
(bcx, result)
22422250
}
@@ -2252,6 +2260,8 @@ impl OverflowOpViaInputCheck {
22522260
binop_debug_loc: DebugLoc)
22532261
-> (Block<'blk, 'tcx>, ValueRef)
22542262
{
2263+
use rustc_const_math::{ConstMathErr, Op};
2264+
22552265
let lhs_llty = val_ty(lhs);
22562266
let rhs_llty = val_ty(rhs);
22572267

@@ -2266,16 +2276,16 @@ impl OverflowOpViaInputCheck {
22662276

22672277
let outer_bits = And(bcx, rhs, invert_mask, binop_debug_loc);
22682278
let cond = build_nonzero_check(bcx, outer_bits, binop_debug_loc);
2269-
let result = match *self {
2279+
let (result, op) = match *self {
22702280
OverflowOpViaInputCheck::Shl =>
2271-
build_unchecked_lshift(bcx, lhs, rhs, binop_debug_loc),
2281+
(build_unchecked_lshift(bcx, lhs, rhs, binop_debug_loc), Op::Shl),
22722282
OverflowOpViaInputCheck::Shr =>
2273-
build_unchecked_rshift(bcx, lhs_t, lhs, rhs, binop_debug_loc),
2283+
(build_unchecked_rshift(bcx, lhs_t, lhs, rhs, binop_debug_loc), Op::Shr)
22742284
};
22752285
let bcx =
22762286
base::with_cond(bcx, cond, |bcx|
22772287
controlflow::trans_fail(bcx, info,
2278-
InternedString::new("shift operation overflowed")));
2288+
InternedString::new(ConstMathErr::Overflow(op).description())));
22792289

22802290
(bcx, result)
22812291
}

src/test/run-fail/mod-zero.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// ignore-pretty : (#23623) problems when ending with // comments
1212

13-
// error-pattern:attempted remainder with a divisor of zero
13+
// error-pattern:attempted to calculate the remainder with a divisor of zero
1414

1515
fn main() {
1616
let y = 0;

src/test/run-fail/overflowing-add.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// ignore-pretty : (#23623) problems when ending with // comments
1212

13-
// error-pattern:thread 'main' panicked at 'arithmetic operation overflowed'
13+
// error-pattern:thread 'main' panicked at 'attempted to add with overflow'
1414
// compile-flags: -C debug-assertions
1515

1616

src/test/run-fail/overflowing-lsh-1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// ignore-pretty : (#23623) problems when ending with // comments
1212

13-
// error-pattern:thread 'main' panicked at 'shift operation overflowed'
13+
// error-pattern:thread 'main' panicked at 'attempted to shift left with overflow'
1414
// compile-flags: -C debug-assertions
1515

1616
#![warn(exceeding_bitshifts)]

src/test/run-fail/overflowing-lsh-2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// ignore-pretty : (#23623) problems when ending with // comments
1212

13-
// error-pattern:thread 'main' panicked at 'shift operation overflowed'
13+
// error-pattern:thread 'main' panicked at 'attempted to shift left with overflow'
1414
// compile-flags: -C debug-assertions
1515

1616
#![warn(exceeding_bitshifts)]

src/test/run-fail/overflowing-lsh-3.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// ignore-pretty : (#23623) problems when ending with // comments
1212

13-
// error-pattern:thread 'main' panicked at 'shift operation overflowed'
13+
// error-pattern:thread 'main' panicked at 'attempted to shift left with overflow'
1414
// compile-flags: -C debug-assertions
1515

1616
#![warn(exceeding_bitshifts)]

src/test/run-fail/overflowing-lsh-4.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// ignore-pretty : (#23623) problems when ending with // comments
1212

13-
// error-pattern:thread 'main' panicked at 'shift operation overflowed'
13+
// error-pattern:thread 'main' panicked at 'attempted to shift left with overflow'
1414
// compile-flags: -C debug-assertions
1515

1616
// This function is checking that our automatic truncation does not

src/test/run-fail/overflowing-mul.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// ignore-pretty : (#23623) problems when ending with // comments
1212

13-
// error-pattern:thread 'main' panicked at 'arithmetic operation overflowed'
13+
// error-pattern:thread 'main' panicked at 'attempted to multiply with overflow'
1414
// compile-flags: -C debug-assertions
1515

1616
fn main() {

src/test/run-fail/overflowing-pow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// error-pattern:thread 'main' panicked at 'arithmetic operation overflowed'
11+
// error-pattern:thread 'main' panicked at 'attempted to multiply with overflow'
1212
// compile-flags: -C debug-assertions
1313

1414
fn main() {

src/test/run-fail/overflowing-rsh-1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// ignore-pretty : (#23623) problems when ending with // comments
1212

13-
// error-pattern:thread 'main' panicked at 'shift operation overflowed'
13+
// error-pattern:thread 'main' panicked at 'attempted to shift right with overflow'
1414
// compile-flags: -C debug-assertions
1515

1616
#![warn(exceeding_bitshifts)]

src/test/run-fail/overflowing-rsh-2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// ignore-pretty : (#23623) problems when ending with // comments
1212

13-
// error-pattern:thread 'main' panicked at 'shift operation overflowed'
13+
// error-pattern:thread 'main' panicked at 'attempted to shift right with overflow'
1414
// compile-flags: -C debug-assertions
1515

1616
#![warn(exceeding_bitshifts)]

src/test/run-fail/overflowing-rsh-3.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// ignore-pretty : (#23623) problems when ending with // comments
1212

13-
// error-pattern:thread 'main' panicked at 'shift operation overflowed'
13+
// error-pattern:thread 'main' panicked at 'attempted to shift right with overflow'
1414
// compile-flags: -C debug-assertions
1515

1616
#![warn(exceeding_bitshifts)]

src/test/run-fail/overflowing-rsh-4.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// ignore-pretty : (#23623) problems when ending with // comments
1212

13-
// error-pattern:thread 'main' panicked at 'shift operation overflowed'
13+
// error-pattern:thread 'main' panicked at 'attempted to shift right with overflow'
1414
// compile-flags: -C debug-assertions
1515

1616
// This function is checking that our (type-based) automatic

src/test/run-fail/overflowing-rsh-5.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// ignore-pretty : (#23623) problems when ending with // comments
1212

13-
// error-pattern:thread 'main' panicked at 'shift operation overflowed'
13+
// error-pattern:thread 'main' panicked at 'attempted to shift right with overflow'
1414
// compile-flags: -C debug-assertions
1515

1616
#![warn(exceeding_bitshifts)]

src/test/run-fail/overflowing-rsh-6.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// ignore-pretty : (#23623) problems when ending with // comments
1212

13-
// error-pattern:thread 'main' panicked at 'shift operation overflowed'
13+
// error-pattern:thread 'main' panicked at 'attempted to shift right with overflow'
1414
// compile-flags: -C debug-assertions
1515

1616
#![warn(exceeding_bitshifts)]

src/test/run-fail/overflowing-sub.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// ignore-pretty : (#23623) problems when ending with // comments
1212

13-
// error-pattern:thread 'main' panicked at 'arithmetic operation overflowed'
13+
// error-pattern:thread 'main' panicked at 'attempted to subtract with overflow'
1414
// compile-flags: -C debug-assertions
1515

1616
fn main() {

0 commit comments

Comments
 (0)