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

num::NonZero::get can be 1 transmute instead of 2 #123139

Merged
merged 1 commit into from
Mar 28, 2024

Conversation

scottmcm
Copy link
Member

Just something I noticed in passing. No need for a match in here to call unreachable_unchecked, as transmute_unchecked will add the appropriate llvm.assume https://rust.godbolt.org/z/W5hjeETnc.

@rustbot
Copy link
Collaborator

rustbot commented Mar 27, 2024

r? @jhpratt

rustbot has assigned @jhpratt.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 27, 2024
/// Types implementing this trait must be primitives that are valid when zeroed.
///
/// The associated `Self::NonZeroInner` type must have the same size+align as `Self`,
/// but with a niche and bit validity making it so the following `transmutes` are sound:
Copy link
Member Author

@scottmcm scottmcm Mar 27, 2024

Choose a reason for hiding this comment

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

I think these were already implied -- they certainly already hold for all the implementations that exist -- but figured I might as well write them out for anyone reading this stuff later.

(And it's a perma-unstable trait, so we can do whatever.)

@scottmcm scottmcm changed the title num::NonZero::get can be 1 transmute instead of 3 num::NonZero::get can be 1 transmute instead of 2 Mar 27, 2024
@jhpratt
Copy link
Member

jhpratt commented Mar 27, 2024

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Mar 27, 2024

📌 Commit 336ff42 has been approved by jhpratt

It is now in the queue for this repository.

@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-review Status: Awaiting review from the assignee but also interested parties. labels Mar 27, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Mar 27, 2024
…pratt

`num::NonZero::get` can be 1 transmute instead of 2

Just something I noticed in passing.  No need for a `match` in here to call `unreachable_unchecked`, as `transmute_unchecked` will add the appropriate `llvm.assume` <https://rust.godbolt.org/z/W5hjeETnc>.
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 27, 2024
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#121943 (Clarify atomic bit validity)
 - rust-lang#123089 (Add invariant to VecDeque::pop_* that len < cap if pop successful)
 - rust-lang#123101 (Delegation: fix ICE on wrong `Self` instantiation)
 - rust-lang#123130 (Load missing type of impl associated constant from trait definition)
 - rust-lang#123133 (chore: fix some comments)
 - rust-lang#123136 (Some wording improvement)
 - rust-lang#123139 (`num::NonZero::get` can be 1 transmute instead of 2)
 - rust-lang#123142 (Let nils know about changes to target docs)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 28, 2024
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#121943 (Clarify atomic bit validity)
 - rust-lang#123075 (CFI: Fix drop and drop_in_place)
 - rust-lang#123101 (Delegation: fix ICE on wrong `Self` instantiation)
 - rust-lang#123130 (Load missing type of impl associated constant from trait definition)
 - rust-lang#123133 (chore: fix some comments)
 - rust-lang#123136 (Some wording improvement)
 - rust-lang#123139 (`num::NonZero::get` can be 1 transmute instead of 2)
 - rust-lang#123142 (Let nils know about changes to target docs)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 9c91e2c into rust-lang:master Mar 28, 2024
11 checks passed
@rustbot rustbot added this to the 1.79.0 milestone Mar 28, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Mar 28, 2024
Rollup merge of rust-lang#123139 - scottmcm:simpler-nonzero-get, r=jhpratt

`num::NonZero::get` can be 1 transmute instead of 2

Just something I noticed in passing.  No need for a `match` in here to call `unreachable_unchecked`, as `transmute_unchecked` will add the appropriate `llvm.assume` <https://rust.godbolt.org/z/W5hjeETnc>.
@scottmcm scottmcm deleted the simpler-nonzero-get branch March 28, 2024 04:44
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. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants