Skip to content

Commit

Permalink
Rollup merge of rust-lang#73852 - euclio:rustdoc-attr-newlines, r=Gui…
Browse files Browse the repository at this point in the history
…llaumeGomez

rustdoc: insert newlines between attributes

Fixes rust-lang#73205.
  • Loading branch information
Manishearth committed Jul 14, 2020
2 parents 8ad6a5c + 0979545 commit ce7a1e0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
21 changes: 13 additions & 8 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ use std::str;
use std::string::ToString;
use std::sync::Arc;

use itertools::Itertools;
use rustc_ast_pretty::pprust;
use rustc_data_structures::flock;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
Expand Down Expand Up @@ -3206,15 +3207,19 @@ const ALLOWED_ATTRIBUTES: &[Symbol] = &[
// bar: usize,
// }
fn render_attributes(w: &mut Buffer, it: &clean::Item, top: bool) {
let mut attrs = String::new();

for attr in &it.attrs.other_attrs {
if !ALLOWED_ATTRIBUTES.contains(&attr.name_or_empty()) {
continue;
}
let attrs = it
.attrs
.other_attrs
.iter()
.filter_map(|attr| {
if ALLOWED_ATTRIBUTES.contains(&attr.name_or_empty()) {
Some(pprust::attribute_to_string(&attr))
} else {
None
}
})
.join("\n");

attrs.push_str(&pprust::attribute_to_string(&attr));
}
if !attrs.is_empty() {
write!(
w,
Expand Down
4 changes: 2 additions & 2 deletions src/test/rustdoc/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ pub extern "C" fn f() {}
#[export_name = "bar"]
pub extern "C" fn g() {}

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

0 comments on commit ce7a1e0

Please sign in to comment.