Skip to content

Commit eeaaee8

Browse files
Rollup merge of rust-lang#67631 - oli-obk:polymorphic_promotion, r=wesleywiser
Work around a resolve bug in const prop r? @wesleywiser @anp This isn't exposed right now, but further changes to rustc may start causing bugs without this.
2 parents 39935ea + 3ab0663 commit eeaaee8

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/librustc_mir/transform/const_prop.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc::ty::layout::{
2020
HasDataLayout, HasTyCtxt, LayoutError, LayoutOf, Size, TargetDataLayout, TyLayout,
2121
};
2222
use rustc::ty::subst::InternalSubsts;
23-
use rustc::ty::{self, Instance, ParamEnv, Ty, TyCtxt};
23+
use rustc::ty::{self, Instance, ParamEnv, Ty, TyCtxt, TypeFoldable};
2424
use rustc_data_structures::fx::FxHashMap;
2525
use rustc_index::vec::IndexVec;
2626
use syntax::ast::Mutability;
@@ -410,6 +410,12 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
410410
}
411411

412412
fn eval_constant(&mut self, c: &Constant<'tcx>) -> Option<Const<'tcx>> {
413+
// `eval_const_to_op` uses `Instance::resolve` which still has a bug (#66901) in the
414+
// presence of trait items with a default body. So we just bail out if we aren't 100%
415+
// monomorphic.
416+
if c.literal.needs_subst() {
417+
return None;
418+
}
413419
self.ecx.tcx.span = c.span;
414420
match self.ecx.eval_const_to_op(c.literal, None) {
415421
Ok(op) => Some(op),
@@ -556,6 +562,13 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
556562
_ => {}
557563
}
558564

565+
// `eval_rvalue_into_place` uses `Instance::resolve` for constants which still has a bug
566+
// (#66901) in the presence of trait items with a default body. So we just bail out if we
567+
// aren't 100% monomorphic.
568+
if rvalue.needs_subst() {
569+
return None;
570+
}
571+
559572
self.use_ecx(source_info, |this| {
560573
trace!("calling eval_rvalue_into_place(rvalue = {:?}, place = {:?})", rvalue, place);
561574
this.ecx.eval_rvalue_into_place(rvalue, place)?;

0 commit comments

Comments
 (0)