- Notifications
You must be signed in to change notification settings - Fork 13.9k
num::NonZero::get can be 1 transmute instead of 2 #123139
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
scottmcm commented 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: |
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.
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.)
num::NonZero::get can be 1 transmute instead of 3num::NonZero::get can be 1 transmute instead of 2 | @bors r+ rollup |
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
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>.
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.
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Just something I noticed in passing. No need for a
matchin here to callunreachable_unchecked, astransmute_uncheckedwill add the appropriatellvm.assumehttps://rust.godbolt.org/z/W5hjeETnc.