Skip to content

Commit 64c523a

Browse files
committed
---
yaml --- r: 54775 b: refs/heads/snap-stage3 c: c2f5a87 h: refs/heads/master i: 54773: 4e006b0 54771: cfb22af 54767: 87b2e74 v: v3
1 parent b23213e commit 64c523a

File tree

2 files changed

+25
-26
lines changed

2 files changed

+25
-26
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 5f13e9ccc2e3328d4cd8ca49f84e6840dd998346
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: c6f7b595f0bb3d8388a6bb89afc457a4702ec374
4+
refs/heads/snap-stage3: c2f5a87cdd79e5531b751749827d2e8a3d269c9e
55
refs/heads/try: 8eb2bab100b42f0ba751552d8eff00eb2134c55a
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/librustc/middle/const_eval.rs

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -371,32 +371,31 @@ pub fn eval_const_expr_partial(tcx: middle::ty::ctxt, e: @expr)
371371
expr_cast(base, _) => {
372372
let ety = ty::expr_ty(tcx, e);
373373
let base = eval_const_expr_partial(tcx, base);
374-
match ty::get(ety).sty {
375-
ty::ty_float(_) => {
376-
match base {
377-
Ok(const_uint(u)) => Ok(const_float(u as f64)),
378-
Ok(const_int(i)) => Ok(const_float(i as f64)),
379-
Ok(const_float(_)) => base,
380-
_ => Err(~"Can't cast float to str")
381-
}
382-
}
383-
ty::ty_uint(_) => {
384-
match base {
385-
Ok(const_uint(_)) => base,
386-
Ok(const_int(i)) => Ok(const_uint(i as u64)),
387-
Ok(const_float(f)) => Ok(const_uint(f as u64)),
388-
_ => Err(~"Can't cast str to uint")
389-
}
390-
}
391-
ty::ty_int(_) | ty::ty_bool => {
392-
match base {
393-
Ok(const_uint(u)) => Ok(const_int(u as i64)),
394-
Ok(const_int(_)) => base,
395-
Ok(const_float(f)) => Ok(const_int(f as i64)),
396-
_ => Err(~"Can't cast str to int")
374+
match /*bad*/copy base {
375+
Err(_) => base,
376+
Ok(val) => {
377+
match ty::get(ety).sty {
378+
ty::ty_float(_) => match val {
379+
const_uint(u) => Ok(const_float(u as f64)),
380+
const_int(i) => Ok(const_float(i as f64)),
381+
const_float(_) => base,
382+
_ => Err(~"Can't cast float to str"),
383+
},
384+
ty::ty_uint(_) => match val {
385+
const_uint(_) => base,
386+
const_int(i) => Ok(const_uint(i as u64)),
387+
const_float(f) => Ok(const_uint(f as u64)),
388+
_ => Err(~"Can't cast str to uint"),
389+
},
390+
ty::ty_int(_) | ty::ty_bool => match val {
391+
const_uint(u) => Ok(const_int(u as i64)),
392+
const_int(_) => base,
393+
const_float(f) => Ok(const_int(f as i64)),
394+
_ => Err(~"Can't cast str to int"),
395+
},
396+
_ => Err(~"Can't cast this type")
397+
}
397398
}
398-
}
399-
_ => Err(~"Can't cast this type")
400399
}
401400
}
402401
expr_path(_) => {

0 commit comments

Comments
 (0)