diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 6577315a2b710..b586fb86b334b 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -304,14 +304,14 @@ fn merge_attrs( both.extend_from_slice(old_attrs); ( if let Some(new_id) = parent_module { - Attributes::from_ast(old_attrs, Some((inner, new_id))) + Attributes::from_ast_with_additional(old_attrs, (inner, new_id)) } else { - Attributes::from_ast(&both, None) + Attributes::from_ast(&both) }, both.cfg(cx.tcx, &cx.cache.hidden_cfg), ) } else { - (old_attrs.clean(cx), old_attrs.cfg(cx.tcx, &cx.cache.hidden_cfg)) + (Attributes::from_ast(&old_attrs), old_attrs.cfg(cx.tcx, &cx.cache.hidden_cfg)) } } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index b6791bfab4ad4..d8515916b500d 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -121,12 +121,6 @@ impl<'tcx> Clean<'tcx, Item> for DocModule<'tcx> { } } -impl<'tcx> Clean<'tcx, Attributes> for [ast::Attribute] { - fn clean(&self, _cx: &mut DocContext<'_>) -> Attributes { - Attributes::from_ast(self, None) - } -} - impl<'tcx> Clean<'tcx, Option> for hir::GenericBound<'tcx> { fn clean(&self, cx: &mut DocContext<'tcx>) -> Option { Some(match *self { @@ -2096,7 +2090,7 @@ fn clean_extern_crate<'tcx>( // FIXME: using `from_def_id_and_kind` breaks `rustdoc/masked` for some reason vec![Item { name: Some(name), - attrs: Box::new(attrs.clean(cx)), + attrs: Box::new(Attributes::from_ast(attrs)), item_id: crate_def_id.into(), visibility: clean_visibility(ty_vis), kind: Box::new(ExternCrateItem { src: orig_name }), diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 1a46d077f1b05..0e6de842cc267 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -34,10 +34,10 @@ use rustc_target::spec::abi::Abi; use rustc_typeck::check::intrinsic::intrinsic_operation_unsafety; use crate::clean::cfg::Cfg; +use crate::clean::clean_visibility; use crate::clean::external_path; use crate::clean::inline::{self, print_inlined_const}; use crate::clean::utils::{is_literal_expr, print_const_expr, print_evaluated_const}; -use crate::clean::{clean_visibility, Clean}; use crate::core::DocContext; use crate::formats::cache::Cache; use crate::formats::item_type::ItemType; @@ -469,7 +469,7 @@ impl Item { def_id, name, kind, - Box::new(ast_attrs.clean(cx)), + Box::new(Attributes::from_ast(ast_attrs)), cx, ast_attrs.cfg(cx.tcx, &cx.cache.hidden_cfg), ) @@ -1161,14 +1161,16 @@ impl Attributes { false } - pub(crate) fn from_ast( + pub(crate) fn from_ast(attrs: &[ast::Attribute]) -> Attributes { + Attributes::from_ast_iter(attrs.iter().map(|attr| (attr, None)), false) + } + + pub(crate) fn from_ast_with_additional( attrs: &[ast::Attribute], - additional_attrs: Option<(&[ast::Attribute], DefId)>, + (additional_attrs, def_id): (&[ast::Attribute], DefId), ) -> Attributes { // Additional documentation should be shown before the original documentation. - let attrs1 = additional_attrs - .into_iter() - .flat_map(|(attrs, def_id)| attrs.iter().map(move |attr| (attr, Some(def_id)))); + let attrs1 = additional_attrs.iter().map(|attr| (attr, Some(def_id))); let attrs2 = attrs.iter().map(|attr| (attr, None)); Attributes::from_ast_iter(attrs1.chain(attrs2), false) } diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index 213f564ce2db5..35964e3ba38e4 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -1222,7 +1222,7 @@ impl<'a, 'hir, 'tcx> HirCollector<'a, 'hir, 'tcx> { // The collapse-docs pass won't combine sugared/raw doc attributes, or included files with // anything else, this will combine them for us. - let attrs = Attributes::from_ast(ast_attrs, None); + let attrs = Attributes::from_ast(ast_attrs); if let Some(doc) = attrs.collapsed_doc_value() { // Use the outermost invocation, so that doctest names come from where the docs were written. let span = ast_attrs diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 547d6696a431d..99cf4291927fb 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -345,7 +345,7 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items: clean::ImportItem(ref import) => { let (stab, stab_tags) = if let Some(import_def_id) = import.source.did { let ast_attrs = cx.tcx().get_attrs_unchecked(import_def_id); - let import_attrs = Box::new(clean::Attributes::from_ast(ast_attrs, None)); + let import_attrs = Box::new(clean::Attributes::from_ast(ast_attrs)); // Just need an item with the correct def_id and attrs let import_item = clean::Item {