Skip to content

Commit ab8068c

Browse files
committed
Improve divide-by-zero error messages
1 parent f39152e commit ab8068c

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

src/librustc/middle/const_eval.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,9 @@ pub fn eval_const_expr_partial(tcx: middle::ty::ctxt, e: @expr)
299299
add => Ok(const_int(a + b)),
300300
subtract => Ok(const_int(a - b)),
301301
mul => Ok(const_int(a * b)),
302-
quot if b == 0 => Err(~"quotient zero"),
302+
quot if b == 0 => Err(~"attempted quotient with a divisor of zero"),
303303
quot => Ok(const_int(a / b)),
304-
rem if b == 0 => Err(~"remainder zero"),
304+
rem if b == 0 => Err(~"attempted remainder with a divisor of zero"),
305305
rem => Ok(const_int(a % b)),
306306
and | bitand => Ok(const_int(a & b)),
307307
or | bitor => Ok(const_int(a | b)),
@@ -321,9 +321,9 @@ pub fn eval_const_expr_partial(tcx: middle::ty::ctxt, e: @expr)
321321
add => Ok(const_uint(a + b)),
322322
subtract => Ok(const_uint(a - b)),
323323
mul => Ok(const_uint(a * b)),
324-
quot if b == 0 => Err(~"quotient zero"),
324+
quot if b == 0 => Err(~"attempted quotient with a divisor of zero"),
325325
quot => Ok(const_uint(a / b)),
326-
rem if b == 0 => Err(~"remainder zero"),
326+
rem if b == 0 => Err(~"attempted remainder with a divisor of zero"),
327327
rem => Ok(const_uint(a % b)),
328328
and | bitand => Ok(const_uint(a & b)),
329329
or | bitor => Ok(const_uint(a | b)),

src/librustc/middle/trans/base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -785,9 +785,9 @@ pub fn cast_shift_rhs(op: ast::binop,
785785
pub fn fail_if_zero(cx: block, span: span, quotrem: ast::binop,
786786
rhs: ValueRef, rhs_t: ty::t) -> block {
787787
let text = if quotrem == ast::quot {
788-
@~"quotient zero"
788+
@~"attempted quotient with a divisor of zero"
789789
} else {
790-
@~"remainder zero"
790+
@~"attempted remainder with a divisor of zero"
791791
};
792792
let is_zero = match ty::get(rhs_t).sty {
793793
ty::ty_int(t) => {

src/test/compile-fail/eval-enum.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
enum test {
2-
quot_zero = 1/0, //~ERROR expected constant: quotient zero
3-
rem_zero = 1%0 //~ERROR expected constant: remainder zero
2+
quot_zero = 1/0, //~ERROR expected constant: attempted quotient with a divisor of zero
3+
rem_zero = 1%0 //~ERROR expected constant: attempted remainder with a divisor of zero
44
}
55

66
fn main() {}

src/test/run-fail/divide-by-zero.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:quotient zero
11+
// error-pattern:attempted quotient with a divisor of zero
1212
fn main() {
1313
let y = 0;
1414
let z = 1 / y;

src/test/run-fail/mod-zero.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:remainder zero
11+
// error-pattern:attempted remainder with a divisor of zero
1212
fn main() {
1313
let y = 0;
1414
let z = 1 % y;

0 commit comments

Comments
 (0)