@@ -49,7 +49,7 @@ pub struct Graph {
49
49
50
50
/// Children of a given impl, grouped into blanket/non-blanket varieties as is
51
51
/// done in `TraitDef`.
52
- #[ derive( RustcEncodable , RustcDecodable ) ]
52
+ #[ derive( Default , RustcEncodable , RustcDecodable ) ]
53
53
struct Children {
54
54
// Impls of a trait (or specializations of a given impl). To allow for
55
55
// quicker lookup, the impls are indexed by a simplified version of their
@@ -81,21 +81,14 @@ enum Inserted {
81
81
}
82
82
83
83
impl < ' a , ' gcx , ' tcx > Children {
84
- fn new ( ) -> Children {
85
- Children {
86
- nonblanket_impls : FxHashMap ( ) ,
87
- blanket_impls : vec ! [ ] ,
88
- }
89
- }
90
-
91
84
/// Insert an impl into this set of children without comparing to any existing impls
92
85
fn insert_blindly ( & mut self ,
93
86
tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
94
87
impl_def_id : DefId ) {
95
88
let trait_ref = tcx. impl_trait_ref ( impl_def_id) . unwrap ( ) ;
96
89
if let Some ( sty) = fast_reject:: simplify_type ( tcx, trait_ref. self_ty ( ) , false ) {
97
90
debug ! ( "insert_blindly: impl_def_id={:?} sty={:?}" , impl_def_id, sty) ;
98
- self . nonblanket_impls . entry ( sty) . or_insert ( vec ! [ ] ) . push ( impl_def_id)
91
+ self . nonblanket_impls . entry ( sty) . or_default ( ) . push ( impl_def_id)
99
92
} else {
100
93
debug ! ( "insert_blindly: impl_def_id={:?} sty=None" , impl_def_id) ;
101
94
self . blanket_impls . push ( impl_def_id)
@@ -230,7 +223,7 @@ impl<'a, 'gcx, 'tcx> Children {
230
223
}
231
224
232
225
fn filtered ( & mut self , sty : SimplifiedType ) -> Box < dyn Iterator < Item = DefId > + ' _ > {
233
- let nonblanket = self . nonblanket_impls . entry ( sty) . or_insert ( vec ! [ ] ) . iter ( ) ;
226
+ let nonblanket = self . nonblanket_impls . entry ( sty) . or_default ( ) . iter ( ) ;
234
227
Box :: new ( self . blanket_impls . iter ( ) . chain ( nonblanket) . cloned ( ) )
235
228
}
236
229
}
@@ -268,7 +261,7 @@ impl<'a, 'gcx, 'tcx> Graph {
268
261
trait_ref, impl_def_id, trait_def_id) ;
269
262
270
263
self . parent . insert ( impl_def_id, trait_def_id) ;
271
- self . children . entry ( trait_def_id) . or_insert ( Children :: new ( ) )
264
+ self . children . entry ( trait_def_id) . or_default ( )
272
265
. insert_blindly ( tcx, impl_def_id) ;
273
266
return Ok ( None ) ;
274
267
}
@@ -281,7 +274,7 @@ impl<'a, 'gcx, 'tcx> Graph {
281
274
loop {
282
275
use self :: Inserted :: * ;
283
276
284
- let insert_result = self . children . entry ( parent) . or_insert ( Children :: new ( ) )
277
+ let insert_result = self . children . entry ( parent) . or_default ( )
285
278
. insert ( tcx, impl_def_id, simplified) ?;
286
279
287
280
match insert_result {
@@ -318,9 +311,8 @@ impl<'a, 'gcx, 'tcx> Graph {
318
311
self . parent . insert ( impl_def_id, parent) ;
319
312
320
313
// Add G as N's child.
321
- let mut grand_children = Children :: new ( ) ;
322
- grand_children. insert_blindly ( tcx, grand_child_to_be) ;
323
- self . children . insert ( impl_def_id, grand_children) ;
314
+ self . children . entry ( impl_def_id) . or_default ( )
315
+ . insert_blindly ( tcx, grand_child_to_be) ;
324
316
break ;
325
317
}
326
318
ShouldRecurseOn ( new_parent) => {
@@ -343,7 +335,7 @@ impl<'a, 'gcx, 'tcx> Graph {
343
335
was already present.") ;
344
336
}
345
337
346
- self . children . entry ( parent) . or_insert ( Children :: new ( ) ) . insert_blindly ( tcx, child) ;
338
+ self . children . entry ( parent) . or_default ( ) . insert_blindly ( tcx, child) ;
347
339
}
348
340
349
341
/// The parent of a given impl, which is the def id of the trait when the
0 commit comments