summary refs log tree commit diff
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2020-07-13 22:23:00 -0700
committerGitHub <noreply@github.com>2020-07-13 22:23:00 -0700
commiteb7fdb2e075e703af33da0b9b48335a39e3f9097 (patch)
treef41ce15bc05db0a9749eccfe91d6b8079f79260e
parentaa29e3de31a2af8cb96ecc87194f5884a1b64259 (diff)
parent0979545330689186dff27e22f539c1a06887981f (diff)
downloadrust-eb7fdb2e075e703af33da0b9b48335a39e3f9097.tar.gz
rust-eb7fdb2e075e703af33da0b9b48335a39e3f9097.zip
Rollup merge of #73852 - euclio:rustdoc-attr-newlines, r=GuillaumeGomez
rustdoc: insert newlines between attributes

Fixes #73205.
-rw-r--r--src/librustdoc/html/render.rs21
-rw-r--r--src/test/rustdoc/attributes.rs4
2 files changed, 15 insertions, 10 deletions
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs
index 8bba21a2e7a..301896fd2c1 100644
--- a/src/librustdoc/html/render.rs
+++ b/src/librustdoc/html/render.rs
@@ -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};
@@ -3170,15 +3171,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,
diff --git a/src/test/rustdoc/attributes.rs b/src/test/rustdoc/attributes.rs
index e9cd3514a07..54c5939f908 100644
--- a/src/test/rustdoc/attributes.rs
+++ b/src/test/rustdoc/attributes.rs
@@ -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 {