Skip to content

Commit eede953

Browse files
committed
Only get ImplKind::Impl once
1 parent f4e4485 commit eede953

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

src/librustdoc/clean/inline.rs

+22-19
Original file line numberDiff line numberDiff line change
@@ -350,14 +350,22 @@ pub fn build_impl(
350350
}
351351
}
352352

353-
let for_ = if let Some(did) = did.as_local() {
354-
let hir_id = tcx.hir().local_def_id_to_hir_id(did);
355-
match tcx.hir().expect_item(hir_id).kind {
356-
hir::ItemKind::Impl { self_ty, .. } => self_ty.clean(cx),
357-
_ => panic!("did given to build_impl was not an impl"),
353+
let impl_item = match did.as_local() {
354+
Some(did) => {
355+
let hir_id = tcx.hir().local_def_id_to_hir_id(did);
356+
match tcx.hir().expect_item(hir_id).kind {
357+
hir::ItemKind::Impl { self_ty, ref generics, ref items, .. } => {
358+
Some((self_ty, generics, items))
359+
}
360+
_ => panic!("`DefID` passed to `build_impl` is not an `impl"),
361+
}
358362
}
359-
} else {
360-
tcx.type_of(did).clean(cx)
363+
None => None,
364+
};
365+
366+
let for_ = match impl_item {
367+
Some((self_ty, _, _)) => self_ty.clean(cx),
368+
None => tcx.type_of(did).clean(cx),
361369
};
362370

363371
// Only inline impl if the implementing type is
@@ -377,17 +385,12 @@ pub fn build_impl(
377385
}
378386

379387
let predicates = tcx.explicit_predicates_of(did);
380-
let (trait_items, generics) = if let Some(did) = did.as_local() {
381-
let hir_id = tcx.hir().local_def_id_to_hir_id(did);
382-
match tcx.hir().expect_item(hir_id).kind {
383-
hir::ItemKind::Impl { ref generics, ref items, .. } => (
384-
items.iter().map(|item| tcx.hir().impl_item(item.id).clean(cx)).collect::<Vec<_>>(),
385-
generics.clean(cx),
386-
),
387-
_ => panic!("did given to build_impl was not an impl"),
388-
}
389-
} else {
390-
(
388+
let (trait_items, generics) = match impl_item {
389+
Some((_, generics, items)) => (
390+
items.iter().map(|item| tcx.hir().impl_item(item.id).clean(cx)).collect::<Vec<_>>(),
391+
generics.clean(cx),
392+
),
393+
None => (
391394
tcx.associated_items(did)
392395
.in_definition_order()
393396
.filter_map(|item| {
@@ -399,7 +402,7 @@ pub fn build_impl(
399402
})
400403
.collect::<Vec<_>>(),
401404
clean::enter_impl_trait(cx, || (tcx.generics_of(did), predicates).clean(cx)),
402-
)
405+
),
403406
};
404407
let polarity = tcx.impl_polarity(did);
405408
let trait_ = associated_trait.clean(cx).map(|bound| match bound {

0 commit comments

Comments
 (0)