@@ -217,6 +217,8 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
217
217
/// the hashmap because certain items (traits and types) need to have their mappings for trait
218
218
/// implementations filled out before they're inserted.
219
219
fn item ( & mut self , item : & clean:: Item ) -> Result < ( ) , Error > {
220
+ use std:: collections:: hash_map:: Entry ;
221
+
220
222
let item_type = item. type_ ( ) ;
221
223
let item_name = item. name ;
222
224
trace ! ( "rendering {item_type} {item_name:?}" ) ;
@@ -271,18 +273,25 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
271
273
| types:: ItemEnum :: Macro ( _)
272
274
| types:: ItemEnum :: ProcMacro ( _) => false ,
273
275
} ;
274
- let removed = self . index . insert ( new_item. id , new_item. clone ( ) ) ;
275
276
276
277
// FIXME(adotinthevoid): Currently, the index is duplicated. This is a sanity check
277
278
// to make sure the items are unique. The main place this happens is when an item, is
278
279
// reexported in more than one place. See `rustdoc-json/reexport/in_root_and_mod`
279
- if let Some ( old_item) = removed {
280
- // In case of generic implementations (like `impl<T> Trait for T {}`), all the
281
- // inner items will be duplicated so we can ignore if they are slightly different.
282
- if !can_be_ignored {
283
- assert_eq ! ( old_item, new_item) ;
280
+ match self . index . entry ( new_item. id ) {
281
+ Entry :: Vacant ( entry) => {
282
+ entry. insert ( new_item) ;
283
+ }
284
+ Entry :: Occupied ( mut entry) => {
285
+ // In case of generic implementations (like `impl<T> Trait for T {}`), all the
286
+ // inner items will be duplicated so we can ignore if they are slightly
287
+ // different.
288
+ let old_item = entry. get_mut ( ) ;
289
+ if !can_be_ignored {
290
+ assert_eq ! ( * old_item, new_item) ;
291
+ }
292
+ trace ! ( "replaced {old_item:?}\n with {new_item:?}" ) ;
293
+ * old_item = new_item;
284
294
}
285
- trace ! ( "replaced {old_item:?}\n with {new_item:?}" ) ;
286
295
}
287
296
}
288
297
0 commit comments