Skip to content

Commit b1a3f88

Browse files
Print more tags in rustdoc
1 parent 5fe733a commit b1a3f88

File tree

1 file changed

+40
-8
lines changed

1 file changed

+40
-8
lines changed

src/librustdoc/html/render.rs

+40-8
Original file line numberDiff line numberDiff line change
@@ -2492,16 +2492,48 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
24922492
Ok(())
24932493
}
24942494

2495+
fn attribute_without_value(s: &str) -> bool {
2496+
vec!("must_use", "no_mangle", "unsafe_destructor_blind_to_params").iter().any(|x| x == &s)
2497+
}
2498+
2499+
fn attribute_with_value(s: &str) -> bool {
2500+
vec!("export_name", "lang", "link_section", "must_use").iter().any(|x| x == &s)
2501+
}
2502+
2503+
fn attribute_with_values(s: &str) -> bool {
2504+
vec!("repr").iter().any(|x| x == &s)
2505+
}
2506+
2507+
fn render_attribute(attr: &clean::Attribute, recurse: bool) -> String {
2508+
match *attr {
2509+
clean::Word(ref s) if attribute_without_value(&*s) || recurse => {
2510+
format!("{}", s)
2511+
}
2512+
clean::NameValue(ref k, ref v) if attribute_with_value(&*k) => {
2513+
format!("{} = \"{}\"", k, v)
2514+
}
2515+
clean::List(ref k, ref values) if attribute_with_values(&*k) => {
2516+
let mut display = Vec::new();
2517+
2518+
for value in values {
2519+
let s = render_attribute(value, true);
2520+
if s.len() > 0 {
2521+
display.push(format!("{}", s));
2522+
}
2523+
}
2524+
format!("{}({})", k, display.join(", "))
2525+
}
2526+
_ => {
2527+
String::new()
2528+
}
2529+
}
2530+
}
2531+
24952532
fn render_attributes(w: &mut fmt::Formatter, it: &clean::Item) -> fmt::Result {
24962533
for attr in &it.attrs {
2497-
match *attr {
2498-
clean::Word(ref s) if *s == "must_use" => {
2499-
write!(w, "#[{}]\n", s)?;
2500-
}
2501-
clean::NameValue(ref k, ref v) if *k == "must_use" => {
2502-
write!(w, "#[{} = \"{}\"]\n", k, v)?;
2503-
}
2504-
_ => ()
2534+
let s = render_attribute(attr, false);
2535+
if s.len() > 0 {
2536+
write!(w, "#[{}]\n", s)?;
25052537
}
25062538
}
25072539
Ok(())

0 commit comments

Comments
 (0)