Skip to content

Implement BITS constant for non-zero integers - #93292

Merged
bors merged 2 commits into
rust-lang:masterfrom
nvzqz:nonzero-bits
Mar 13, 2022
Merged

Implement BITS constant for non-zero integers#93292
bors merged 2 commits into
rust-lang:masterfrom
nvzqz:nonzero-bits

Conversation

@nvzqz

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

r? @yaahc

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

@rust-highfiverust-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.

Comment threadlibrary/core/src/num/nonzero.rs Outdated

@paolobarbolinipaolobarboliniJan 25, 2022

Copy link
Copy Markdown
Contributor

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

@nvzqznvzqzJan 25, 2022

Copy link
Copy Markdown
ContributorAuthor

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
Copy Markdown
Member

Looks good, just needs a tracking issue.

@scottmcm

Copy link
Copy Markdown
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.

@yaahcyaahc 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
@JohnCSimonJohnCSimon 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
Copy Markdown

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

bors commented Mar 11, 2022

Copy link
Copy Markdown
Collaborator

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

@dtolnay

Copy link
Copy Markdown
Member

@bors r+

@bors

bors commented Mar 13, 2022

Copy link
Copy Markdown
Collaborator

📌 Commit 6b5acf0 has been approved by dtolnay

@borsbors 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:masterMar 13, 2022
@rustbotrustbot added this to the 1.61.0 milestone Mar 13, 2022
@nvzqz
nvzqz deleted the nonzero-bits branch March 20, 2022 22:53
@nvzqznvzqz 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`
Closesrust-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;
}
```
@dtolnaydtolnay self-assigned this Mar 24, 2024
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: 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

@nvzqz@rust-highfive@rust-log-analyzer@yaahc@scottmcm@JohnCSimon@bors@dtolnay@paolobarbolini@rustbot