From f4b42946c8d0e2b74dc78c34a833cc94c2df251d Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Fri, 21 Jan 2022 13:01:58 -0500 Subject: [PATCH 1/3] Remove FIXME and fix inconsistency of local blanket impls by using HIR for them --- src/librustdoc/clean/blanket_impl.rs | 28 ++++++++++++++++++++++------ src/librustdoc/json/mod.rs | 15 +-------------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/librustdoc/clean/blanket_impl.rs b/src/librustdoc/clean/blanket_impl.rs index eafc74b9945ba..75ee663b926c4 100644 --- a/src/librustdoc/clean/blanket_impl.rs +++ b/src/librustdoc/clean/blanket_impl.rs @@ -101,6 +101,27 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> { cx.generated_synthetics.insert((ty, trait_def_id)); + let hir_imp = impl_def_id.as_local() + .map(|local| cx.tcx.hir().expect_item(local)) + .and_then(|item| if let hir::ItemKind::Impl(i) = &item.kind { + Some(i) + } else { + None + }); + + let items = match hir_imp { + Some(imp) => imp + .items + .iter() + .map(|ii| cx.tcx.hir().impl_item(ii.id).clean(cx)) + .collect::>(), + None => cx.tcx + .associated_items(impl_def_id) + .in_definition_order() + .map(|x| x.clean(cx)) + .collect::>(), + }; + impls.push(Item { name: None, attrs: Default::default(), @@ -117,12 +138,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> { // the post-inference `trait_ref`, as it's more accurate. trait_: Some(trait_ref.clean(cx)), for_: ty.clean(cx), - items: cx - .tcx - .associated_items(impl_def_id) - .in_definition_order() - .map(|x| x.clean(cx)) - .collect::>(), + items, polarity: ty::ImplPolarity::Positive, kind: ImplKind::Blanket(box trait_ref.self_ty().clean(cx)), }), diff --git a/src/librustdoc/json/mod.rs b/src/librustdoc/json/mod.rs index 8f484766d9a5b..f9e9fe0d3cf20 100644 --- a/src/librustdoc/json/mod.rs +++ b/src/librustdoc/json/mod.rs @@ -172,21 +172,8 @@ 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 - // 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()); - } + 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) { From 66d056a9bf0f7d486c2ed637c1e1a7b9ce0c3bbc Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Fri, 21 Jan 2022 13:19:18 -0500 Subject: [PATCH 2/3] Update test to include `self` case --- src/test/rustdoc-json/impls/blanket_with_local.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/rustdoc-json/impls/blanket_with_local.rs b/src/test/rustdoc-json/impls/blanket_with_local.rs index 963ea2fe5aea8..e5f48820720fd 100644 --- a/src/test/rustdoc-json/impls/blanket_with_local.rs +++ b/src/test/rustdoc-json/impls/blanket_with_local.rs @@ -4,10 +4,12 @@ // @has blanket_with_local.json "$.index[*][?(@.name=='Load')]" pub trait Load { fn load() {} + fn write(self) {} } impl

Load for P { fn load() {} + fn write(self) {} } // @has - "$.index[*][?(@.name=='Wrapper')]" From 92206318bc0ca743507367e492aaaa3c6660dbfb Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Sat, 22 Jan 2022 19:55:25 -0500 Subject: [PATCH 3/3] Add has tests for blanket_with_local trait methods --- src/test/rustdoc-json/impls/blanket_with_local.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/rustdoc-json/impls/blanket_with_local.rs b/src/test/rustdoc-json/impls/blanket_with_local.rs index e5f48820720fd..a3d55b35f0018 100644 --- a/src/test/rustdoc-json/impls/blanket_with_local.rs +++ b/src/test/rustdoc-json/impls/blanket_with_local.rs @@ -3,7 +3,9 @@ // @has blanket_with_local.json "$.index[*][?(@.name=='Load')]" pub trait Load { + // @has - "$.index[*][?(@.name=='load')]" fn load() {} + // @has - "$.index[*][?(@.name=='write')]" fn write(self) {} }