Skip to content

Commit d6f2c89

Browse files
committed
elaborate: skip projection with unconstrained vars
1 parent a8d52c9 commit d6f2c89

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

compiler/rustc_type_ir/src/elaborate.rs

+19-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use smallvec::smallvec;
55
use crate::data_structures::HashSet;
66
use crate::inherent::*;
77
use crate::outlives::{Component, push_outlives_components};
8+
use crate::visit::{collect_constrained_late_bound_regions, collect_referenced_late_bound_regions};
89
use crate::{self as ty, Interner, Upcast as _};
910

1011
/// "Elaboration" is the process of identifying all the predicates that
@@ -86,16 +87,31 @@ pub fn elaborate<I: Interner, O: Elaboratable<I>>(
8687
elaborator
8788
}
8889

90+
fn projection_has_unconstrained_vars<I: Interner>(cx: I, predicate: I::Predicate) -> bool {
91+
let Some(pred) = predicate.as_clause().and_then(|c| c.as_projection_clause()) else {
92+
return false;
93+
};
94+
95+
let constrained_regions =
96+
collect_constrained_late_bound_regions(cx, pred.map_bound(|pred| pred.projection_term));
97+
let referenced_regions =
98+
collect_referenced_late_bound_regions(cx, pred.map_bound(|pred| pred.term));
99+
referenced_regions.difference(&constrained_regions).next().is_some()
100+
}
101+
89102
impl<I: Interner, O: Elaboratable<I>> Elaborator<I, O> {
90103
fn extend_deduped(&mut self, obligations: impl IntoIterator<Item = O>) {
91104
// Only keep those bounds that we haven't already seen.
92105
// This is necessary to prevent infinite recursion in some
93106
// cases. One common case is when people define
94107
// `trait Sized: Sized { }` rather than `trait Sized { }`.
95108
self.stack.extend(
96-
obligations.into_iter().filter(|o| {
97-
self.visited.insert(self.cx.anonymize_bound_vars(o.predicate().kind()))
98-
}),
109+
obligations
110+
.into_iter()
111+
.filter(|o| !projection_has_unconstrained_vars(self.cx, o.predicate()))
112+
.filter(|o| {
113+
self.visited.insert(self.cx.anonymize_bound_vars(o.predicate().kind()))
114+
}),
99115
);
100116
}
101117

0 commit comments

Comments
 (0)