Skip to content

Fix const evaluation of cast expression from bool #16718

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

Merged
merged 1 commit into from
Aug 24, 2014
Merged
Show file tree
Hide file tree
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
11 changes: 7 additions & 4 deletions src/librustc/middle/const_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,26 +517,29 @@ pub fn eval_const_expr_partial<T: ty::ExprTyProvider>(tcx: &T, e: &Expr)
match ty::get(ety).sty {
ty::ty_float(_) => {
match val {
const_bool(b) => Ok(const_float(b as f64)),
const_uint(u) => Ok(const_float(u as f64)),
const_int(i) => Ok(const_float(i as f64)),
const_float(f) => Ok(const_float(f)),
_ => Err("can't cast float to str".to_string()),
_ => Err("can't cast this type to float".to_string()),
}
}
ty::ty_uint(_) => {
match val {
const_bool(b) => Ok(const_uint(b as u64)),
const_uint(u) => Ok(const_uint(u)),
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".to_string()),
_ => Err("can't cast this type to uint".to_string()),
}
}
ty::ty_int(_) | ty::ty_bool => {
ty::ty_int(_) => {
match val {
const_bool(b) => Ok(const_int(b as i64)),
const_uint(u) => Ok(const_int(u as i64)),
const_int(i) => Ok(const_int(i)),
const_float(f) => Ok(const_int(f as i64)),
_ => Err("can't cast str to int".to_string()),
_ => Err("can't cast this type to int".to_string()),
}
}
_ => Err("can't cast this type".to_string())
Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/cast-in-array-size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ fn main() {
let _a: [bool, ..1 as uint];
let _b: [int, ..SIZE as uint] = [1, ..SIZE as uint];
let _c: [bool, ..'\n' as uint] = [true, ..'\n' as uint];
let _d: [bool, ..true as uint] = [true, ..true as uint];
}