diff options
| author | bors <bors@rust-lang.org> | 2021-02-25 12:33:21 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-02-25 12:33:21 +0000 |
| commit | b36f77012dcbfbcf7d04e29fb9a10c8ead9b3ab1 (patch) | |
| tree | 69a4296a398bad6cf2ac4b5c825586336a79f45e | |
| parent | 89d32eb1ea44b3d739feb3c2a77adbba1e39b8e6 (diff) | |
| parent | cc0d53146363a4741530f16821efc308550a5021 (diff) | |
| download | rust-b36f77012dcbfbcf7d04e29fb9a10c8ead9b3ab1.tar.gz rust-b36f77012dcbfbcf7d04e29fb9a10c8ead9b3ab1.zip | |
Auto merge of #82265 - GuillaumeGomez:cleanup-attrs-twice, r=jyn514
Prevent to compute Item attributes twice I came across this case when working on another part of rustdoc. Not a game changer but a nice little improvement. cc `@camelid` r? `@jyn514`
| -rw-r--r-- | src/librustdoc/clean/inline.rs | 11 | ||||
| -rw-r--r-- | 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 f9c63186544..9cfa72132cb 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -414,7 +414,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 { @@ -428,11 +431,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 51bef344e67..7fc48cd5f0b 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -148,6 +148,22 @@ impl Item { 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<Symbol>, + kind: ItemKind, + attrs: Box<Attributes>, + cx: &mut DocContext<'_>, + ) -> Item { debug!("name={:?}, def_id={:?}", name, def_id); // `span_if_local()` lies about functions and only gives the span of the function signature @@ -164,7 +180,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), } } |
