Skip to content
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

Implement BITS constant for non-zero integers #93292

Merged
merged 2 commits into from
Mar 13, 2022
Merged

Conversation

nvzqz
Copy link
Contributor

@nvzqz nvzqz commented Jan 25, 2022

This adds the associated BITS constant to NonZero{U,I}{8,16,32,64,128,size}.

This is useful when a type alias refers to either a regular or non-zero integer.

@rust-highfive
Copy link
Contributor

r? @yaahc

(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 Jan 25, 2022
@rust-log-analyzer

This comment has been minimized.

#[doc = concat!("assert_eq!(", stringify!($Ty), "::BITS, ", stringify!($Int), "::BITS);")]
/// ```
#[unstable(feature = "nonzero_bits", issue = "none")]
pub const BITS: u32 = $BITS;
Copy link
Contributor

@paolobarbolini paolobarbolini Jan 25, 2022

Choose a reason for hiding this comment

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

Drive-by review: could this just be $Int::BITS instead of $BITS? Basically removing $BITS altogether

Copy link
Contributor Author

@nvzqz nvzqz Jan 25, 2022

Choose a reason for hiding this comment

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

I considered implementing it directly in terms of $Int::BITS but wanted the constant in doctests. After thinking about it for a bit (heh), I'm in favor of this. Especially because it reduces the maintenance burden.

See 870f978.

@yaahc
Copy link
Member

yaahc commented Jan 25, 2022

Looks good, just needs a tracking issue.

@scottmcm
Copy link
Member

minor thing, since you need another commit for a tracking issue anyway:

Consider using this constant on line 468 in the log2 implementation. Doesn't make a big difference, but avoiding some <$Int> would be slightly nicer, I think.

@yaahc yaahc 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 Feb 7, 2022
@JohnCSimon JohnCSimon 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 6, 2022
@JohnCSimon
Copy link
Member

Ping from triage:
@nvzqz can you address the comment from the reviewer?

FYI: when a PR is ready for review, post a message containing
@rustbot ready to switch the PR to S-waiting-on-review so the PR appears in the reviewer's backlog.

@bors
Copy link
Collaborator

bors commented Mar 11, 2022

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

@dtolnay
Copy link
Member

dtolnay commented Mar 13, 2022

@bors r+

@bors
Copy link
Collaborator

bors commented Mar 13, 2022

📌 Commit 6b5acf0 has been approved by dtolnay

@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 Mar 13, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 13, 2022
…askrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#93292 (Implement `BITS` constant for non-zero integers)
 - rust-lang#94777 (Update armv7-unknown-linux-uclibceabi platform support page.)
 - rust-lang#94816 (Add `Atomic*::get_mut_slice`)
 - rust-lang#94844 (Reduce rustbuild bloat caused by serde_derive)
 - rust-lang#94907 (Omit stdarch test crates from the rust-src component)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 2f9bc56 into rust-lang:master Mar 13, 2022
@rustbot rustbot added this to the 1.61.0 milestone Mar 13, 2022
@nvzqz nvzqz deleted the nonzero-bits branch March 20, 2022 22:53
@nvzqz nvzqz mentioned this pull request Sep 7, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 4, 2022
…r=thomcc

Stabilize `nonzero_bits`

Closes rust-lang#94881, implemented by rust-lang#93292.

This change stabilizes the associated `BITS` constant for `NonZero{U,I}{8,16,32,64,128,size}` integers, e.g.:

```rs
impl NonZeroUsize {
    pub const BITS: u32 = usize::BITS;
}
```
@dtolnay dtolnay self-assigned this Mar 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants