Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only get ImplKind::Impl once #76783

Merged
merged 1 commit into from
Sep 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,14 +350,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 @@ -377,17 +385,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 @@ -399,7 +402,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