Rollup merge of #92860 - CraftSpider:rustdoc-json-impl-ice, r=jsha

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

Related to #83718

We can safely skip the children, as they don't contain any new info, and may be subtly different for reasons hard to track down, in ways that are consistently worse than the actual generic impl.
This commit is contained in:
Matthias Krüger 2022-01-20 23:37:31 +01:00 committed by GitHub
commit 530c884372
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View File

@ -171,8 +171,21 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
/// the hashmap because certain items (traits and types) need to have their mappings for trait
/// implementations filled out before they're inserted.
fn item(&mut self, item: clean::Item) -> Result<(), Error> {
let local_blanket_impl = match item.def_id {
clean::ItemId::Blanket { impl_id, .. } => impl_id.is_local(),
clean::ItemId::Auto { .. }
| clean::ItemId::DefId(_)
| clean::ItemId::Primitive(_, _) => false,
};
// Flatten items that recursively store other items
item.kind.inner_items().for_each(|i| self.item(i.clone()).unwrap());
// FIXME(CraftSpider): We skip children of local blanket implementations, as we'll have
// already seen the actual generic impl, and the generated ones don't need documenting.
// This is necessary due to the visibility, return type, and self arg of the generated
// impls not quite matching, and will no longer be necessary when the mismatch is fixed.
if !local_blanket_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) {

View File

@ -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 {}