From 652cec1410bbeb74b8483101fc7788b444b29772 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Thu, 26 Dec 2019 15:10:13 +0100 Subject: [PATCH] Work around a resolve bug in const prop --- src/librustc_mir/transform/const_prop.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index a6b30ab5e68cf..88b916424f155 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -20,7 +20,7 @@ use rustc::ty::layout::{ HasDataLayout, HasTyCtxt, LayoutError, LayoutOf, Size, TargetDataLayout, TyLayout, }; use rustc::ty::subst::InternalSubsts; -use rustc::ty::{self, Instance, ParamEnv, Ty, TyCtxt}; +use rustc::ty::{self, Instance, ParamEnv, Ty, TyCtxt, TypeFoldable}; use rustc_data_structures::fx::FxHashMap; use rustc_index::vec::IndexVec; use syntax::ast::Mutability; @@ -410,6 +410,12 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { } fn eval_constant(&mut self, c: &Constant<'tcx>) -> Option> { + // `eval_const_to_op` uses `Instance::resolve` which still has a bug (#66901) in the + // presence of trait items with a default body. So we just bail out if we aren't 100% + // monomorphic. + if c.literal.needs_subst() { + return None; + } self.ecx.tcx.span = c.span; match self.ecx.eval_const_to_op(c.literal, None) { Ok(op) => Some(op),