diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2016-11-06 20:06:01 +0100 |
|---|---|---|
| committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2016-11-06 20:06:04 +0100 |
| commit | a96247bcac385671757034bd928c13097fd2ce76 (patch) | |
| tree | fcc3f30bb0f490f9d848ca88e10874847aadb5f3 | |
| parent | b1a3f88e5501521548ddea4e918d55cc1c777187 (diff) | |
| download | rust-a96247bcac385671757034bd928c13097fd2ce76.tar.gz rust-a96247bcac385671757034bd928c13097fd2ce76.zip | |
Set possibility to hide attributes
| -rw-r--r-- | src/librustdoc/html/render.rs | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index e3efcc5c2f9..aa1fd63082f 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -2493,24 +2493,24 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, } fn attribute_without_value(s: &str) -> bool { - vec!("must_use", "no_mangle", "unsafe_destructor_blind_to_params").iter().any(|x| x == &s) + ["must_use", "no_mangle", "unsafe_destructor_blind_to_params"].iter().any(|x| x == &s) } fn attribute_with_value(s: &str) -> bool { - vec!("export_name", "lang", "link_section", "must_use").iter().any(|x| x == &s) + ["export_name", "lang", "link_section", "must_use"].iter().any(|x| x == &s) } fn attribute_with_values(s: &str) -> bool { - vec!("repr").iter().any(|x| x == &s) + ["repr"].iter().any(|x| x == &s) } -fn render_attribute(attr: &clean::Attribute, recurse: bool) -> String { +fn render_attribute(attr: &clean::Attribute, recurse: bool) -> Option<String> { match *attr { clean::Word(ref s) if attribute_without_value(&*s) || recurse => { - format!("{}", s) + Some(format!("{}", s)) } clean::NameValue(ref k, ref v) if attribute_with_value(&*k) => { - format!("{} = \"{}\"", k, v) + Some(format!("{} = \"{}\"", k, v)) } clean::List(ref k, ref values) if attribute_with_values(&*k) => { let mut display = Vec::new(); @@ -2521,21 +2521,25 @@ fn render_attribute(attr: &clean::Attribute, recurse: bool) -> String { display.push(format!("{}", s)); } } - format!("{}({})", k, display.join(", ")) + Some(format!("{}({})", k, display.join(", "))) } _ => { - String::new() + None } } } fn render_attributes(w: &mut fmt::Formatter, it: &clean::Item) -> fmt::Result { + let mut attrs = String::new(); + for attr in &it.attrs { - let s = render_attribute(attr, false); - if s.len() > 0 { - write!(w, "#[{}]\n", s)?; + if let Some(s) = render_attribute(attr, false) { + attrs.push_str(&format!("#[{}]\n", s)); } } + if attrs.len() > 0 { + write!(w, "<div class=\"docblock\">{}</div>", &attrs)?; + } Ok(()) } |
