Skip to content

Commit 1de6a96

Browse files
committed
mir: Don't use ConstVal kinds that contain local NodeId's.
1 parent b38627d commit 1de6a96

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

src/librustc_mir/hair/cx/mod.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,16 @@ impl<'a,'tcx:'a> Cx<'a, 'tcx> {
8484

8585
pub fn try_const_eval_literal(&mut self, e: &hir::Expr) -> Option<Literal<'tcx>> {
8686
let hint = const_eval::EvalHint::ExprTypeChecked;
87-
const_eval::eval_const_expr_partial(self.tcx, e, hint, None)
88-
.ok()
89-
.map(|v| Literal::Value { value: v })
87+
const_eval::eval_const_expr_partial(self.tcx, e, hint, None).ok().and_then(|v| {
88+
match v {
89+
// All of these contain local IDs, unsuitable for storing in MIR.
90+
ConstVal::Struct(_) | ConstVal::Tuple(_) |
91+
ConstVal::Array(..) | ConstVal::Repeat(..) |
92+
ConstVal::Function(_) => None,
93+
94+
_ => Some(Literal::Value { value: v })
95+
}
96+
})
9097
}
9198

9299
pub fn num_variants(&mut self, adt_def: ty::AdtDef<'tcx>) -> usize {

src/librustc_trans/trans/mir/constant.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_const_eval::ConstInt::*;
1515
use rustc::mir::repr as mir;
1616
use trans::abi;
1717
use trans::common::{self, BlockAndBuilder, C_bool, C_bytes, C_floating_f64, C_integral,
18-
C_str_slice, C_nil, C_undef};
18+
C_str_slice, C_undef};
1919
use trans::consts;
2020
use trans::expr;
2121
use trans::inline;
@@ -85,16 +85,13 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
8585
ConstVal::Integral(InferSigned(v)) => C_integral(llty, v as u64, true),
8686
ConstVal::Str(ref v) => C_str_slice(ccx, v.clone()),
8787
ConstVal::ByteStr(ref v) => consts::addr_of(ccx, C_bytes(ccx, v), 1, "byte_str"),
88-
ConstVal::Struct(id) | ConstVal::Tuple(id) |
89-
ConstVal::Array(id, _) | ConstVal::Repeat(id, _) => {
90-
let expr = bcx.tcx().map.expect_expr(id);
91-
bcx.with_block(|bcx| {
92-
expr::trans(bcx, expr).datum.val
93-
})
94-
},
88+
ConstVal::Struct(_) | ConstVal::Tuple(_) |
89+
ConstVal::Array(..) | ConstVal::Repeat(..) |
90+
ConstVal::Function(_) => {
91+
unreachable!("MIR must not use {:?} (which refers to a local ID)", cv)
92+
}
9593
ConstVal::Char(c) => C_integral(Type::char(ccx), c as u64, false),
9694
ConstVal::Dummy => unreachable!(),
97-
ConstVal::Function(_) => C_nil(ccx)
9895
}
9996
}
10097

0 commit comments

Comments
 (0)