Skip to content

Commit 2c13e4a

Browse files
only normalize projections if they have inference variables in them
1 parent 87a3778 commit 2c13e4a

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

compiler/rustc_middle/src/ty/flags.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,13 @@ impl FlagComputation {
327327
}
328328

329329
fn add_projection_ty(&mut self, projection_ty: ty::ProjectionTy<'_>) {
330+
let old_outer_exclusive_binder =
331+
std::mem::replace(&mut self.outer_exclusive_binder, ty::INNERMOST);
330332
self.add_substs(projection_ty.substs);
333+
if self.outer_exclusive_binder > ty::INNERMOST {
334+
self.add_flags(TypeFlags::HAS_LATE_IN_PROJECTION);
335+
}
336+
self.outer_exclusive_binder = self.outer_exclusive_binder.max(old_outer_exclusive_binder);
331337
}
332338

333339
fn add_substs(&mut self, substs: &[GenericArg<'_>]) {

compiler/rustc_middle/src/ty/fold.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,14 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
166166
fn still_further_specializable(&self) -> bool {
167167
self.has_type_flags(TypeFlags::STILL_FURTHER_SPECIALIZABLE)
168168
}
169+
170+
// Indicates that this value has projection types which capture late-bound variables,
171+
// which is a sign that the projection types within need further normalization. This
172+
// is because we do not replace projections with inference variables when they capture
173+
// late-bound variables.
174+
fn has_late_bound_vars_in_projection(&self) -> bool {
175+
self.has_type_flags(TypeFlags::HAS_LATE_IN_PROJECTION)
176+
}
169177
}
170178

171179
impl<'tcx> TypeFoldable<'tcx> for hir::Constness {

compiler/rustc_trait_selection/src/traits/fulfill.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
357357

358358
let infcx = self.selcx.infcx();
359359

360-
if obligation.predicate.has_projections() {
360+
if obligation.predicate.has_late_bound_vars_in_projection() {
361361
let mut obligations = Vec::new();
362362
let predicate = crate::traits::project::try_normalize_with_depth_to(
363363
self.selcx,

compiler/rustc_type_ir/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ bitflags! {
107107

108108
/// Does this value have `InferConst::Fresh`?
109109
const HAS_CT_FRESH = 1 << 19;
110+
111+
// Does this value have any late-bound vars in any projection type substs?
112+
const HAS_LATE_IN_PROJECTION = 1 << 20;
110113
}
111114
}
112115

0 commit comments

Comments
 (0)