-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
rustdoc: render doc(hidden) as a code attribute #151001
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
rustbot has assigned @GuillaumeGomez. Use |
719dca9 to
d88a903
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
b6e120a to
273d673
Compare
This comment has been minimized.
This comment has been minimized.
src/librustdoc/html/render/mod.rs
Outdated
| 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) | ||
| }; |
There was a problem hiding this comment.
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:
| 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).
There was a problem hiding this comment.
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)
};
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Move `#[doc(hidden)]` into the shared code-attribute renderer so it matches the styling and placement of other attributes in rustdoc HTML.
68fa0af to
3fb84f0
Compare
|
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. |
|
☔ The latest upstream changes (presumably #151232) made this pull request unmergeable. Please resolve the merge conflicts. |
Move
#[doc(hidden)]into the shared code-attribute renderer so it matches the styling and placement of other attributes in rustdoc HTML.Closes #132304