Skip to content

Commit c906f8d

Browse files
Correctly encode doc attribute metadata
1 parent c4dc70e commit c906f8d

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,21 @@ pub struct DocAttribute {
549549
pub no_crate_inject: Option<Span>,
550550
}
551551

552+
impl DocAttribute {
553+
/// Returns `true` if contains `doc(inline)` and doesn't contain `doc(no_inline)`.
554+
pub fn is_inline(&self) -> bool {
555+
let mut is_no_inline = false;
556+
let mut is_inline = false;
557+
for (inline, _) in &self.inline {
558+
match inline {
559+
DocInline::Inline => is_inline = true,
560+
DocInline::NoInline => is_no_inline = true,
561+
}
562+
}
563+
is_inline && !is_no_inline
564+
}
565+
}
566+
552567
/// Represents parsed *built-in* inert attributes.
553568
///
554569
/// ## Overview

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ fn analyze_attr(attr: &hir::Attribute, state: &mut AnalyzeAttrState<'_>) -> bool
880880
} else if let hir::Attribute::Parsed(AttributeKind::Doc(d)) = attr {
881881
// If this is a `doc` attribute that doesn't have anything except maybe `inline` (as in
882882
// `#[doc(inline)]`), then we can remove it. It won't be inlinable in downstream crates.
883-
if d.inline.is_empty() {
883+
if !d.is_inline() {
884884
should_encode = true;
885885
if d.hidden.is_some() {
886886
state.is_doc_hidden = true;

0 commit comments

Comments
 (0)