@@ -73,8 +73,8 @@ enum Inserted {
73
73
/// The impl was inserted as a new child in this group of children.
74
74
BecameNewSibling ( Option < OverlapError > ) ,
75
75
76
- /// The impl should replace an existing impl X, because the impl specializes X .
77
- ReplaceChild ( DefId ) ,
76
+ /// The impl should replace existing impls [X1, ..], because the impl specializes X1, X2, etc .
77
+ ReplaceChildren ( Vec < DefId > ) ,
78
78
79
79
/// The impl is a specialization of an existing child.
80
80
ShouldRecurseOn ( DefId ) ,
@@ -124,6 +124,7 @@ impl<'a, 'gcx, 'tcx> Children {
124
124
-> Result < Inserted , OverlapError >
125
125
{
126
126
let mut last_lint = None ;
127
+ let mut replace_children = Vec :: new ( ) ;
127
128
128
129
debug ! (
129
130
"insert(impl_def_id={:?}, simplified_self={:?})" ,
@@ -194,7 +195,7 @@ impl<'a, 'gcx, 'tcx> Children {
194
195
debug ! ( "placing as parent of TraitRef {:?}" ,
195
196
tcx. impl_trait_ref( possible_sibling) . unwrap( ) ) ;
196
197
197
- return Ok ( Inserted :: ReplaceChild ( possible_sibling) ) ;
198
+ replace_children . push ( possible_sibling) ;
198
199
} else {
199
200
if !tcx. impls_are_allowed_to_overlap ( impl_def_id, possible_sibling) {
200
201
traits:: overlapping_impls (
@@ -211,6 +212,10 @@ impl<'a, 'gcx, 'tcx> Children {
211
212
}
212
213
}
213
214
215
+ if !replace_children. is_empty ( ) {
216
+ return Ok ( Inserted :: ReplaceChildren ( replace_children) ) ;
217
+ }
218
+
214
219
// no overlap with any potential siblings, so add as a new sibling
215
220
debug ! ( "placing as new sibling" ) ;
216
221
self . insert_blindly ( tcx, impl_def_id) ;
@@ -282,7 +287,7 @@ impl<'a, 'gcx, 'tcx> Graph {
282
287
last_lint = opt_lint;
283
288
break ;
284
289
}
285
- ReplaceChild ( grand_child_to_be ) => {
290
+ ReplaceChildren ( grand_children_to_be ) => {
286
291
// We currently have
287
292
//
288
293
// P
@@ -302,17 +307,23 @@ impl<'a, 'gcx, 'tcx> Graph {
302
307
let siblings = self . children
303
308
. get_mut ( & parent)
304
309
. unwrap ( ) ;
305
- siblings. remove_existing ( tcx, grand_child_to_be) ;
310
+ for & grand_child_to_be in & grand_children_to_be {
311
+ siblings. remove_existing ( tcx, grand_child_to_be) ;
312
+ }
306
313
siblings. insert_blindly ( tcx, impl_def_id) ;
307
314
}
308
315
309
316
// Set G's parent to N and N's parent to P
310
- self . parent . insert ( grand_child_to_be, impl_def_id) ;
317
+ for & grand_child_to_be in & grand_children_to_be {
318
+ self . parent . insert ( grand_child_to_be, impl_def_id) ;
319
+ }
311
320
self . parent . insert ( impl_def_id, parent) ;
312
321
313
322
// Add G as N's child.
314
- self . children . entry ( impl_def_id) . or_default ( )
315
- . insert_blindly ( tcx, grand_child_to_be) ;
323
+ for & grand_child_to_be in & grand_children_to_be {
324
+ self . children . entry ( impl_def_id) . or_default ( )
325
+ . insert_blindly ( tcx, grand_child_to_be) ;
326
+ }
316
327
break ;
317
328
}
318
329
ShouldRecurseOn ( new_parent) => {
0 commit comments