From f24eac5e644a715c8a290f8ef8eb4883a7ddad3b Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 18 Feb 2021 17:29:44 +0100 Subject: [PATCH 1/2] Prevent to compute Item attributes twice --- src/librustdoc/clean/inline.rs | 11 ++++++----- src/librustdoc/clean/types.rs | 18 +++++++++++++++++- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index ea75d1614bd..27df320c19c 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -416,7 +416,10 @@ crate fn build_impl( debug!("build_impl: impl {:?} for {:?}", trait_.def_id(), for_.def_id()); - let mut item = clean::Item::from_def_id_and_parts( + let attrs = box merge_attrs(cx, parent_module.into(), load_attrs(cx, did), attrs); + debug!("merged_attrs={:?}", attrs); + + ret.push(clean::Item::from_def_id_and_attrs_and_parts( did, None, clean::ImplItem(clean::Impl { @@ -430,11 +433,9 @@ crate fn build_impl( synthetic: false, blanket_impl: None, }), + attrs, cx, - ); - item.attrs = box merge_attrs(cx, parent_module.into(), load_attrs(cx, did), attrs); - debug!("merged_attrs={:?}", item.attrs); - ret.push(item); + )); } fn build_module( diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 9a2319f6e37..202449748c4 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -140,6 +140,22 @@ impl Item { name: Option, kind: ItemKind, cx: &mut DocContext<'_>, + ) -> Item { + Self::from_def_id_and_attrs_and_parts( + def_id, + name, + kind, + box cx.tcx.get_attrs(def_id).clean(cx), + cx, + ) + } + + pub fn from_def_id_and_attrs_and_parts( + def_id: DefId, + name: Option, + kind: ItemKind, + attrs: Box, + cx: &DocContext<'_>, ) -> Item { debug!("name={:?}, def_id={:?}", name, def_id); @@ -157,7 +173,7 @@ impl Item { kind: box kind, name, source: source.clean(cx), - attrs: box cx.tcx.get_attrs(def_id).clean(cx), + attrs, visibility: cx.tcx.visibility(def_id).clean(cx), } } From cc0d53146363a4741530f16821efc308550a5021 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 24 Feb 2021 10:16:33 +0100 Subject: [PATCH 2/2] Make DocContext &mut for clean --- src/librustdoc/clean/types.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 202449748c4..e898727d463 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -155,7 +155,7 @@ impl Item { name: Option, kind: ItemKind, attrs: Box, - cx: &DocContext<'_>, + cx: &mut DocContext<'_>, ) -> Item { debug!("name={:?}, def_id={:?}", name, def_id);