Skip to content

Commit d3a6d67

Browse files
committed
mir: Don't use ConstVal when adjustments are involved, as they would be lost.
1 parent 9cc5ee3 commit d3a6d67

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/librustc_mir/hair/cx/expr.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -668,11 +668,15 @@ fn convert_path_expr<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>, expr: &'tcx hir::Expr)
668668
},
669669
Def::Const(def_id) |
670670
Def::AssociatedConst(def_id) => {
671-
if let Some(v) = cx.try_const_eval_literal(expr) {
672-
return ExprKind::Literal { literal: v };
673-
} else {
674-
def_id
671+
if let Some(e) = const_eval::lookup_const_by_id(cx.tcx, def_id, Some(expr.id), None) {
672+
// FIXME ConstVal can't be yet used with adjustments, as they would be lost.
673+
if !cx.tcx.tables.borrow().adjustments.contains_key(&e.id) {
674+
if let Some(v) = cx.try_const_eval_literal(e) {
675+
return ExprKind::Literal { literal: v };
676+
}
677+
}
675678
}
679+
def_id
676680
}
677681

678682
Def::Static(node_id, _) => return ExprKind::StaticRef {

0 commit comments

Comments
 (0)