Skip to content

Commit e20b599

Browse files
authored
Rollup merge of rust-lang#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 rust-lang#99638. r? `@notriddle`
2 parents a0991b8 + 04f570a commit e20b599

File tree

5 files changed

+15
-19
lines changed

5 files changed

+15
-19
lines changed

src/librustdoc/clean/inline.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -304,14 +304,14 @@ fn merge_attrs(
304304
both.extend_from_slice(old_attrs);
305305
(
306306
if let Some(new_id) = parent_module {
307-
Attributes::from_ast(old_attrs, Some((inner, new_id)))
307+
Attributes::from_ast_with_additional(old_attrs, (inner, new_id))
308308
} else {
309-
Attributes::from_ast(&both, None)
309+
Attributes::from_ast(&both)
310310
},
311311
both.cfg(cx.tcx, &cx.cache.hidden_cfg),
312312
)
313313
} else {
314-
(old_attrs.clean(cx), old_attrs.cfg(cx.tcx, &cx.cache.hidden_cfg))
314+
(Attributes::from_ast(&old_attrs), old_attrs.cfg(cx.tcx, &cx.cache.hidden_cfg))
315315
}
316316
}
317317

src/librustdoc/clean/mod.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,6 @@ impl<'tcx> Clean<'tcx, Item> for DocModule<'tcx> {
121121
}
122122
}
123123

124-
impl<'tcx> Clean<'tcx, Attributes> for [ast::Attribute] {
125-
fn clean(&self, _cx: &mut DocContext<'_>) -> Attributes {
126-
Attributes::from_ast(self, None)
127-
}
128-
}
129-
130124
impl<'tcx> Clean<'tcx, Option<GenericBound>> for hir::GenericBound<'tcx> {
131125
fn clean(&self, cx: &mut DocContext<'tcx>) -> Option<GenericBound> {
132126
Some(match *self {
@@ -2096,7 +2090,7 @@ fn clean_extern_crate<'tcx>(
20962090
// FIXME: using `from_def_id_and_kind` breaks `rustdoc/masked` for some reason
20972091
vec![Item {
20982092
name: Some(name),
2099-
attrs: Box::new(attrs.clean(cx)),
2093+
attrs: Box::new(Attributes::from_ast(attrs)),
21002094
item_id: crate_def_id.into(),
21012095
visibility: clean_visibility(ty_vis),
21022096
kind: Box::new(ExternCrateItem { src: orig_name }),

src/librustdoc/clean/types.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ use rustc_target::spec::abi::Abi;
3434
use rustc_typeck::check::intrinsic::intrinsic_operation_unsafety;
3535

3636
use crate::clean::cfg::Cfg;
37+
use crate::clean::clean_visibility;
3738
use crate::clean::external_path;
3839
use crate::clean::inline::{self, print_inlined_const};
3940
use crate::clean::utils::{is_literal_expr, print_const_expr, print_evaluated_const};
40-
use crate::clean::{clean_visibility, Clean};
4141
use crate::core::DocContext;
4242
use crate::formats::cache::Cache;
4343
use crate::formats::item_type::ItemType;
@@ -469,7 +469,7 @@ impl Item {
469469
def_id,
470470
name,
471471
kind,
472-
Box::new(ast_attrs.clean(cx)),
472+
Box::new(Attributes::from_ast(ast_attrs)),
473473
cx,
474474
ast_attrs.cfg(cx.tcx, &cx.cache.hidden_cfg),
475475
)
@@ -1161,14 +1161,16 @@ impl Attributes {
11611161
false
11621162
}
11631163

1164-
pub(crate) fn from_ast(
1164+
pub(crate) fn from_ast(attrs: &[ast::Attribute]) -> Attributes {
1165+
Attributes::from_ast_iter(attrs.iter().map(|attr| (attr, None)), false)
1166+
}
1167+
1168+
pub(crate) fn from_ast_with_additional(
11651169
attrs: &[ast::Attribute],
1166-
additional_attrs: Option<(&[ast::Attribute], DefId)>,
1170+
(additional_attrs, def_id): (&[ast::Attribute], DefId),
11671171
) -> Attributes {
11681172
// Additional documentation should be shown before the original documentation.
1169-
let attrs1 = additional_attrs
1170-
.into_iter()
1171-
.flat_map(|(attrs, def_id)| attrs.iter().map(move |attr| (attr, Some(def_id))));
1173+
let attrs1 = additional_attrs.iter().map(|attr| (attr, Some(def_id)));
11721174
let attrs2 = attrs.iter().map(|attr| (attr, None));
11731175
Attributes::from_ast_iter(attrs1.chain(attrs2), false)
11741176
}

src/librustdoc/doctest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1222,7 +1222,7 @@ impl<'a, 'hir, 'tcx> HirCollector<'a, 'hir, 'tcx> {
12221222

12231223
// The collapse-docs pass won't combine sugared/raw doc attributes, or included files with
12241224
// anything else, this will combine them for us.
1225-
let attrs = Attributes::from_ast(ast_attrs, None);
1225+
let attrs = Attributes::from_ast(ast_attrs);
12261226
if let Some(doc) = attrs.collapsed_doc_value() {
12271227
// Use the outermost invocation, so that doctest names come from where the docs were written.
12281228
let span = ast_attrs

src/librustdoc/html/render/print_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items:
345345
clean::ImportItem(ref import) => {
346346
let (stab, stab_tags) = if let Some(import_def_id) = import.source.did {
347347
let ast_attrs = cx.tcx().get_attrs_unchecked(import_def_id);
348-
let import_attrs = Box::new(clean::Attributes::from_ast(ast_attrs, None));
348+
let import_attrs = Box::new(clean::Attributes::from_ast(ast_attrs));
349349

350350
// Just need an item with the correct def_id and attrs
351351
let import_item = clean::Item {

0 commit comments

Comments
 (0)