rustdoc: insert newlines between attributes
This commit is contained in:
parent
346aec9b02
commit
0979545330
2 changed files with 15 additions and 10 deletions
|
@ -42,6 +42,7 @@ use std::str;
|
||||||
use std::string::ToString;
|
use std::string::ToString;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use itertools::Itertools;
|
||||||
use rustc_ast_pretty::pprust;
|
use rustc_ast_pretty::pprust;
|
||||||
use rustc_data_structures::flock;
|
use rustc_data_structures::flock;
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||||
|
@ -3170,15 +3171,19 @@ const ALLOWED_ATTRIBUTES: &[Symbol] = &[
|
||||||
// bar: usize,
|
// bar: usize,
|
||||||
// }
|
// }
|
||||||
fn render_attributes(w: &mut Buffer, it: &clean::Item, top: bool) {
|
fn render_attributes(w: &mut Buffer, it: &clean::Item, top: bool) {
|
||||||
let mut attrs = String::new();
|
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");
|
||||||
|
|
||||||
for attr in &it.attrs.other_attrs {
|
|
||||||
if !ALLOWED_ATTRIBUTES.contains(&attr.name_or_empty()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
attrs.push_str(&pprust::attribute_to_string(&attr));
|
|
||||||
}
|
|
||||||
if !attrs.is_empty() {
|
if !attrs.is_empty() {
|
||||||
write!(
|
write!(
|
||||||
w,
|
w,
|
||||||
|
|
|
@ -8,8 +8,8 @@ pub extern "C" fn f() {}
|
||||||
#[export_name = "bar"]
|
#[export_name = "bar"]
|
||||||
pub extern "C" fn g() {}
|
pub extern "C" fn g() {}
|
||||||
|
|
||||||
// @has foo/enum.Foo.html '//*[@class="docblock attributes top-attr"]' '#[repr(i64)]'
|
// @matches foo/enum.Foo.html '//*[@class="docblock attributes top-attr"]' \
|
||||||
// @has foo/enum.Foo.html '//*[@class="docblock attributes top-attr"]' '#[must_use]'
|
// '(?m)\A#\[repr\(i64\)\]\n#\[must_use\]\Z'
|
||||||
#[repr(i64)]
|
#[repr(i64)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub enum Foo {
|
pub enum Foo {
|
||||||
|
|
Loading…
Add table
Reference in a new issue