@@ -5,6 +5,7 @@ use smallvec::smallvec;
5
5
use crate :: data_structures:: HashSet ;
6
6
use crate :: inherent:: * ;
7
7
use crate :: outlives:: { Component , push_outlives_components} ;
8
+ use crate :: visit:: { collect_constrained_late_bound_regions, collect_referenced_late_bound_regions} ;
8
9
use crate :: { self as ty, Interner , Upcast as _} ;
9
10
10
11
/// "Elaboration" is the process of identifying all the predicates that
@@ -86,16 +87,31 @@ pub fn elaborate<I: Interner, O: Elaboratable<I>>(
86
87
elaborator
87
88
}
88
89
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
+
89
102
impl < I : Interner , O : Elaboratable < I > > Elaborator < I , O > {
90
103
fn extend_deduped ( & mut self , obligations : impl IntoIterator < Item = O > ) {
91
104
// Only keep those bounds that we haven't already seen.
92
105
// This is necessary to prevent infinite recursion in some
93
106
// cases. One common case is when people define
94
107
// `trait Sized: Sized { }` rather than `trait Sized { }`.
95
108
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
+ } ) ,
99
115
) ;
100
116
}
101
117
0 commit comments