Skip to content

Commit 621c42c

Browse files
committed
Render full attributes in rustdoc
1 parent 5a72ecf commit 621c42c

File tree

2 files changed

+6
-22
lines changed

2 files changed

+6
-22
lines changed

src/librustdoc/html/render.rs

+2-22
Original file line numberDiff line numberDiff line change
@@ -3126,25 +3126,6 @@ fn item_enum(w: &mut Buffer, cx: &Context, it: &clean::Item, e: &clean::Enum) {
31263126
render_assoc_items(w, cx, it, it.def_id, AssocItemRender::All)
31273127
}
31283128

3129-
fn render_attribute(attr: &ast::MetaItem) -> Option<String> {
3130-
let path = pprust::path_to_string(&attr.path);
3131-
3132-
if attr.is_word() {
3133-
Some(path)
3134-
} else if let Some(v) = attr.value_str() {
3135-
Some(format!("{} = {:?}", path, v))
3136-
} else if let Some(values) = attr.meta_item_list() {
3137-
let display: Vec<_> = values
3138-
.iter()
3139-
.filter_map(|attr| attr.meta_item().and_then(|mi| render_attribute(mi)))
3140-
.collect();
3141-
3142-
if !display.is_empty() { Some(format!("{}({})", path, display.join(", "))) } else { None }
3143-
} else {
3144-
None
3145-
}
3146-
}
3147-
31483129
const ATTRIBUTE_WHITELIST: &[Symbol] = &[
31493130
sym::export_name,
31503131
sym::lang,
@@ -3170,9 +3151,8 @@ fn render_attributes(w: &mut Buffer, it: &clean::Item, top: bool) {
31703151
if !ATTRIBUTE_WHITELIST.contains(&attr.name_or_empty()) {
31713152
continue;
31723153
}
3173-
if let Some(s) = render_attribute(&attr.meta().unwrap()) {
3174-
attrs.push_str(&format!("#[{}]\n", s));
3175-
}
3154+
3155+
attrs.push_str(&pprust::attribute_to_string(&attr));
31763156
}
31773157
if !attrs.is_empty() {
31783158
write!(

src/test/rustdoc/attributes.rs

+4
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ pub extern "C" fn g() {}
1515
pub enum Foo {
1616
Bar,
1717
}
18+
19+
// @has foo/struct.Repr.html '//*[@class="docblock attributes top-attr"]' '#[repr(C, align (8))]'
20+
#[repr(C, align(8))]
21+
pub struct Repr;

0 commit comments

Comments
 (0)