Skip to content

Commit a96247b

Browse files
Set possibility to hide attributes
1 parent b1a3f88 commit a96247b

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/librustdoc/html/render.rs

+15-11
Original file line numberDiff line numberDiff line change
@@ -2493,24 +2493,24 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
24932493
}
24942494

24952495
fn attribute_without_value(s: &str) -> bool {
2496-
vec!("must_use", "no_mangle", "unsafe_destructor_blind_to_params").iter().any(|x| x == &s)
2496+
["must_use", "no_mangle", "unsafe_destructor_blind_to_params"].iter().any(|x| x == &s)
24972497
}
24982498

24992499
fn attribute_with_value(s: &str) -> bool {
2500-
vec!("export_name", "lang", "link_section", "must_use").iter().any(|x| x == &s)
2500+
["export_name", "lang", "link_section", "must_use"].iter().any(|x| x == &s)
25012501
}
25022502

25032503
fn attribute_with_values(s: &str) -> bool {
2504-
vec!("repr").iter().any(|x| x == &s)
2504+
["repr"].iter().any(|x| x == &s)
25052505
}
25062506

2507-
fn render_attribute(attr: &clean::Attribute, recurse: bool) -> String {
2507+
fn render_attribute(attr: &clean::Attribute, recurse: bool) -> Option<String> {
25082508
match *attr {
25092509
clean::Word(ref s) if attribute_without_value(&*s) || recurse => {
2510-
format!("{}", s)
2510+
Some(format!("{}", s))
25112511
}
25122512
clean::NameValue(ref k, ref v) if attribute_with_value(&*k) => {
2513-
format!("{} = \"{}\"", k, v)
2513+
Some(format!("{} = \"{}\"", k, v))
25142514
}
25152515
clean::List(ref k, ref values) if attribute_with_values(&*k) => {
25162516
let mut display = Vec::new();
@@ -2521,21 +2521,25 @@ fn render_attribute(attr: &clean::Attribute, recurse: bool) -> String {
25212521
display.push(format!("{}", s));
25222522
}
25232523
}
2524-
format!("{}({})", k, display.join(", "))
2524+
Some(format!("{}({})", k, display.join(", ")))
25252525
}
25262526
_ => {
2527-
String::new()
2527+
None
25282528
}
25292529
}
25302530
}
25312531

25322532
fn render_attributes(w: &mut fmt::Formatter, it: &clean::Item) -> fmt::Result {
2533+
let mut attrs = String::new();
2534+
25332535
for attr in &it.attrs {
2534-
let s = render_attribute(attr, false);
2535-
if s.len() > 0 {
2536-
write!(w, "#[{}]\n", s)?;
2536+
if let Some(s) = render_attribute(attr, false) {
2537+
attrs.push_str(&format!("#[{}]\n", s));
25372538
}
25382539
}
2540+
if attrs.len() > 0 {
2541+
write!(w, "<div class=\"docblock\">{}</div>", &attrs)?;
2542+
}
25392543
Ok(())
25402544
}
25412545

0 commit comments

Comments
 (0)