Skip to content

Commit 5c8bb67

Browse files
committed
Use a consistent way to filter out bounds instead of splitting it into three places
1 parent d2ad293 commit 5c8bb67

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs

+6-11
Original file line numberDiff line numberDiff line change
@@ -239,24 +239,19 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
239239
return Ok(());
240240
}
241241

242-
let all_bounds = stack
242+
let bounds = stack
243243
.obligation
244244
.param_env
245245
.caller_bounds()
246246
.iter()
247247
.filter(|p| !p.references_error())
248-
.filter_map(|p| p.as_trait_clause());
249-
250-
// Micro-optimization: filter out predicates relating to different traits.
251-
let matching_bounds =
252-
all_bounds.filter(|p| p.def_id() == stack.obligation.predicate.def_id());
248+
.filter_map(|p| p.as_trait_clause())
249+
// Micro-optimization: filter out predicates relating to different traits.
250+
.filter(|p| p.def_id() == stack.obligation.predicate.def_id())
251+
.filter(|p| p.polarity() == stack.obligation.predicate.polarity());
253252

254253
// Keep only those bounds which may apply, and propagate overflow if it occurs.
255-
for bound in matching_bounds {
256-
if bound.skip_binder().polarity != stack.obligation.predicate.skip_binder().polarity {
257-
continue;
258-
}
259-
254+
for bound in bounds {
260255
// FIXME(oli-obk): it is suspicious that we are dropping the constness and
261256
// polarity here.
262257
let wc = self.where_clause_may_apply(stack, bound.map_bound(|t| t.trait_ref))?;

0 commit comments

Comments
 (0)