@@ -181,15 +181,44 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
181
181
let name = item. name ;
182
182
let item_id = item. item_id ;
183
183
if let Some ( mut new_item) = self . convert_item ( item) {
184
- if let types:: ItemEnum :: Trait ( ref mut t) = new_item. inner {
185
- t. implementations = self . get_trait_implementors ( item_id. expect_def_id ( ) )
186
- } else if let types:: ItemEnum :: Struct ( ref mut s) = new_item. inner {
187
- s. impls = self . get_impls ( item_id. expect_def_id ( ) )
188
- } else if let types:: ItemEnum :: Enum ( ref mut e) = new_item. inner {
189
- e. impls = self . get_impls ( item_id. expect_def_id ( ) )
190
- } else if let types:: ItemEnum :: Union ( ref mut u) = new_item. inner {
191
- u. impls = self . get_impls ( item_id. expect_def_id ( ) )
192
- }
184
+ let can_be_ignored = match new_item. inner {
185
+ types:: ItemEnum :: Trait ( ref mut t) => {
186
+ t. implementations = self . get_trait_implementors ( item_id. expect_def_id ( ) ) ;
187
+ false
188
+ }
189
+ types:: ItemEnum :: Struct ( ref mut s) => {
190
+ s. impls = self . get_impls ( item_id. expect_def_id ( ) ) ;
191
+ false
192
+ }
193
+ types:: ItemEnum :: Enum ( ref mut e) => {
194
+ e. impls = self . get_impls ( item_id. expect_def_id ( ) ) ;
195
+ false
196
+ }
197
+ types:: ItemEnum :: Union ( ref mut u) => {
198
+ u. impls = self . get_impls ( item_id. expect_def_id ( ) ) ;
199
+ false
200
+ }
201
+
202
+ types:: ItemEnum :: Method ( _)
203
+ | types:: ItemEnum :: AssocConst { .. }
204
+ | types:: ItemEnum :: AssocType { .. } => true ,
205
+ types:: ItemEnum :: Module ( _)
206
+ | types:: ItemEnum :: ExternCrate { .. }
207
+ | types:: ItemEnum :: Import ( _)
208
+ | types:: ItemEnum :: StructField ( _)
209
+ | types:: ItemEnum :: Variant ( _)
210
+ | types:: ItemEnum :: Function ( _)
211
+ | types:: ItemEnum :: TraitAlias ( _)
212
+ | types:: ItemEnum :: Impl ( _)
213
+ | types:: ItemEnum :: Typedef ( _)
214
+ | types:: ItemEnum :: OpaqueTy ( _)
215
+ | types:: ItemEnum :: Constant ( _)
216
+ | types:: ItemEnum :: Static ( _)
217
+ | types:: ItemEnum :: ForeignType
218
+ | types:: ItemEnum :: Macro ( _)
219
+ | types:: ItemEnum :: ProcMacro ( _)
220
+ | types:: ItemEnum :: PrimitiveType ( _) => false ,
221
+ } ;
193
222
let removed = self
194
223
. index
195
224
. borrow_mut ( )
@@ -199,7 +228,11 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
199
228
// to make sure the items are unique. The main place this happens is when an item, is
200
229
// reexported in more than one place. See `rustdoc-json/reexport/in_root_and_mod`
201
230
if let Some ( old_item) = removed {
202
- assert_eq ! ( old_item, new_item) ;
231
+ // In case of generic implementations (like `impl<T> Trait for T {}`), all the
232
+ // inner items will be duplicated so we can ignore if they are slightly different.
233
+ if !can_be_ignored {
234
+ assert_eq ! ( old_item, new_item) ;
235
+ }
203
236
}
204
237
}
205
238
0 commit comments