@@ -132,10 +132,12 @@ impl<'a, 'gcx, 'tcx> Children {
132132 simplified_self,
133133 ) ;
134134
135- for possible_sibling in match simplified_self {
136- Some ( sty) => self . filtered ( sty) ,
137- None => self . iter ( ) ,
138- } {
135+ let possible_siblings = match simplified_self {
136+ Some ( sty) => PotentialSiblings :: Filtered ( self . filtered ( sty) ) ,
137+ None => PotentialSiblings :: Unfiltered ( self . iter ( ) ) ,
138+ } ;
139+
140+ for possible_sibling in possible_siblings {
139141 debug ! (
140142 "insert: impl_def_id={:?}, simplified_self={:?}, possible_sibling={:?}" ,
141143 impl_def_id,
@@ -222,14 +224,37 @@ impl<'a, 'gcx, 'tcx> Children {
222224 Ok ( Inserted :: BecameNewSibling ( last_lint) )
223225 }
224226
225- fn iter ( & mut self ) -> Box < dyn Iterator < Item = DefId > + ' _ > {
227+ fn iter ( & mut self ) -> impl Iterator < Item = DefId > + ' _ {
226228 let nonblanket = self . nonblanket_impls . iter_mut ( ) . flat_map ( |( _, v) | v. iter ( ) ) ;
227- Box :: new ( self . blanket_impls . iter ( ) . chain ( nonblanket) . cloned ( ) )
229+ self . blanket_impls . iter ( ) . chain ( nonblanket) . cloned ( )
228230 }
229231
230- fn filtered ( & mut self , sty : SimplifiedType ) -> Box < dyn Iterator < Item = DefId > + ' _ > {
232+ fn filtered ( & mut self , sty : SimplifiedType ) -> impl Iterator < Item = DefId > + ' _ {
231233 let nonblanket = self . nonblanket_impls . entry ( sty) . or_default ( ) . iter ( ) ;
232- Box :: new ( self . blanket_impls . iter ( ) . chain ( nonblanket) . cloned ( ) )
234+ self . blanket_impls . iter ( ) . chain ( nonblanket) . cloned ( )
235+ }
236+ }
237+
238+ // A custom iterator used by Children::insert
239+ enum PotentialSiblings < I , J >
240+ where I : Iterator < Item = DefId > ,
241+ J : Iterator < Item = DefId >
242+ {
243+ Unfiltered ( I ) ,
244+ Filtered ( J )
245+ }
246+
247+ impl < I , J > Iterator for PotentialSiblings < I , J >
248+ where I : Iterator < Item = DefId > ,
249+ J : Iterator < Item = DefId >
250+ {
251+ type Item = DefId ;
252+
253+ fn next ( & mut self ) -> Option < Self :: Item > {
254+ match * self {
255+ PotentialSiblings :: Unfiltered ( ref mut iter) => iter. next ( ) ,
256+ PotentialSiblings :: Filtered ( ref mut iter) => iter. next ( )
257+ }
233258 }
234259}
235260
0 commit comments