Skip to content

Commit 2481ade

Browse files
authored
Rollup merge of rust-lang#73852 - euclio:rustdoc-attr-newlines, r=GuillaumeGomez
rustdoc: insert newlines between attributes Fixes rust-lang#73205.
2 parents 70ea364 + 0979545 commit 2481ade

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

src/librustdoc/html/render.rs

+13-8
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ use std::str;
4242
use std::string::ToString;
4343
use std::sync::Arc;
4444

45+
use itertools::Itertools;
4546
use rustc_ast_pretty::pprust;
4647
use rustc_data_structures::flock;
4748
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
@@ -3206,15 +3207,19 @@ const ALLOWED_ATTRIBUTES: &[Symbol] = &[
32063207
// bar: usize,
32073208
// }
32083209
fn render_attributes(w: &mut Buffer, it: &clean::Item, top: bool) {
3209-
let mut attrs = String::new();
3210-
3211-
for attr in &it.attrs.other_attrs {
3212-
if !ALLOWED_ATTRIBUTES.contains(&attr.name_or_empty()) {
3213-
continue;
3214-
}
3210+
let attrs = it
3211+
.attrs
3212+
.other_attrs
3213+
.iter()
3214+
.filter_map(|attr| {
3215+
if ALLOWED_ATTRIBUTES.contains(&attr.name_or_empty()) {
3216+
Some(pprust::attribute_to_string(&attr))
3217+
} else {
3218+
None
3219+
}
3220+
})
3221+
.join("\n");
32153222

3216-
attrs.push_str(&pprust::attribute_to_string(&attr));
3217-
}
32183223
if !attrs.is_empty() {
32193224
write!(
32203225
w,

src/test/rustdoc/attributes.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ pub extern "C" fn f() {}
88
#[export_name = "bar"]
99
pub extern "C" fn g() {}
1010

11-
// @has foo/enum.Foo.html '//*[@class="docblock attributes top-attr"]' '#[repr(i64)]'
12-
// @has foo/enum.Foo.html '//*[@class="docblock attributes top-attr"]' '#[must_use]'
11+
// @matches foo/enum.Foo.html '//*[@class="docblock attributes top-attr"]' \
12+
// '(?m)\A#\[repr\(i64\)\]\n#\[must_use\]\Z'
1313
#[repr(i64)]
1414
#[must_use]
1515
pub enum Foo {

0 commit comments

Comments
 (0)