-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Make the "main" constructors of NonZero/Shared/Unique return Option #42959
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @sfackler (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
CC @aturon @rust-lang/libs |
cc @rust-lang/libs |
☔ The latest upstream changes (presumably #42964) made this pull request unmergeable. Please resolve the merge conflicts. |
9b54928
to
94081de
Compare
☔ The latest upstream changes (presumably #42924) made this pull request unmergeable. Please resolve the merge conflicts. |
It looks like almost all current instances were changed to |
The were changed to If it is indeed the wrong default, we can drop the two renaming commits and only add |
@SimonSapin: Well, can initializing a |
@eternaleye Correct, that’s why the unchecked constructor is For example in |
94081de
to
4e3cd03
Compare
I don't mind what's what here, but adding a new function that's the "default" and then moving all existing uses to the non-default one seems incoherent to me. I'd feel that we should fix that one way or another, but I don't particularly mind how. |
Hi @SimonSapin, have you had a chance to have a think about @alexcrichton's comment above? |
Hi @aidanhs, I’ve had more than a chance. We’ve been having the same discussion in the tracking issue. I’ve listed three options corresponding to commits of this PR: #27730 (comment), Alex suggested "none of the above", and I replied with a lengthy analysis of call sites: #27730 (comment). The TL;DR is that most calls can be made unnecessary if we add new APIs or modify unstable ones, and most remaining calls could either use the unsafe unchecked constructor or use the checked constructor with |
Visiting again for PR triage. I assume this PR is on hold until the discussion is resolved in the tracking issue you mention? Looks like it hasn't been updated for about a week now and the rest of the libs team has yet to comment on the fcp. Just pondering whether it makes sense to close this PR until the questions are resolved over there - thoughts? |
Yes, this is waiting on that discussion. Closing seems unproductive to me. |
4e3cd03
to
6a5fa26
Compare
I’ve replaced some unsafe calls to
These are all |
6a5fa26
to
ad85c2a
Compare
Opened rust-lang/nomicon#32 which makes |
ad85c2a
to
7350d2d
Compare
☔ The latest upstream changes (presumably #43246) made this pull request unmergeable. Please resolve the merge conflicts. |
💔 Test failed - status-travis |
⌛ Testing commit 0d1864b with merge 83b003f3c985efe1687df88519aefa932556ef5f... |
💔 Test failed - status-appveyor |
Looks like #43453 again. |
@bors retry |
⌛ Testing commit 0d1864b with merge 0af7cb5ada568f986c7a43436aa31bc20bba39ee... |
💔 Test failed - status-travis |
Those
|
@bors rollup |
Make the "main" constructors of NonZero/Shared/Unique return Option Per discussion in rust-lang#27730 (comment). This is a breaking change to unstable APIs. The old behavior is still available under the name `new_unchecked`. Note that only that one can be `const fn`, since `if` is currently not allowed in constant contexts. In the case of `NonZero` this requires adding a new `is_zero` method to the `Zeroable` trait. I mildly dislike this, but it’s not much worse than having a `Zeroable` trait in the first place. `Zeroable` and `NonZero` are both unstable, this can be reworked later.
This is a breaking change. See a [PR](rust-lang/rust#42959).
Update nomicon (This should have been in #42959.)
Per discussion in #27730 (comment).
This is a breaking change to unstable APIs.
The old behavior is still available under the name
new_unchecked
. Note that only that one can beconst fn
, sinceif
is currently not allowed in constant contexts.In the case of
NonZero
this requires adding a newis_zero
method to theZeroable
trait. I mildly dislike this, but it’s not much worse than having aZeroable
trait in the first place.Zeroable
andNonZero
are both unstable, this can be reworked later.