From b1f5917930c5bb8f44522b260460c34618cd4c89 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Thu, 22 Apr 2021 21:02:21 -0400 Subject: [PATCH] Remove unnecessary `provided_trait_methods` field from Impl It can be calculated on-demand. --- src/librustdoc/clean/auto_trait.rs | 1 - src/librustdoc/clean/blanket_impl.rs | 7 ------- src/librustdoc/clean/inline.rs | 9 +-------- src/librustdoc/clean/mod.rs | 6 ------ src/librustdoc/clean/types.rs | 10 +++++++++- src/librustdoc/html/render/mod.rs | 6 ++++-- src/librustdoc/html/render/print_item.rs | 7 +++---- src/librustdoc/json/conversions.rs | 2 +- 8 files changed, 18 insertions(+), 30 deletions(-) diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index 92eb6214f79fe..dbdf2e4bbb0f9 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -118,7 +118,6 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { span: Span::dummy(), unsafety: hir::Unsafety::Normal, generics: new_generics, - provided_trait_methods: Default::default(), trait_: Some(trait_ref.clean(self.cx).get_trait_type().unwrap()), for_: ty.clean(self.cx), items: Vec::new(), diff --git a/src/librustdoc/clean/blanket_impl.rs b/src/librustdoc/clean/blanket_impl.rs index 3a14a1d23f2d4..f5c4034a61de2 100644 --- a/src/librustdoc/clean/blanket_impl.rs +++ b/src/librustdoc/clean/blanket_impl.rs @@ -92,12 +92,6 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> { } self.cx.generated_synthetics.insert((ty, trait_def_id)); - let provided_trait_methods = self - .cx - .tcx - .provided_trait_methods(trait_def_id) - .map(|meth| meth.ident.name) - .collect(); impls.push(Item { name: None, @@ -112,7 +106,6 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> { self.cx.tcx.explicit_predicates_of(impl_def_id), ) .clean(self.cx), - provided_trait_methods, // FIXME(eddyb) compute both `trait_` and `for_` from // the post-inference `trait_ref`, as it's more accurate. trait_: Some(trait_ref.clean(self.cx).get_trait_type().unwrap()), diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 3e89c1ac4c514..5dd9f3f1ebd34 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -414,16 +414,10 @@ crate fn build_impl( record_extern_trait(cx, trait_did); } - let provided = trait_ - .def_id() - .map(|did| tcx.provided_trait_methods(did).map(|meth| meth.ident.name).collect()) - .unwrap_or_default(); - - debug!("build_impl: impl {:?} for {:?}", trait_.def_id(), for_.def_id()); - let (merged_attrs, cfg) = merge_attrs(cx, parent_module.into(), load_attrs(cx, did), attrs); debug!("merged_attrs={:?}", merged_attrs); + debug!("build_impl: impl {:?} for {:?}", trait_.def_id(), for_.def_id()); ret.push(clean::Item::from_def_id_and_attrs_and_parts( did, None, @@ -431,7 +425,6 @@ crate fn build_impl( span: clean::types::rustc_span(did, cx.tcx), unsafety: hir::Unsafety::Normal, generics, - provided_trait_methods: provided, trait_, for_, items: trait_items, diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 6563f398edb6f..39ff18e8bf505 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1930,11 +1930,6 @@ fn clean_impl(impl_: &hir::Impl<'_>, hir_id: hir::HirId, cx: &mut DocContext<'_> build_deref_target_impls(cx, &items, &mut ret); } - let provided: FxHashSet = trait_ - .def_id() - .map(|did| tcx.provided_trait_methods(did).map(|meth| meth.ident.name).collect()) - .unwrap_or_default(); - let for_ = impl_.self_ty.clean(cx); let type_alias = for_.def_id().and_then(|did| match tcx.def_kind(did) { DefKind::TyAlias => Some(tcx.type_of(did).clean(cx)), @@ -1945,7 +1940,6 @@ fn clean_impl(impl_: &hir::Impl<'_>, hir_id: hir::HirId, cx: &mut DocContext<'_> span: types::rustc_span(tcx.hir().local_def_id(hir_id).to_def_id(), tcx), unsafety: impl_.unsafety, generics: impl_.generics.clean(cx), - provided_trait_methods: provided.clone(), trait_, for_, items, diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 5e47144588b3f..fa8eec847b251 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -2150,7 +2150,6 @@ crate struct Impl { crate span: Span, crate unsafety: hir::Unsafety, crate generics: Generics, - crate provided_trait_methods: FxHashSet, crate trait_: Option, crate for_: Type, crate items: Vec, @@ -2159,6 +2158,15 @@ crate struct Impl { crate blanket_impl: Option, } +impl Impl { + crate fn provided_trait_methods(&self, tcx: TyCtxt<'_>) -> FxHashSet { + self.trait_ + .def_id() + .map(|did| tcx.provided_trait_methods(did).map(|meth| meth.ident.name).collect()) + .unwrap_or_default() + } +} + #[derive(Clone, Debug)] crate struct Import { crate kind: ImportKind, diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 7de72d8198725..0a8026ef942b1 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -726,7 +726,8 @@ fn render_impls( .iter() .map(|i| { let did = i.trait_did_full(cache).unwrap(); - let assoc_link = AssocItemLink::GotoSource(did, &i.inner_impl().provided_trait_methods); + let provided_trait_methods = i.inner_impl().provided_trait_methods(tcx); + let assoc_link = AssocItemLink::GotoSource(did, &provided_trait_methods); let mut buffer = if w.is_for_html() { Buffer::html() } else { Buffer::new() }; render_impl( &mut buffer, @@ -1490,7 +1491,8 @@ fn render_impl( continue; } let did = i.trait_.as_ref().unwrap().def_id_full(cx.cache()).unwrap(); - let assoc_link = AssocItemLink::GotoSource(did, &i.provided_trait_methods); + let provided_methods = i.provided_trait_methods(cx.tcx()); + let assoc_link = AssocItemLink::GotoSource(did, &provided_methods); doc_impl_item( w, diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 1bb1db00e8825..1bf726dd31a46 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -669,10 +669,9 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra write_small_section_header(w, "foreign-impls", "Implementations on Foreign Types", ""); for implementor in foreign { - let assoc_link = AssocItemLink::GotoSource( - implementor.impl_item.def_id, - &implementor.inner_impl().provided_trait_methods, - ); + let provided_methods = implementor.inner_impl().provided_trait_methods(cx.tcx()); + let assoc_link = + AssocItemLink::GotoSource(implementor.impl_item.def_id, &provided_methods); render_impl( w, cx, diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs index 2d8c347c3c167..8ca6342462fc4 100644 --- a/src/librustdoc/json/conversions.rs +++ b/src/librustdoc/json/conversions.rs @@ -453,10 +453,10 @@ impl FromWithTcx for Trait { impl FromWithTcx for Impl { fn from_tcx(impl_: clean::Impl, tcx: TyCtxt<'_>) -> Self { + let provided_trait_methods = impl_.provided_trait_methods(tcx); let clean::Impl { unsafety, generics, - provided_trait_methods, trait_, for_, items,