From d3a6d67fb85c766d58c3097ef8c880e468e25478 Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Tue, 8 Mar 2016 14:20:06 +0200 Subject: [PATCH] mir: Don't use ConstVal when adjustments are involved, as they would be lost. --- src/librustc_mir/hair/cx/expr.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/librustc_mir/hair/cx/expr.rs b/src/librustc_mir/hair/cx/expr.rs index 1f8a5da9c1b..e1962eb076b 100644 --- a/src/librustc_mir/hair/cx/expr.rs +++ b/src/librustc_mir/hair/cx/expr.rs @@ -668,11 +668,15 @@ fn convert_path_expr<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>, expr: &'tcx hir::Expr) }, Def::Const(def_id) | Def::AssociatedConst(def_id) => { - if let Some(v) = cx.try_const_eval_literal(expr) { - return ExprKind::Literal { literal: v }; - } else { - def_id + if let Some(e) = const_eval::lookup_const_by_id(cx.tcx, def_id, Some(expr.id), None) { + // FIXME ConstVal can't be yet used with adjustments, as they would be lost. + if !cx.tcx.tables.borrow().adjustments.contains_key(&e.id) { + if let Some(v) = cx.try_const_eval_literal(e) { + return ExprKind::Literal { literal: v }; + } + } } + def_id } Def::Static(node_id, _) => return ExprKind::StaticRef {