Rollup merge of #149919 - GuillaumeGomez:doc-metadata-encoding, r=lqd
Correctly encode doc attribute metadata Follow-up of https://github.com/rust-lang/rust/pull/149645. The change I made was slightly wrong. [Originally](https://github.com/rust-lang/rust/pull/149645/changes#diff-72bf3e63aae0c5f24a5ce78a560db321ac6ead9df5ada3e33462a7f7d6218a55) the check was: ```rust if let Some(item_list) = attr.meta_item_list() { for item in item_list { if !item.has_name(sym::inline) { ``` So we were checking that there was no `doc(inline)` attribute. This PR should fix it. r? ``@lqd``
This commit is contained in:
commit
5fb00f2f28
2 changed files with 60 additions and 8 deletions
|
|
@ -530,7 +530,7 @@ pub struct CfgHideShow {
|
|||
pub values: ThinVec<CfgInfo>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, HashStable_Generic, Encodable, Decodable, PrintAttribute)]
|
||||
#[derive(Clone, Debug, Default, HashStable_Generic, Decodable, PrintAttribute)]
|
||||
pub struct DocAttribute {
|
||||
pub aliases: FxIndexMap<Symbol, Span>,
|
||||
pub hidden: Option<Span>,
|
||||
|
|
@ -566,6 +566,62 @@ pub struct DocAttribute {
|
|||
pub no_crate_inject: Option<Span>,
|
||||
}
|
||||
|
||||
impl<E: rustc_span::SpanEncoder> rustc_serialize::Encodable<E> for DocAttribute {
|
||||
fn encode(&self, encoder: &mut E) {
|
||||
let DocAttribute {
|
||||
aliases,
|
||||
hidden,
|
||||
inline,
|
||||
cfg,
|
||||
auto_cfg,
|
||||
auto_cfg_change,
|
||||
fake_variadic,
|
||||
keyword,
|
||||
attribute,
|
||||
masked,
|
||||
notable_trait,
|
||||
search_unbox,
|
||||
html_favicon_url,
|
||||
html_logo_url,
|
||||
html_playground_url,
|
||||
html_root_url,
|
||||
html_no_source,
|
||||
issue_tracker_base_url,
|
||||
rust_logo,
|
||||
test_attrs,
|
||||
no_crate_inject,
|
||||
} = self;
|
||||
rustc_serialize::Encodable::<E>::encode(aliases, encoder);
|
||||
rustc_serialize::Encodable::<E>::encode(hidden, encoder);
|
||||
|
||||
// FIXME: The `doc(inline)` attribute is never encoded, but is it actually the right thing
|
||||
// to do? I suspect the condition was broken, should maybe instead not encode anything if we
|
||||
// have `doc(no_inline)`.
|
||||
let inline: ThinVec<_> =
|
||||
inline.iter().filter(|(i, _)| *i != DocInline::Inline).cloned().collect();
|
||||
rustc_serialize::Encodable::<E>::encode(&inline, encoder);
|
||||
|
||||
rustc_serialize::Encodable::<E>::encode(cfg, encoder);
|
||||
rustc_serialize::Encodable::<E>::encode(auto_cfg, encoder);
|
||||
rustc_serialize::Encodable::<E>::encode(auto_cfg_change, encoder);
|
||||
rustc_serialize::Encodable::<E>::encode(fake_variadic, encoder);
|
||||
rustc_serialize::Encodable::<E>::encode(keyword, encoder);
|
||||
rustc_serialize::Encodable::<E>::encode(attribute, encoder);
|
||||
rustc_serialize::Encodable::<E>::encode(masked, encoder);
|
||||
rustc_serialize::Encodable::<E>::encode(notable_trait, encoder);
|
||||
rustc_serialize::Encodable::<E>::encode(search_unbox, encoder);
|
||||
rustc_serialize::Encodable::<E>::encode(html_favicon_url, encoder);
|
||||
rustc_serialize::Encodable::<E>::encode(html_logo_url, encoder);
|
||||
rustc_serialize::Encodable::<E>::encode(html_playground_url, encoder);
|
||||
rustc_serialize::Encodable::<E>::encode(html_root_url, encoder);
|
||||
rustc_serialize::Encodable::<E>::encode(html_no_source, encoder);
|
||||
rustc_serialize::Encodable::<E>::encode(issue_tracker_base_url, encoder);
|
||||
rustc_serialize::Encodable::<E>::encode(rust_logo, encoder);
|
||||
rustc_serialize::Encodable::<E>::encode(test_attrs, encoder);
|
||||
rustc_serialize::Encodable::<E>::encode(no_crate_inject, encoder);
|
||||
}
|
||||
}
|
||||
|
||||
/// Represents parsed *built-in* inert attributes.
|
||||
///
|
||||
/// ## Overview
|
||||
|
|
|
|||
|
|
@ -879,13 +879,9 @@ fn analyze_attr(attr: &hir::Attribute, state: &mut AnalyzeAttrState<'_>) -> bool
|
|||
should_encode = true;
|
||||
}
|
||||
} else if let hir::Attribute::Parsed(AttributeKind::Doc(d)) = attr {
|
||||
// If this is a `doc` attribute that doesn't have anything except maybe `inline` (as in
|
||||
// `#[doc(inline)]`), then we can remove it. It won't be inlinable in downstream crates.
|
||||
if d.inline.is_empty() {
|
||||
should_encode = true;
|
||||
if d.hidden.is_some() {
|
||||
state.is_doc_hidden = true;
|
||||
}
|
||||
should_encode = true;
|
||||
if d.hidden.is_some() {
|
||||
state.is_doc_hidden = true;
|
||||
}
|
||||
} else if let &[sym::diagnostic, seg] = &*attr.path() {
|
||||
should_encode = rustc_feature::is_stable_diagnostic_attribute(seg, state.features);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue