Only dedup obligation after new ones have been added.

This commit is contained in:
Nicholas Nethercote 2023-08-08 14:25:03 +10:00
parent 3c99b3dbd0
commit 8378487f27

View File

@ -1214,7 +1214,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
let projected_term = selcx.infcx.resolve_vars_if_possible(projected_term); let projected_term = selcx.infcx.resolve_vars_if_possible(projected_term);
let mut result = if projected_term.has_projections() { let result = if projected_term.has_projections() {
let mut normalizer = AssocTypeNormalizer::new( let mut normalizer = AssocTypeNormalizer::new(
selcx, selcx,
param_env, param_env,
@ -1224,14 +1224,14 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
); );
let normalized_ty = normalizer.fold(projected_term); let normalized_ty = normalizer.fold(projected_term);
let mut deduped = SsoHashSet::with_capacity(projected_obligations.len());
projected_obligations.retain(|obligation| deduped.insert(obligation.clone()));
Normalized { value: normalized_ty, obligations: projected_obligations } Normalized { value: normalized_ty, obligations: projected_obligations }
} else { } else {
Normalized { value: projected_term, obligations: projected_obligations } Normalized { value: projected_term, obligations: projected_obligations }
}; };
let mut deduped = SsoHashSet::with_capacity(projected_obligations.len());
result.obligations.retain(|obligation| deduped.insert(obligation.clone()));
if use_cache { if use_cache {
infcx.inner.borrow_mut().projection_cache().insert_term(cache_key, result.clone()); infcx.inner.borrow_mut().projection_cache().insert_term(cache_key, result.clone());
} }