Improve divide-by-zero error messages

This commit is contained in:
Brendan Zabarauskas 2013-04-24 13:01:38 +10:00
parent f39152e07b
commit ab8068c9f2
5 changed files with 10 additions and 10 deletions

View File

@ -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)),
@ -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)),

View File

@ -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) => {

View File

@ -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() {}

View File

@ -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;

View File

@ -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;