-
-
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
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.
68fa0af to
3fb84f0
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
bff7096 to
713a0f2
Compare
|
Some changes occurred in src/tools/cargo cc @ehuss |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
713a0f2 to
7c54229
Compare
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
bddcba7 to
43477d6
Compare
This comment has been minimized.
This comment has been minimized.
|
Looks all good to me, thanks! Please squash your commits and then I'll r+ it. |
Move `#[doc(hidden)]` into the shared code-attribute renderer so it matches the styling and placement of other attributes in rustdoc HTML.
8ae2687 to
b4c4d95
Compare
|
@GuillaumeGomez Thanks! |
|
Thanks! @bors r+ rollup |
…uwer Rollup of 11 pull requests Successful merges: - #151001 (rustdoc: render doc(hidden) as a code attribute) - #151042 (fix fallback impl for select_unpredictable intrinsic) - #151220 (option: Use Option::map in Option::cloned) - #151260 (Handle unevaluated ConstKind in in_operand) - #151296 (MGCA: Fix incorrect pretty printing of valtree arrays) - #151423 (Move assert_matches to planned stable path) - #151441 (Fix ICE: Don't try to evaluate type_consts when eagerly collecting items) - #151465 (codegen: clarify some variable names around function calls) - #151468 (fix `f16` doctest FIXMEs) - #151469 (llvm: Tolerate dead_on_return attribute changes) - #151476 (Avoid `-> ()` in derived functions.) r? @ghost
…uwer Rollup of 11 pull requests Successful merges: - #151001 (rustdoc: render doc(hidden) as a code attribute) - #151042 (fix fallback impl for select_unpredictable intrinsic) - #151220 (option: Use Option::map in Option::cloned) - #151260 (Handle unevaluated ConstKind in in_operand) - #151296 (MGCA: Fix incorrect pretty printing of valtree arrays) - #151423 (Move assert_matches to planned stable path) - #151441 (Fix ICE: Don't try to evaluate type_consts when eagerly collecting items) - #151465 (codegen: clarify some variable names around function calls) - #151468 (fix `f16` doctest FIXMEs) - #151469 (llvm: Tolerate dead_on_return attribute changes) - #151476 (Avoid `-> ()` in derived functions.) r? @ghost
…uwer Rollup of 11 pull requests Successful merges: - #151001 (rustdoc: render doc(hidden) as a code attribute) - #151042 (fix fallback impl for select_unpredictable intrinsic) - #151220 (option: Use Option::map in Option::cloned) - #151260 (Handle unevaluated ConstKind in in_operand) - #151296 (MGCA: Fix incorrect pretty printing of valtree arrays) - #151423 (Move assert_matches to planned stable path) - #151441 (Fix ICE: Don't try to evaluate type_consts when eagerly collecting items) - #151465 (codegen: clarify some variable names around function calls) - #151468 (fix `f16` doctest FIXMEs) - #151469 (llvm: Tolerate dead_on_return attribute changes) - #151476 (Avoid `-> ()` in derived functions.) r? @ghost
Move
#[doc(hidden)]into the shared code-attribute renderer so it matches the styling and placement of other attributes in rustdoc HTML.Closes #132304