From aa523a9b4b42662c721fc747aa2cc278797195f2 Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Thu, 13 Jan 2022 12:38:08 -0500 Subject: [PATCH] Fix errors on blanket impls by ignoring the children of their generated implementations --- src/librustdoc/clean/types.rs | 8 ++++++++ src/librustdoc/json/mod.rs | 6 +++++- src/test/rustdoc-json/impls/blanket_with_local.rs | 14 ++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/test/rustdoc-json/impls/blanket_with_local.rs diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 00c6e38839f..c47a2c7ca03 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -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, + } + } + #[inline] #[track_caller] crate fn expect_def_id(self) -> DefId { diff --git a/src/librustdoc/json/mod.rs b/src/librustdoc/json/mod.rs index 88a5c0c5ca2..c1efefc322e 100644 --- a/src/librustdoc/json/mod.rs +++ b/src/librustdoc/json/mod.rs @@ -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. + 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) { diff --git a/src/test/rustdoc-json/impls/blanket_with_local.rs b/src/test/rustdoc-json/impls/blanket_with_local.rs new file mode 100644 index 00000000000..88d1477f0b2 --- /dev/null +++ b/src/test/rustdoc-json/impls/blanket_with_local.rs @@ -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 method_abi.json "$.index[*][?(@.name=='Load')]" +pub trait Load { + fn load() {} +} + +impl

Load for P { + fn load() {} +} + +// @has - "$.index[*][?(@.name=='Wrapper')]" +pub struct Wrapper {}