Skip to content

Commit 6871b3f

Browse files
authored
Auto merge of #34657 - oli-obk:no_needless_const_eval, r=eddyb
don't const eval constants during MIR creation this didn't work very well anyway, because const_eval can't eval all kinds of constants.
2 parents 46e7f4b + e7b083a commit 6871b3f

File tree

2 files changed

+1
-28
lines changed

2 files changed

+1
-28
lines changed

src/librustc_mir/hair/cx/expr.rs

+1-13
Original file line numberDiff line numberDiff line change
@@ -700,19 +700,7 @@ fn convert_path_expr<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
700700
ref sty => bug!("unexpected sty: {:?}", sty)
701701
},
702702
Def::Const(def_id) |
703-
Def::AssociatedConst(def_id) => {
704-
let substs = Some(cx.tcx.node_id_item_substs(expr.id).substs);
705-
let tcx = cx.tcx.global_tcx();
706-
if let Some((e, _)) = const_eval::lookup_const_by_id(tcx, def_id, substs) {
707-
// FIXME ConstVal can't be yet used with adjustments, as they would be lost.
708-
if !cx.tcx.tables.borrow().adjustments.contains_key(&e.id) {
709-
if let Some(v) = cx.try_const_eval_literal(e) {
710-
return ExprKind::Literal { literal: v };
711-
}
712-
}
713-
}
714-
def_id
715-
}
703+
Def::AssociatedConst(def_id) => def_id,
716704

717705
Def::Static(node_id, _) => return ExprKind::StaticRef {
718706
id: node_id,

src/librustc_mir/hair/cx/mod.rs

-15
Original file line numberDiff line numberDiff line change
@@ -129,21 +129,6 @@ impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> {
129129
}
130130
}
131131

132-
pub fn try_const_eval_literal(&mut self, e: &hir::Expr) -> Option<Literal<'tcx>> {
133-
let hint = const_eval::EvalHint::ExprTypeChecked;
134-
let tcx = self.tcx.global_tcx();
135-
const_eval::eval_const_expr_partial(tcx, e, hint, None).ok().and_then(|v| {
136-
match v {
137-
// All of these contain local IDs, unsuitable for storing in MIR.
138-
ConstVal::Struct(_) | ConstVal::Tuple(_) |
139-
ConstVal::Array(..) | ConstVal::Repeat(..) |
140-
ConstVal::Function(_) => None,
141-
142-
_ => Some(Literal::Value { value: v })
143-
}
144-
})
145-
}
146-
147132
pub fn trait_method(&mut self,
148133
trait_def_id: DefId,
149134
method_name: &str,

0 commit comments

Comments
 (0)