diff options
| author | Eduard Burtescu <edy.burt@gmail.com> | 2016-03-08 14:15:23 +0200 |
|---|---|---|
| committer | Eduard Burtescu <edy.burt@gmail.com> | 2016-03-17 21:51:53 +0200 |
| commit | 1de6a9682f16a893cd5651db28e26a1cd92fd459 (patch) | |
| tree | bbbc103ad769bdf1bcaea0383a5eab240430a994 /src | |
| parent | b38627dafb534fc6773d3f4061d639a2c7b86f9f (diff) | |
| download | rust-1de6a9682f16a893cd5651db28e26a1cd92fd459.tar.gz rust-1de6a9682f16a893cd5651db28e26a1cd92fd459.zip | |
mir: Don't use ConstVal kinds that contain local NodeId's.
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_mir/hair/cx/mod.rs | 13 | ||||
| -rw-r--r-- | src/librustc_trans/trans/mir/constant.rs | 15 |
2 files changed, 16 insertions, 12 deletions
diff --git a/src/librustc_mir/hair/cx/mod.rs b/src/librustc_mir/hair/cx/mod.rs index fd4cf7c0473..d29d895e11d 100644 --- a/src/librustc_mir/hair/cx/mod.rs +++ b/src/librustc_mir/hair/cx/mod.rs @@ -84,9 +84,16 @@ impl<'a,'tcx:'a> Cx<'a, 'tcx> { pub fn try_const_eval_literal(&mut self, e: &hir::Expr) -> Option<Literal<'tcx>> { let hint = const_eval::EvalHint::ExprTypeChecked; - const_eval::eval_const_expr_partial(self.tcx, e, hint, None) - .ok() - .map(|v| Literal::Value { value: v }) + const_eval::eval_const_expr_partial(self.tcx, e, hint, None).ok().and_then(|v| { + match v { + // All of these contain local IDs, unsuitable for storing in MIR. + ConstVal::Struct(_) | ConstVal::Tuple(_) | + ConstVal::Array(..) | ConstVal::Repeat(..) | + ConstVal::Function(_) => None, + + _ => Some(Literal::Value { value: v }) + } + }) } pub fn num_variants(&mut self, adt_def: ty::AdtDef<'tcx>) -> usize { diff --git a/src/librustc_trans/trans/mir/constant.rs b/src/librustc_trans/trans/mir/constant.rs index 21cd35ea045..ba737bae445 100644 --- a/src/librustc_trans/trans/mir/constant.rs +++ b/src/librustc_trans/trans/mir/constant.rs @@ -15,7 +15,7 @@ use rustc_const_eval::ConstInt::*; use rustc::mir::repr as mir; use trans::abi; use trans::common::{self, BlockAndBuilder, C_bool, C_bytes, C_floating_f64, C_integral, - C_str_slice, C_nil, C_undef}; + C_str_slice, C_undef}; use trans::consts; use trans::expr; use trans::inline; @@ -85,16 +85,13 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> { ConstVal::Integral(InferSigned(v)) => C_integral(llty, v as u64, true), ConstVal::Str(ref v) => C_str_slice(ccx, v.clone()), ConstVal::ByteStr(ref v) => consts::addr_of(ccx, C_bytes(ccx, v), 1, "byte_str"), - ConstVal::Struct(id) | ConstVal::Tuple(id) | - ConstVal::Array(id, _) | ConstVal::Repeat(id, _) => { - let expr = bcx.tcx().map.expect_expr(id); - bcx.with_block(|bcx| { - expr::trans(bcx, expr).datum.val - }) - }, + ConstVal::Struct(_) | ConstVal::Tuple(_) | + ConstVal::Array(..) | ConstVal::Repeat(..) | + ConstVal::Function(_) => { + unreachable!("MIR must not use {:?} (which refers to a local ID)", cv) + } ConstVal::Char(c) => C_integral(Type::char(ccx), c as u64, false), ConstVal::Dummy => unreachable!(), - ConstVal::Function(_) => C_nil(ccx) } } |
