about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-12-12 11:24:20 +0000
committerbors <bors@rust-lang.org>2021-12-12 11:24:20 +0000
commit4c9bdf4cbbf1deab0b5da398d4910558a66b332f (patch)
treee4fbffd7c9d800a4bbe9cfbdcbb0778c85bbe2d0
parenta0a4c7d1e48c39a73119eb9107d402d60c83293b (diff)
parent39d44e72ca2ef82ea294f64e7ef3db23b4fdfd04 (diff)
downloadrust-4c9bdf4cbbf1deab0b5da398d4910558a66b332f.tar.gz
rust-4c9bdf4cbbf1deab0b5da398d4910558a66b332f.zip
Auto merge of #90423 - Aaron1011:deduplicate-projection, r=jackh726
Deduplicate projection sub-obligations
-rw-r--r--compiler/rustc_trait_selection/src/traits/project.rs6
1 files changed, 6 insertions, 0 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs
index b8c66931cbe..4a23206402e 100644
--- a/compiler/rustc_trait_selection/src/traits/project.rs
+++ b/compiler/rustc_trait_selection/src/traits/project.rs
@@ -20,6 +20,7 @@ use super::{Normalized, NormalizedTy, ProjectionCacheEntry, ProjectionCacheKey};
 use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
 use crate::infer::{InferCtxt, InferOk, LateBoundRegionConversionTime};
 use crate::traits::error_reporting::InferCtxtExt as _;
+use rustc_data_structures::sso::SsoHashSet;
 use rustc_data_structures::stack::ensure_sufficient_stack;
 use rustc_errors::ErrorReported;
 use rustc_hir::def_id::DefId;
@@ -944,9 +945,14 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
                 Normalized { value: projected_ty, obligations: projected_obligations }
             };
 
+            let mut deduped: SsoHashSet<_> = Default::default();
             let mut canonical =
                 SelectionContext::with_query_mode(selcx.infcx(), TraitQueryMode::Canonical);
+
             result.obligations.drain_filter(|projected_obligation| {
+                if !deduped.insert(projected_obligation.clone()) {
+                    return true;
+                }
                 // If any global obligations always apply, considering regions, then we don't
                 // need to include them. The `is_global` check rules out inference variables,
                 // so there's no need for the caller of `opt_normalize_projection_type`