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

Fix errors on blanket impls by ignoring the children of generated impls #92860

Merged
merged 5 commits into from
Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 8 additions & 0 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ impl ItemId {
}
}

#[inline]
crate fn is_local_impl(self) -> bool {
match self {
ItemId::Blanket { impl_id, .. } => impl_id.is_local(),
ItemId::Auto { .. } | ItemId::DefId(_) | ItemId::Primitive(_, _) => false,
}
}
CraftSpider marked this conversation as resolved.
Show resolved Hide resolved

#[inline]
#[track_caller]
crate fn expect_def_id(self) -> DefId {
Expand Down
6 changes: 5 additions & 1 deletion src/librustdoc/json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,11 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
/// implementations filled out before they're inserted.
fn item(&mut self, item: clean::Item) -> Result<(), Error> {
// Flatten items that recursively store other items
item.kind.inner_items().for_each(|i| self.item(i.clone()).unwrap());
// We skip local blanket implementations, as we'll have already seen the actual generic
// impl, and the generated ones don't need documenting.
CraftSpider marked this conversation as resolved.
Show resolved Hide resolved
if !item.def_id.is_local_impl() {
item.kind.inner_items().for_each(|i| self.item(i.clone()).unwrap());
}

let id = item.def_id;
if let Some(mut new_item) = self.convert_item(item) {
Expand Down
14 changes: 14 additions & 0 deletions src/test/rustdoc-json/impls/blanket_with_local.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Test for the ICE in rust/83718
// A blanket impl plus a local type together shouldn't result in mismatched ID issues

// @has blanket_with_local.json "$.index[*][?(@.name=='Load')]"
pub trait Load {
fn load() {}
}

impl<P> Load for P {
fn load() {}
}

// @has - "$.index[*][?(@.name=='Wrapper')]"
pub struct Wrapper {}