Skip to content

Commit 532df00

Browse files
authored
Rollup merge of rust-lang#76783 - lzutao:rd_impl_kind, r=GuillaumeGomez
Only get ImplKind::Impl once With this, the code panics in one place instead of two.
2 parents 7826459 + eede953 commit 532df00

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
@@ -352,14 +352,22 @@ pub fn build_impl(
352352
}
353353
}
354354

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

365373
// Only inline impl if the implementing type is
@@ -379,17 +387,12 @@ pub fn build_impl(
379387
}
380388

381389
let predicates = tcx.explicit_predicates_of(did);
382-
let (trait_items, generics) = if let Some(did) = did.as_local() {
383-
let hir_id = tcx.hir().local_def_id_to_hir_id(did);
384-
match tcx.hir().expect_item(hir_id).kind {
385-
hir::ItemKind::Impl { ref generics, ref items, .. } => (
386-
items.iter().map(|item| tcx.hir().impl_item(item.id).clean(cx)).collect::<Vec<_>>(),
387-
generics.clean(cx),
388-
),
389-
_ => panic!("did given to build_impl was not an impl"),
390-
}
391-
} else {
392-
(
390+
let (trait_items, generics) = match impl_item {
391+
Some((_, generics, items)) => (
392+
items.iter().map(|item| tcx.hir().impl_item(item.id).clean(cx)).collect::<Vec<_>>(),
393+
generics.clean(cx),
394+
),
395+
None => (
393396
tcx.associated_items(did)
394397
.in_definition_order()
395398
.filter_map(|item| {
@@ -401,7 +404,7 @@ pub fn build_impl(
401404
})
402405
.collect::<Vec<_>>(),
403406
clean::enter_impl_trait(cx, || (tcx.generics_of(did), predicates).clean(cx)),
404-
)
407+
),
405408
};
406409
let polarity = tcx.impl_polarity(did);
407410
let trait_ = associated_trait.clean(cx).map(|bound| match bound {

0 commit comments

Comments
 (0)