Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent expr_cast hides prior error. #5889

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 24 additions & 25 deletions src/librustc/middle/const_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,32 +371,31 @@ pub fn eval_const_expr_partial(tcx: middle::ty::ctxt, e: @expr)
expr_cast(base, _) => {
let ety = ty::expr_ty(tcx, e);
let base = eval_const_expr_partial(tcx, base);
match ty::get(ety).sty {
ty::ty_float(_) => {
match base {
Ok(const_uint(u)) => Ok(const_float(u as f64)),
Ok(const_int(i)) => Ok(const_float(i as f64)),
Ok(const_float(_)) => base,
_ => Err(~"Can't cast float to str")
}
}
ty::ty_uint(_) => {
match base {
Ok(const_uint(_)) => base,
Ok(const_int(i)) => Ok(const_uint(i as u64)),
Ok(const_float(f)) => Ok(const_uint(f as u64)),
_ => Err(~"Can't cast str to uint")
}
}
ty::ty_int(_) | ty::ty_bool => {
match base {
Ok(const_uint(u)) => Ok(const_int(u as i64)),
Ok(const_int(_)) => base,
Ok(const_float(f)) => Ok(const_int(f as i64)),
_ => Err(~"Can't cast str to int")
match /*bad*/copy base {
Err(_) => base,
Ok(val) => {
match ty::get(ety).sty {
ty::ty_float(_) => match val {
const_uint(u) => Ok(const_float(u as f64)),
const_int(i) => Ok(const_float(i as f64)),
const_float(_) => base,
_ => Err(~"Can't cast float to str"),
},
ty::ty_uint(_) => match val {
const_uint(_) => base,
const_int(i) => Ok(const_uint(i as u64)),
const_float(f) => Ok(const_uint(f as u64)),
_ => Err(~"Can't cast str to uint"),
},
ty::ty_int(_) | ty::ty_bool => match val {
const_uint(u) => Ok(const_int(u as i64)),
const_int(_) => base,
const_float(f) => Ok(const_int(f as i64)),
_ => Err(~"Can't cast str to int"),
},
_ => Err(~"Can't cast this type")
}
}
}
_ => Err(~"Can't cast this type")
}
}
expr_path(_) => {
Expand Down