diff --git a/src/librustc_trans/trans/consts.rs b/src/librustc_trans/trans/consts.rs index 5284911340bd..406eaafb3f5e 100644 --- a/src/librustc_trans/trans/consts.rs +++ b/src/librustc_trans/trans/consts.rs @@ -108,12 +108,13 @@ pub fn const_lit(cx: &CrateContext, e: &hir::Expr, lit: &ast::Lit) } } -pub fn trans_constval<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, +pub fn trans_constval<'blk, 'tcx>(bcx: common::Block<'blk, 'tcx>, cv: &ConstVal, ty: Ty<'tcx>, param_substs: &'tcx Substs<'tcx>) -> ValueRef { + let ccx = bcx.ccx(); let llty = type_of::type_of(ccx, ty); match *cv { ConstVal::Float(v) => C_floating_f64(v, llty), @@ -123,21 +124,19 @@ pub fn trans_constval<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ConstVal::Str(ref v) => C_str_slice(ccx, v.clone()), ConstVal::ByteStr(ref v) => addr_of(ccx, C_bytes(ccx, v), 1, "byte_str"), ConstVal::Struct(id) | ConstVal::Tuple(id) => { - let expr = ccx.tcx().map.expect_expr(id); + let expr = bcx.tcx().map.expect_expr(id); match const_expr(ccx, expr, param_substs, None, TrueConst::Yes) { Ok((val, _)) => val, Err(e) => panic!("const eval failure: {}", e.description()), } }, + ConstVal::Array(id, _) | ConstVal::Repeat(id, _) => { + let expr = ccx.tcx().map.expect_expr(id); + expr::trans(bcx, expr).datum.val + }, ConstVal::Function(_) => { unimplemented!() }, - ConstVal::Array(..) => { - unimplemented!() - }, - ConstVal::Repeat(..) => { - unimplemented!() - }, } } diff --git a/src/librustc_trans/trans/mir/constant.rs b/src/librustc_trans/trans/mir/constant.rs index cbcc1c3c47db..38fab1dbf07f 100644 --- a/src/librustc_trans/trans/mir/constant.rs +++ b/src/librustc_trans/trans/mir/constant.rs @@ -26,11 +26,11 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> { -> OperandRef<'tcx> { let ccx = bcx.ccx(); - let val = consts::trans_constval(ccx, cv, ty, bcx.fcx.param_substs); + let val = consts::trans_constval(bcx, cv, ty, bcx.fcx.param_substs); let val = if common::type_is_immediate(ccx, ty) { - Immediate(val) + OperandValue::Immediate(val) } else { - Ref(val) + OperandValue::Ref(val) }; assert!(!ty.has_erasable_regions()); diff --git a/src/librustc_trans/trans/mir/did.rs b/src/librustc_trans/trans/mir/did.rs index 28a7ca3f72f4..368708d470be 100644 --- a/src/librustc_trans/trans/mir/did.rs +++ b/src/librustc_trans/trans/mir/did.rs @@ -50,6 +50,8 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> { let did = inline::maybe_instantiate_inline(bcx.ccx(), did); let expr = const_eval::lookup_const_by_id(bcx.tcx(), did, None) .expect("def was const, but lookup_const_by_id failed"); + // FIXME: this is falling back to translating from HIR. This is not easy to fix, + // because we would have somehow adapt const_eval to work on MIR rather than HIR. let d = expr::trans(bcx, expr); OperandRef::from_rvalue_datum(d.datum.to_rvalue_datum(d.bcx, "").datum) }