Skip to content

Conversation

@chojs23
Copy link
Contributor

@chojs23 chojs23 commented Jan 12, 2026

Move #[doc(hidden)] into the shared code-attribute renderer so it matches the styling and placement of other attributes in rustdoc HTML.

Closes #132304

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. labels Jan 12, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 12, 2026

r? @GuillaumeGomez

rustbot has assigned @GuillaumeGomez.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@JayanAXHF JayanAXHF added the A-rustdoc-ui Area: Rustdoc UI (generated HTML) label Jan 12, 2026
@chojs23 chojs23 force-pushed the fix/hidden-attr-docs branch from 719dca9 to d88a903 Compare January 13, 2026 11:01
@rustbot

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@chojs23 chojs23 force-pushed the fix/hidden-attr-docs branch from b6e120a to 273d673 Compare January 15, 2026 07:02
@rustbot

This comment has been minimized.

Comment on lines 2932 to 2939
let mut render_attr = |attr: &str| -> fmt::Result {
if !wrote_any {
if let Some(open_tag) = open_tag {
w.write_str(open_tag)?;
}
wrote_any = true;
}
render_code_attribute(prefix, attr, w)
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case open_tag is None, we could remove the need for the if check by creating two different closures:

Suggested change
let mut render_attr = |attr: &str| -> fmt::Result {
if !wrote_any {
if let Some(open_tag) = open_tag {
w.write_str(open_tag)?;
}
wrote_any = true;
}
render_code_attribute(prefix, attr, w)
};
let mut render_attr: FnMut(&str) -> fmt::Result = if let Some(open_tag) = open_tag {
|attr: &str| -> fmt::Result {
if !wrote_any {
w.write_str(open_tag)?;
wrote_any = true;
}
render_code_attribute(prefix, attr, w)
}
} else {
|attr: &str| -> fmt::Result {
render_code_attribute(prefix, attr, w)
}
};

Not sure it compiles but with a few tweaks it should (or use functions instead, it works too).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using two closures in an if expression does not compile because each closure has a unique anonymous type. So I need boxing or enum to make one concrete type which adds allocation or extra codes.

I used the empty string instead, WDYT?

    let open_tag = open_tag.unwrap_or("");
    let mut render_attr = |attr: &str| -> fmt::Result {
        if !wrote_any {
            w.write_str(open_tag)?;
            wrote_any = true;
        }
        render_code_attribute(prefix, attr, w)
    };

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is also that it adds more checks. Did you try with functions instead of closures?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm i tried it but using function does not reduce the checks, it only changes the style.

I moved the <dt><code> write into render_attributes_in_code_with_options by adding an open_tag parameter.

@chojs23 chojs23 force-pushed the fix/hidden-attr-docs branch from 68fa0af to 3fb84f0 Compare January 17, 2026 16:12
@rustbot
Copy link
Collaborator

rustbot commented Jan 17, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 17, 2026

☔ The latest upstream changes (presumably #151232) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-rustdoc-ui Area: Rustdoc UI (generated HTML) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rustdoc: Appearance of #[doc(hidden)] differs from all the other attributes

5 participants