Skip to content

Commit 04f570a

Browse files
Remove Clean trait implementation for ast::Attribute and cleanup Attributes::from_ast function by splitting it in two
1 parent 482153b commit 04f570a

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 {
@@ -2097,7 +2091,7 @@ fn clean_extern_crate<'tcx>(
20972091
// FIXME: using `from_def_id_and_kind` breaks `rustdoc/masked` for some reason
20982092
vec![Item {
20992093
name: Some(name),
2100-
attrs: Box::new(attrs.clean(cx)),
2094+
attrs: Box::new(Attributes::from_ast(attrs)),
21012095
item_id: crate_def_id.into(),
21022096
visibility: clean_visibility(ty_vis),
21032097
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;
@@ -477,7 +477,7 @@ impl Item {
477477
def_id,
478478
name,
479479
kind,
480-
Box::new(ast_attrs.clean(cx)),
480+
Box::new(Attributes::from_ast(ast_attrs)),
481481
cx,
482482
ast_attrs.cfg(cx.tcx, &cx.cache.hidden_cfg),
483483
)
@@ -1177,14 +1177,16 @@ impl Attributes {
11771177
false
11781178
}
11791179

1180-
pub(crate) fn from_ast(
1180+
pub(crate) fn from_ast(attrs: &[ast::Attribute]) -> Attributes {
1181+
Attributes::from_ast_iter(attrs.iter().map(|attr| (attr, None)), false)
1182+
}
1183+
1184+
pub(crate) fn from_ast_with_additional(
11811185
attrs: &[ast::Attribute],
1182-
additional_attrs: Option<(&[ast::Attribute], DefId)>,
1186+
(additional_attrs, def_id): (&[ast::Attribute], DefId),
11831187
) -> Attributes {
11841188
// Additional documentation should be shown before the original documentation.
1185-
let attrs1 = additional_attrs
1186-
.into_iter()
1187-
.flat_map(|(attrs, def_id)| attrs.iter().map(move |attr| (attr, Some(def_id))));
1189+
let attrs1 = additional_attrs.iter().map(|attr| (attr, Some(def_id)));
11881190
let attrs2 = attrs.iter().map(|attr| (attr, None));
11891191
Attributes::from_ast_iter(attrs1.chain(attrs2), false)
11901192
}

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)