Rollup merge of #76783 - lzutao:rd_impl_kind, r=GuillaumeGomez
Only get ImplKind::Impl once With this, the code panics in one place instead of two.
This commit is contained in:
commit
b3433c7cc9
@ -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
|
||||
@ -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| {
|
||||
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user