Skip to content

Commit

Permalink
Improve divide-by-zero error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanzab committed Apr 24, 2013
1 parent f39152e commit ab8068c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/librustc/middle/const_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,9 @@ pub fn eval_const_expr_partial(tcx: middle::ty::ctxt, e: @expr)
add => Ok(const_int(a + b)),
subtract => Ok(const_int(a - b)),
mul => Ok(const_int(a * b)),
quot if b == 0 => Err(~"quotient zero"),
quot if b == 0 => Err(~"attempted quotient with a divisor of zero"),
quot => Ok(const_int(a / b)),
rem if b == 0 => Err(~"remainder zero"),
rem if b == 0 => Err(~"attempted remainder with a divisor of zero"),
rem => Ok(const_int(a % b)),
and | bitand => Ok(const_int(a & b)),
or | bitor => Ok(const_int(a | b)),
Expand All @@ -321,9 +321,9 @@ pub fn eval_const_expr_partial(tcx: middle::ty::ctxt, e: @expr)
add => Ok(const_uint(a + b)),
subtract => Ok(const_uint(a - b)),
mul => Ok(const_uint(a * b)),
quot if b == 0 => Err(~"quotient zero"),
quot if b == 0 => Err(~"attempted quotient with a divisor of zero"),
quot => Ok(const_uint(a / b)),
rem if b == 0 => Err(~"remainder zero"),
rem if b == 0 => Err(~"attempted remainder with a divisor of zero"),
rem => Ok(const_uint(a % b)),
and | bitand => Ok(const_uint(a & b)),
or | bitor => Ok(const_uint(a | b)),
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -785,9 +785,9 @@ pub fn cast_shift_rhs(op: ast::binop,
pub fn fail_if_zero(cx: block, span: span, quotrem: ast::binop,
rhs: ValueRef, rhs_t: ty::t) -> block {
let text = if quotrem == ast::quot {
@~"quotient zero"
@~"attempted quotient with a divisor of zero"
} else {
@~"remainder zero"
@~"attempted remainder with a divisor of zero"
};
let is_zero = match ty::get(rhs_t).sty {
ty::ty_int(t) => {
Expand Down
4 changes: 2 additions & 2 deletions src/test/compile-fail/eval-enum.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
enum test {
quot_zero = 1/0, //~ERROR expected constant: quotient zero
rem_zero = 1%0 //~ERROR expected constant: remainder zero
quot_zero = 1/0, //~ERROR expected constant: attempted quotient with a divisor of zero
rem_zero = 1%0 //~ERROR expected constant: attempted remainder with a divisor of zero
}

fn main() {}
2 changes: 1 addition & 1 deletion src/test/run-fail/divide-by-zero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// error-pattern:quotient zero
// error-pattern:attempted quotient with a divisor of zero
fn main() {
let y = 0;
let z = 1 / y;
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-fail/mod-zero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// error-pattern:remainder zero
// error-pattern:attempted remainder with a divisor of zero
fn main() {
let y = 0;
let z = 1 % y;
Expand Down

5 comments on commit ab8068c

@bors
Copy link
Contributor

@bors bors commented on ab8068c Apr 24, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from brson
at brendanzab@ab8068c

@bors
Copy link
Contributor

@bors bors commented on ab8068c Apr 24, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging bjz/rust/numeric-traits = ab8068c into auto

@bors
Copy link
Contributor

@bors bors commented on ab8068c Apr 24, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bjz/rust/numeric-traits = ab8068c merged ok, testing candidate = c8ac057

@bors
Copy link
Contributor

@bors bors commented on ab8068c Apr 24, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on ab8068c Apr 24, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding incoming to auto = c8ac057

Please sign in to comment.