diff options
| author | bors <bors@rust-lang.org> | 2013-04-16 12:48:56 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-04-16 12:48:56 -0700 |
| commit | 07e087bf310e7e7911bf05efa36a2cdb57855a4e (patch) | |
| tree | fad53032b663f39ae7f9f402e03ba2c5e8e2508c | |
| parent | 7cacd87efd34f8b8c3c0db5e5b2192ddd32a6ec5 (diff) | |
| parent | 9b55d86e74112361c560e49ca28a8fc71964adb9 (diff) | |
| download | rust-07e087bf310e7e7911bf05efa36a2cdb57855a4e.tar.gz rust-07e087bf310e7e7911bf05efa36a2cdb57855a4e.zip | |
auto merge of #5890 : youknowone/rust/const-eval, r=catamorphism
This will help not to meet confusing errors. In issue #5873, the error was "expected constant expr for vector length: Can't cast str to int". It was originally "expected constant expr for vector length: Non-constant path in constant expr" (though still invalid error). This patch make the original error to be printed.
| -rw-r--r-- | src/librustc/middle/const_eval.rs | 49 |
1 files changed, 24 insertions, 25 deletions
diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index d6434e469b2..63122a82eaf 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -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(_) => { |
