diff options
| author | Dylan DPC <dylan.dpc@gmail.com> | 2020-03-16 01:30:24 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-03-16 01:30:24 +0100 |
| commit | e5de0b13febfe9a9a3f0dc07489a7d19d5525e3b (patch) | |
| tree | 22a31c8d13c99431db2a81b9d059608a8cbfdf67 | |
| parent | 45ebd5808afd3df7ba842797c0fcd4447ddf30fb (diff) | |
| parent | c599ec4460f17c43f5df1d4df269f3811ece4bd7 (diff) | |
| download | rust-e5de0b13febfe9a9a3f0dc07489a7d19d5525e3b.tar.gz rust-e5de0b13febfe9a9a3f0dc07489a7d19d5525e3b.zip | |
Rollup merge of #69686 - varkor:rustdoc-attributes, r=GuillaumeGomez
Use `pprust` to print attributes in rustdoc Fixes https://github.com/rust-lang/rust/issues/69559. I'm not sure what the original motivation was for the `render_attribute`, so I may be missing something, but replacing it with `pprust::attribute_to_string` seems to give the intended output (modulo some spacing idiosyncrasies). r? @GuillaumeGomez
| -rw-r--r-- | src/librustdoc/html/render.rs | 26 | ||||
| -rw-r--r-- | src/test/rustdoc/attributes.rs | 4 |
2 files changed, 7 insertions, 23 deletions
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index ceae42cc598..b3d70475bf3 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -44,7 +44,6 @@ use std::sync::Arc; use rustc::middle::privacy::AccessLevels; use rustc::middle::stability; -use rustc_ast::ast; use rustc_ast_pretty::pprust; use rustc_data_structures::flock; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; @@ -3126,25 +3125,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) } -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] = &[ sym::export_name, sym::lang, @@ -3170,9 +3150,9 @@ fn render_attributes(w: &mut Buffer, it: &clean::Item, top: bool) { if !ATTRIBUTE_WHITELIST.contains(&attr.name_or_empty()) { continue; } - if let Some(s) = render_attribute(&attr.meta().unwrap()) { - attrs.push_str(&format!("#[{}]\n", s)); - } + + // FIXME: this currently renders too many spaces as in: `#[repr(C, align (8))]`. + attrs.push_str(&pprust::attribute_to_string(&attr)); } if !attrs.is_empty() { write!( diff --git a/src/test/rustdoc/attributes.rs b/src/test/rustdoc/attributes.rs index 6ecdad3ec00..d5772e183bc 100644 --- a/src/test/rustdoc/attributes.rs +++ b/src/test/rustdoc/attributes.rs @@ -15,3 +15,7 @@ pub extern "C" fn g() {} pub enum Foo { Bar, } + +// @has foo/struct.Repr.html '//*[@class="docblock attributes top-attr"]' '#[repr(C, align (8))]' +#[repr(C, align(8))] +pub struct Repr; |
