-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Valid underscores in hex/octal/binary literal docs #84017
Conversation
r? @ollie27 (rust-highfive has picked a reviewer for you, use r? to override) |
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.
Looks good to me. But I wonder why the tests
couldn't be kept in the same file?
@pickfire All of the other Rustdoc tests are also in their own |
r? @jyn514 |
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.
@pickfire All of the other Rustdoc tests are also in their own
tests
module, so I added these tests using the same convention.
Yup, and this also avoids recompiling the main rustdoc crate when you only change a test.
This looks good to me, just a couple nits on the implementation :)
@@ -331,11 +334,27 @@ crate fn print_evaluated_const(tcx: TyCtxt<'_>, def_id: DefId) -> Option<String> | |||
|
|||
fn format_integer_with_underscore_sep(num: &str) -> String { | |||
let num_chars: Vec<_> = num.chars().collect(); |
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.
A good follow-up would be to remove num_chars
altogether - num
is always ascii so you should be able to just use bytes directly. Doesn't need to be in this PR though :)
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Do you mind squashing the commits into one? There are instructions at https://rustc-dev-guide.rust-lang.org/git.html#advanced-rebasing, or if it's a pain bors can do it automatically (it will just show the PR as closed instead of merged because github doesn't recognize it). |
Currently hex/octal/binary literals with computed values are displayed like `0_xff_fff_fffu32`, which is invalid since underscores can't be in the middle of integer prefixes. This properly formats prefixed integers.
5be9752
to
f84b4c5
Compare
@bors r+ Thanks for working on this! |
📌 Commit f84b4c5 has been approved by |
🌲 The tree is currently closed for pull requests below priority 99. This pull request will be tested once the tree is reopened. |
…=jyn514 Valid underscores in hex/octal/binary literal docs Currently hex/octal/binary literals with computed values are displayed like `0_xff_fff_fffu32`, which is invalid since underscores can't be in the middle of integer prefixes. This properly formats prefixed integers. This causes [`std::u32::MAX`](https://doc.rust-lang.org/std/u32/constant.MAX.html) to be displayed as ```rust pub const MAX: u32 = u32::MAX; // 0_xff_fff_fffu32 ``` This PR changes it to be displayed as: ```rust pub const MAX: u32 = u32::MAX; // 0xffff_ffffu32 ```
💥 Unable to create a status for d624549bf84ee7110771ff0b5fe2b63ebcc21e9a (422 No commit found for SHA: d624549bf84ee7110771ff0b5fe2b63ebcc21e9a) |
☀️ Test successful - checks-actions |
Currently hex/octal/binary literals with computed values are displayed like
0_xff_fff_fffu32
, which is invalid since underscores can't be in the middle of integer prefixes. This properly formats prefixed integers.This causes
std::u32::MAX
to be displayed asThis PR changes it to be displayed as: