about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-06-15 10:56:42 +0200
committerGitHub <noreply@github.com>2024-06-15 10:56:42 +0200
commit6f21da3bb40f942f0d559f80e897426874006223 (patch)
tree067a31754c895d14c9a247eb0303b5b2f1ac9923
parentf24509aa232f927332219cb56fd1b13ba680e1dd (diff)
parent5c8bb678d07da4fe64e0595e7ace7b993fc0f000 (diff)
downloadrust-6f21da3bb40f942f0d559f80e897426874006223.tar.gz
rust-6f21da3bb40f942f0d559f80e897426874006223.zip
Rollup merge of #126471 - oli-obk:filter_loop, r=compiler-errors
Use a consistent way to filter out bounds instead of splitting it into three places

just a small cleanup, no logic change.

Initially the code had me looking for why anything was special here, only to realize there's nothing interesting going on
-rw-r--r--compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs17
1 files changed, 6 insertions, 11 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs
index a026b233c68..c53939bfe60 100644
--- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs
+++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs
@@ -239,24 +239,19 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
             return Ok(());
         }
 
-        let all_bounds = stack
+        let bounds = stack
             .obligation
             .param_env
             .caller_bounds()
             .iter()
             .filter(|p| !p.references_error())
-            .filter_map(|p| p.as_trait_clause());
-
-        // Micro-optimization: filter out predicates relating to different traits.
-        let matching_bounds =
-            all_bounds.filter(|p| p.def_id() == stack.obligation.predicate.def_id());
+            .filter_map(|p| p.as_trait_clause())
+            // Micro-optimization: filter out predicates relating to different traits.
+            .filter(|p| p.def_id() == stack.obligation.predicate.def_id())
+            .filter(|p| p.polarity() == stack.obligation.predicate.polarity());
 
         // Keep only those bounds which may apply, and propagate overflow if it occurs.
-        for bound in matching_bounds {
-            if bound.skip_binder().polarity != stack.obligation.predicate.skip_binder().polarity {
-                continue;
-            }
-
+        for bound in bounds {
             // FIXME(oli-obk): it is suspicious that we are dropping the constness and
             // polarity here.
             let wc = self.where_clause_may_apply(stack, bound.map_bound(|t| t.trait_ref))?;