Rollup merge of #100005 - GuillaumeGomez:cleanup-ast-attr-clean, r=notriddle
Remove Clean trait for ast::Attribute and improve Attributes::from_ast I prefer to keep this commit on its own for this PR because I'm changing a bit more things than expected originally: I split `Attributes::from_ast` into two because there is only one location making use of its second parameter. Follow-up of https://github.com/rust-lang/rust/pull/99638. r? `@notriddle`
This commit is contained in:
commit
e20b59977b
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<GenericBound>> for hir::GenericBound<'tcx> {
|
||||
fn clean(&self, cx: &mut DocContext<'tcx>) -> Option<GenericBound> {
|
||||
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 }),
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user