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
5 changed files with 15 additions and 19 deletions
|
@ -304,14 +304,14 @@ fn merge_attrs(
|
||||||
both.extend_from_slice(old_attrs);
|
both.extend_from_slice(old_attrs);
|
||||||
(
|
(
|
||||||
if let Some(new_id) = parent_module {
|
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 {
|
} else {
|
||||||
Attributes::from_ast(&both, None)
|
Attributes::from_ast(&both)
|
||||||
},
|
},
|
||||||
both.cfg(cx.tcx, &cx.cache.hidden_cfg),
|
both.cfg(cx.tcx, &cx.cache.hidden_cfg),
|
||||||
)
|
)
|
||||||
} else {
|
} 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> {
|
impl<'tcx> Clean<'tcx, Option<GenericBound>> for hir::GenericBound<'tcx> {
|
||||||
fn clean(&self, cx: &mut DocContext<'tcx>) -> Option<GenericBound> {
|
fn clean(&self, cx: &mut DocContext<'tcx>) -> Option<GenericBound> {
|
||||||
Some(match *self {
|
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
|
// FIXME: using `from_def_id_and_kind` breaks `rustdoc/masked` for some reason
|
||||||
vec![Item {
|
vec![Item {
|
||||||
name: Some(name),
|
name: Some(name),
|
||||||
attrs: Box::new(attrs.clean(cx)),
|
attrs: Box::new(Attributes::from_ast(attrs)),
|
||||||
item_id: crate_def_id.into(),
|
item_id: crate_def_id.into(),
|
||||||
visibility: clean_visibility(ty_vis),
|
visibility: clean_visibility(ty_vis),
|
||||||
kind: Box::new(ExternCrateItem { src: orig_name }),
|
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 rustc_typeck::check::intrinsic::intrinsic_operation_unsafety;
|
||||||
|
|
||||||
use crate::clean::cfg::Cfg;
|
use crate::clean::cfg::Cfg;
|
||||||
|
use crate::clean::clean_visibility;
|
||||||
use crate::clean::external_path;
|
use crate::clean::external_path;
|
||||||
use crate::clean::inline::{self, print_inlined_const};
|
use crate::clean::inline::{self, print_inlined_const};
|
||||||
use crate::clean::utils::{is_literal_expr, print_const_expr, print_evaluated_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::core::DocContext;
|
||||||
use crate::formats::cache::Cache;
|
use crate::formats::cache::Cache;
|
||||||
use crate::formats::item_type::ItemType;
|
use crate::formats::item_type::ItemType;
|
||||||
|
@ -469,7 +469,7 @@ impl Item {
|
||||||
def_id,
|
def_id,
|
||||||
name,
|
name,
|
||||||
kind,
|
kind,
|
||||||
Box::new(ast_attrs.clean(cx)),
|
Box::new(Attributes::from_ast(ast_attrs)),
|
||||||
cx,
|
cx,
|
||||||
ast_attrs.cfg(cx.tcx, &cx.cache.hidden_cfg),
|
ast_attrs.cfg(cx.tcx, &cx.cache.hidden_cfg),
|
||||||
)
|
)
|
||||||
|
@ -1161,14 +1161,16 @@ impl Attributes {
|
||||||
false
|
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],
|
attrs: &[ast::Attribute],
|
||||||
additional_attrs: Option<(&[ast::Attribute], DefId)>,
|
(additional_attrs, def_id): (&[ast::Attribute], DefId),
|
||||||
) -> Attributes {
|
) -> Attributes {
|
||||||
// Additional documentation should be shown before the original documentation.
|
// Additional documentation should be shown before the original documentation.
|
||||||
let attrs1 = additional_attrs
|
let attrs1 = additional_attrs.iter().map(|attr| (attr, Some(def_id)));
|
||||||
.into_iter()
|
|
||||||
.flat_map(|(attrs, def_id)| attrs.iter().map(move |attr| (attr, Some(def_id))));
|
|
||||||
let attrs2 = attrs.iter().map(|attr| (attr, None));
|
let attrs2 = attrs.iter().map(|attr| (attr, None));
|
||||||
Attributes::from_ast_iter(attrs1.chain(attrs2), false)
|
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
|
// The collapse-docs pass won't combine sugared/raw doc attributes, or included files with
|
||||||
// anything else, this will combine them for us.
|
// 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() {
|
if let Some(doc) = attrs.collapsed_doc_value() {
|
||||||
// Use the outermost invocation, so that doctest names come from where the docs were written.
|
// Use the outermost invocation, so that doctest names come from where the docs were written.
|
||||||
let span = ast_attrs
|
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) => {
|
clean::ImportItem(ref import) => {
|
||||||
let (stab, stab_tags) = if let Some(import_def_id) = import.source.did {
|
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 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
|
// Just need an item with the correct def_id and attrs
|
||||||
let import_item = clean::Item {
|
let import_item = clean::Item {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue