Skip to content

Commit 12bde10

Browse files
committed
---
yaml --- r: 41894 b: refs/heads/master c: 3ed39ce h: refs/heads/master v: v3
1 parent a34b17c commit 12bde10

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 93e969e356dc8908a7eeef675269149f81a10eed
2+
refs/heads/master: 3ed39ce26ff6dbe3d3a8f4196b9226550cc6a979
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 2f46b763da2c098913884f101b6d71d69af41b49
55
refs/heads/try: 3d5418789064fdb463e872a4e651af1c628a3650

trunk/src/librustc/middle/const_eval.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,9 @@ fn eval_const_expr_partial(tcx: middle::ty::ctxt, e: @expr)
295295
add => Ok(const_int(a + b)),
296296
subtract => Ok(const_int(a - b)),
297297
mul => Ok(const_int(a * b)),
298+
div if b == 0 => Err(~"divide by zero"),
298299
div => Ok(const_int(a / b)),
300+
rem if b == 0 => Err(~"modulo zero"),
299301
rem => Ok(const_int(a % b)),
300302
and | bitand => Ok(const_int(a & b)),
301303
or | bitor => Ok(const_int(a | b)),
@@ -315,7 +317,9 @@ fn eval_const_expr_partial(tcx: middle::ty::ctxt, e: @expr)
315317
add => Ok(const_uint(a + b)),
316318
subtract => Ok(const_uint(a - b)),
317319
mul => Ok(const_uint(a * b)),
320+
div if b == 0 => Err(~"divide by zero"),
318321
div => Ok(const_uint(a / b)),
322+
rem if b == 0 => Err(~"modulo zero"),
319323
rem => Ok(const_uint(a % b)),
320324
and | bitand => Ok(const_uint(a & b)),
321325
or | bitor => Ok(const_uint(a | b)),
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
enum test {
2+
div_zero = 1/0, //~ERROR expected constant: divide by zero
3+
rem_zero = 1%0 //~ERROR expected constant: modulo zero
4+
}
5+
6+
fn main() {}

0 commit comments

Comments
 (0)