@@ -116,11 +116,11 @@ pub fn elaborate_predicates_with_span<'tcx>(
116
116
117
117
pub fn elaborate_obligations < ' tcx > (
118
118
tcx : TyCtxt < ' tcx > ,
119
- mut obligations : Vec < PredicateObligation < ' tcx > > ,
119
+ obligations : Vec < PredicateObligation < ' tcx > > ,
120
120
) -> Elaborator < ' tcx > {
121
- let mut visited = PredicateSet :: new ( tcx) ;
122
- obligations . retain ( |obligation| visited . insert ( obligation . predicate ) ) ;
123
- Elaborator { stack : obligations , visited }
121
+ let mut elaborator = Elaborator { stack : Vec :: new ( ) , visited : PredicateSet :: new ( tcx) } ;
122
+ elaborator . extend_deduped ( obligations ) ;
123
+ elaborator
124
124
}
125
125
126
126
fn predicate_obligation < ' tcx > (
@@ -132,6 +132,15 @@ fn predicate_obligation<'tcx>(
132
132
}
133
133
134
134
impl < ' tcx > Elaborator < ' tcx > {
135
+ fn extend_deduped ( & mut self , obligations : impl IntoIterator < Item = PredicateObligation < ' tcx > > ) {
136
+ // Only keep those bounds that we haven't already seen.
137
+ // This is necessary to prevent infinite recursion in some
138
+ // cases. One common case is when people define
139
+ // `trait Sized: Sized { }` rather than `trait Sized { }`.
140
+ // let visited = &mut self.visited;
141
+ self . stack . extend ( obligations. into_iter ( ) . filter ( |o| self . visited . insert ( o. predicate ) ) ) ;
142
+ }
143
+
135
144
pub fn filter_to_traits ( self ) -> FilterToTraits < Self > {
136
145
FilterToTraits :: new ( self )
137
146
}
@@ -172,15 +181,7 @@ impl<'tcx> Elaborator<'tcx> {
172
181
)
173
182
} ) ;
174
183
debug ! ( ?data, ?obligations, "super_predicates" ) ;
175
-
176
- // Only keep those bounds that we haven't already seen.
177
- // This is necessary to prevent infinite recursion in some
178
- // cases. One common case is when people define
179
- // `trait Sized: Sized { }` rather than `trait Sized { }`.
180
- let visited = & mut self . visited ;
181
- let obligations = obligations. filter ( |o| visited. insert ( o. predicate ) ) ;
182
-
183
- self . stack . extend ( obligations) ;
184
+ self . extend_deduped ( obligations) ;
184
185
}
185
186
ty:: PredicateKind :: WellFormed ( ..) => {
186
187
// Currently, we do not elaborate WF predicates,
@@ -237,10 +238,9 @@ impl<'tcx> Elaborator<'tcx> {
237
238
return ;
238
239
}
239
240
240
- let visited = & mut self . visited ;
241
241
let mut components = smallvec ! [ ] ;
242
242
push_outlives_components ( tcx, ty_max, & mut components) ;
243
- self . stack . extend (
243
+ self . extend_deduped (
244
244
components
245
245
. into_iter ( )
246
246
. filter_map ( |component| match component {
@@ -280,7 +280,6 @@ impl<'tcx> Elaborator<'tcx> {
280
280
. map ( |predicate_kind| {
281
281
bound_predicate. rebind ( predicate_kind) . to_predicate ( tcx)
282
282
} )
283
- . filter ( |& predicate| visited. insert ( predicate) )
284
283
. map ( |predicate| {
285
284
predicate_obligation (
286
285
predicate,
0 commit comments