]> git.lizzy.rs Git - rust.git/commitdiff
mir: Don't use ConstVal when adjustments are involved, as they would be lost.
authorEduard Burtescu <edy.burt@gmail.com>
Tue, 8 Mar 2016 12:20:06 +0000 (14:20 +0200)
committerEduard Burtescu <edy.burt@gmail.com>
Thu, 17 Mar 2016 19:51:53 +0000 (21:51 +0200)
src/librustc_mir/hair/cx/expr.rs

index 1f8a5da9c1b9d598d89e32719cbab9c8a5d9abbc..e1962eb076be53383bf3f1c8485f17aa5465c716 100644 (file)
@@ -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 {