Skip to content

Commit

Permalink
Rollup merge of rust-lang#76783 - lzutao:rd_impl_kind, r=GuillaumeGomez
Browse files Browse the repository at this point in the history
Only get ImplKind::Impl once

With this, the code panics in one place instead of two.
  • Loading branch information
Dylan-DPC committed Sep 19, 2020
2 parents 33dfb7a + eede953 commit 0d5d402
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,14 +352,22 @@ pub fn build_impl(
}
}

let for_ = if let Some(did) = did.as_local() {
let hir_id = tcx.hir().local_def_id_to_hir_id(did);
match tcx.hir().expect_item(hir_id).kind {
hir::ItemKind::Impl { self_ty, .. } => self_ty.clean(cx),
_ => panic!("did given to build_impl was not an impl"),
let impl_item = match did.as_local() {
Some(did) => {
let hir_id = tcx.hir().local_def_id_to_hir_id(did);
match tcx.hir().expect_item(hir_id).kind {
hir::ItemKind::Impl { self_ty, ref generics, ref items, .. } => {
Some((self_ty, generics, items))
}
_ => panic!("`DefID` passed to `build_impl` is not an `impl"),
}
}
} else {
tcx.type_of(did).clean(cx)
None => None,
};

let for_ = match impl_item {
Some((self_ty, _, _)) => self_ty.clean(cx),
None => tcx.type_of(did).clean(cx),
};

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

let predicates = tcx.explicit_predicates_of(did);
let (trait_items, generics) = if let Some(did) = did.as_local() {
let hir_id = tcx.hir().local_def_id_to_hir_id(did);
match tcx.hir().expect_item(hir_id).kind {
hir::ItemKind::Impl { ref generics, ref items, .. } => (
items.iter().map(|item| tcx.hir().impl_item(item.id).clean(cx)).collect::<Vec<_>>(),
generics.clean(cx),
),
_ => panic!("did given to build_impl was not an impl"),
}
} else {
(
let (trait_items, generics) = match impl_item {
Some((_, generics, items)) => (
items.iter().map(|item| tcx.hir().impl_item(item.id).clean(cx)).collect::<Vec<_>>(),
generics.clean(cx),
),
None => (
tcx.associated_items(did)
.in_definition_order()
.filter_map(|item| {
Expand All @@ -401,7 +404,7 @@ pub fn build_impl(
})
.collect::<Vec<_>>(),
clean::enter_impl_trait(cx, || (tcx.generics_of(did), predicates).clean(cx)),
)
),
};
let polarity = tcx.impl_polarity(did);
let trait_ = associated_trait.clean(cx).map(|bound| match bound {
Expand Down

0 comments on commit 0d5d402

Please sign in to comment.