Skip to content

Valid underscores in hex/octal/binary literal docs #84017

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
May 4, 2021

Conversation

syvb
Copy link
Contributor

@syvb syvb commented Apr 8, 2021

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 as

pub const MAX: u32 = u32::MAX; // 0_xff_fff_fffu32

This PR changes it to be displayed as:

pub const MAX: u32 = u32::MAX; // 0xffff_ffffu32

@rust-highfive
Copy link
Contributor

r? @ollie27

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 8, 2021
Copy link
Contributor

@pickfire pickfire left a 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?

@syvb
Copy link
Contributor Author

syvb commented Apr 9, 2021

@pickfire All of the other Rustdoc tests are also in their own tests module, so I added these tests using the same convention.

@crlf0710 crlf0710 added T-rustdoc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 1, 2021
@jyn514
Copy link
Member

jyn514 commented May 3, 2021

r? @jyn514

@rust-highfive rust-highfive assigned jyn514 and unassigned ollie27 May 3, 2021
Copy link
Member

@jyn514 jyn514 left a 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();
Copy link
Member

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 :)

@jyn514 jyn514 added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 3, 2021
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@jyn514
Copy link
Member

jyn514 commented May 4, 2021

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.
@syvb syvb force-pushed the int-literal-underscores branch from 5be9752 to f84b4c5 Compare May 4, 2021 00:11
@jyn514
Copy link
Member

jyn514 commented May 4, 2021

@bors r+

Thanks for working on this!

@bors
Copy link
Collaborator

bors commented May 4, 2021

📌 Commit f84b4c5 has been approved by jyn514

@bors
Copy link
Collaborator

bors commented May 4, 2021

🌲 The tree is currently closed for pull requests below priority 99. This pull request will be tested once the tree is reopened.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 4, 2021
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request May 4, 2021
…=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
```
@bors
Copy link
Collaborator

bors commented May 4, 2021

💥 Unable to create a status for d624549bf84ee7110771ff0b5fe2b63ebcc21e9a (422 No commit found for SHA: d624549bf84ee7110771ff0b5fe2b63ebcc21e9a)

@bors
Copy link
Collaborator

bors commented May 4, 2021

⌛ Testing commit f84b4c5 with merge a5f164f...

@bors
Copy link
Collaborator

bors commented May 4, 2021

☀️ Test successful - checks-actions
Approved by: jyn514
Pushing a5f164f to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 4, 2021
@bors bors merged commit a5f164f into rust-lang:master May 4, 2021
@rustbot rustbot added this to the 1.54.0 milestone May 4, 2021
@jyn514 jyn514 added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Jun 22, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants