Skip to content

Commit 20e2693

Browse files
committed
[HACK] also insert in projection_cache for the pre-ReLateBound->RePlaceholder key.
1 parent 1ac2dca commit 20e2693

File tree

1 file changed

+28
-1
lines changed
  • compiler/rustc_trait_selection/src/traits

1 file changed

+28
-1
lines changed

compiler/rustc_trait_selection/src/traits/project.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ pub(super) fn poly_project_and_unify_type<'cx, 'tcx>(
182182
selcx: &mut SelectionContext<'cx, 'tcx>,
183183
obligation: &PolyProjectionObligation<'tcx>,
184184
) -> ProjectAndUnifyResult<'tcx> {
185+
let pre_bound2placeholder_cache_key =
186+
ProjectionCacheKey::from_poly_projection_predicate(selcx, obligation.predicate).unwrap();
187+
185188
let infcx = selcx.infcx();
186189
let r = infcx.commit_if_ok(|_snapshot| {
187190
let old_universe = infcx.universe();
@@ -190,7 +193,11 @@ pub(super) fn poly_project_and_unify_type<'cx, 'tcx>(
190193
let new_universe = infcx.universe();
191194

192195
let placeholder_obligation = obligation.with(placeholder_predicate);
193-
match project_and_unify_type(selcx, &placeholder_obligation) {
196+
match project_and_unify_type(
197+
selcx,
198+
&placeholder_obligation,
199+
Some(&pre_bound2placeholder_cache_key),
200+
) {
194201
ProjectAndUnifyResult::MismatchedProjectionTypes(e) => Err(e),
195202
ProjectAndUnifyResult::Holds(obligations)
196203
if old_universe != new_universe
@@ -235,6 +242,7 @@ pub(super) fn poly_project_and_unify_type<'cx, 'tcx>(
235242
fn project_and_unify_type<'cx, 'tcx>(
236243
selcx: &mut SelectionContext<'cx, 'tcx>,
237244
obligation: &ProjectionObligation<'tcx>,
245+
pre_bound2placeholder_cache_key: Option<&ProjectionCacheKey<'tcx>>,
238246
) -> ProjectAndUnifyResult<'tcx> {
239247
let mut obligations = vec![];
240248

@@ -246,6 +254,7 @@ fn project_and_unify_type<'cx, 'tcx>(
246254
obligation.cause.clone(),
247255
obligation.recursion_depth,
248256
&mut obligations,
257+
pre_bound2placeholder_cache_key,
249258
) {
250259
Ok(Some(n)) => n,
251260
Ok(None) => return ProjectAndUnifyResult::FailedNormalization,
@@ -539,6 +548,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
539548
self.cause.clone(),
540549
self.depth,
541550
&mut self.obligations,
551+
None,
542552
)
543553
.ok()
544554
.flatten()
@@ -578,6 +588,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
578588
self.cause.clone(),
579589
self.depth,
580590
&mut self.obligations,
591+
None,
581592
)
582593
.ok()
583594
.flatten()
@@ -917,6 +928,7 @@ pub fn normalize_projection_type<'a, 'b, 'tcx>(
917928
cause.clone(),
918929
depth,
919930
obligations,
931+
None,
920932
)
921933
.ok()
922934
.flatten()
@@ -950,6 +962,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
950962
cause: ObligationCause<'tcx>,
951963
depth: usize,
952964
obligations: &mut Vec<PredicateObligation<'tcx>>,
965+
pre_bound2placeholder_cache_key: Option<&ProjectionCacheKey<'tcx>>,
953966
) -> Result<Option<Term<'tcx>>, InProgress> {
954967
let infcx = selcx.infcx();
955968
// Don't use the projection cache in intercrate mode -
@@ -1069,6 +1082,20 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
10691082

10701083
if use_cache {
10711084
infcx.inner.borrow_mut().projection_cache().insert_term(cache_key, result.clone());
1085+
if let Some(&pre_bound2placeholder_cache_key) = pre_bound2placeholder_cache_key {
1086+
if !result.has_placeholders() {
1087+
// HACK(eddyb) `pre_bound2placeholder_cache_key` was never started.
1088+
let mut infcx_inner = infcx.inner.borrow_mut();
1089+
if let Ok(()) = infcx_inner
1090+
.projection_cache()
1091+
.try_start(pre_bound2placeholder_cache_key)
1092+
{
1093+
infcx_inner
1094+
.projection_cache()
1095+
.insert_term(pre_bound2placeholder_cache_key, result.clone());
1096+
}
1097+
}
1098+
}
10721099
}
10731100
obligations.extend(result.obligations);
10741101
Ok(Some(result.value))

0 commit comments

Comments
 (0)