Render full attributes in rustdoc
This commit is contained in:
parent
5a72ecf2c5
commit
621c42c163
2 changed files with 6 additions and 22 deletions
|
@ -3126,25 +3126,6 @@ fn item_enum(w: &mut Buffer, cx: &Context, it: &clean::Item, e: &clean::Enum) {
|
||||||
render_assoc_items(w, cx, it, it.def_id, AssocItemRender::All)
|
render_assoc_items(w, cx, it, it.def_id, AssocItemRender::All)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_attribute(attr: &ast::MetaItem) -> Option<String> {
|
|
||||||
let path = pprust::path_to_string(&attr.path);
|
|
||||||
|
|
||||||
if attr.is_word() {
|
|
||||||
Some(path)
|
|
||||||
} else if let Some(v) = attr.value_str() {
|
|
||||||
Some(format!("{} = {:?}", path, v))
|
|
||||||
} else if let Some(values) = attr.meta_item_list() {
|
|
||||||
let display: Vec<_> = values
|
|
||||||
.iter()
|
|
||||||
.filter_map(|attr| attr.meta_item().and_then(|mi| render_attribute(mi)))
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
if !display.is_empty() { Some(format!("{}({})", path, display.join(", "))) } else { None }
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const ATTRIBUTE_WHITELIST: &[Symbol] = &[
|
const ATTRIBUTE_WHITELIST: &[Symbol] = &[
|
||||||
sym::export_name,
|
sym::export_name,
|
||||||
sym::lang,
|
sym::lang,
|
||||||
|
@ -3170,9 +3151,8 @@ fn render_attributes(w: &mut Buffer, it: &clean::Item, top: bool) {
|
||||||
if !ATTRIBUTE_WHITELIST.contains(&attr.name_or_empty()) {
|
if !ATTRIBUTE_WHITELIST.contains(&attr.name_or_empty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if let Some(s) = render_attribute(&attr.meta().unwrap()) {
|
|
||||||
attrs.push_str(&format!("#[{}]\n", s));
|
attrs.push_str(&pprust::attribute_to_string(&attr));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if !attrs.is_empty() {
|
if !attrs.is_empty() {
|
||||||
write!(
|
write!(
|
||||||
|
|
|
@ -15,3 +15,7 @@ pub extern "C" fn g() {}
|
||||||
pub enum Foo {
|
pub enum Foo {
|
||||||
Bar,
|
Bar,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @has foo/struct.Repr.html '//*[@class="docblock attributes top-attr"]' '#[repr(C, align (8))]'
|
||||||
|
#[repr(C, align(8))]
|
||||||
|
pub struct Repr;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue