-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
feat(core): impl Step for NonZero<u*> #127534
base: master
Are you sure you want to change the base?
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @cuviper (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
This comment has been minimized.
This comment has been minimized.
UI tests are failing because the output of diagnostics was reorganized now that Its getting late so I'll take a look at it tomorrow and see if I find a way to update the ui tests. |
You can use I know you already went through an ACP, but I think this still needs a libs-api reviewer since it is instantly stable -- @rustbot label -T-libs +T-libs-api |
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.
Regarding the stable API surface: We should also add the appropriate ExactSizeIterator
impls, without repeating the 16-bit-platform mistakes.
|
718b7a9
to
ca46c6d
Compare
I see that |
Implement Step for NonZero unsigned integers as discussed in [libs-team#130][1]. [1]: rust-lang/libs-team#130 `step_nonzero_impls` was adapted from `step_integer_impls` and the tests were adapted from the step tests.
Implementing `Step` for the `NonZero<u*>` changed the diagnostics from the compiler.
ca46c6d
to
18adf5f
Compare
@joshtriplett friendly ping. Should I assign someone else if you are too busy? |
r? libs-api |
@rfcbot fcp merge |
Team member @Amanieu has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
See also #73121 |
This comment was marked as resolved.
This comment was marked as resolved.
For now I've reworded and renamed that ER issue. But I'm now less sure it's a useful enough thing to have. |
Having the issue there is nice though, it might prompt some further discussion in the future, although |
My point isn't to remove the panic from the binary, but to remove it from the source code. I try to minimize the number of visible unwraps in my Rust modules. |
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. This will be merged soon. |
@@ -960,6 +1104,12 @@ range_incl_exact_iter_impl! { | |||
i16 | |||
} | |||
|
|||
#[cfg(target_pointer_width = "32")] |
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.
do we want these ExactSizeIterator
impls to be dependent on pointer size? the impls for primitive integer types don't depend on pointer size, presumably to help you write more portable code that doesn't break on 32 or 16-bit platforms.
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.
That is a known bug, if they don't depend on the pointer width (size of usize
) they can't be ExactSizeIterators
(for anything >u16).
(0..=u32::MAX).len()
causes an overflow on usize == u16
. If you prefer code not to break on usize == u16
platforms, then I would prefer to remove the impls over removing the constraint.
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.
yeah, i'm proposing implementing ExactSizeIterator
as follows,
with no #[cfg]
attributes (edit: i forgot RangeInclusive
still can't have len == 2^16
because NonZero
excludes one value):
T |
Range<NonZero<T>> |
RangeInclusive<NonZero<T>> |
---|---|---|
u8 |
Yes | Yes |
u16 |
Yes | Yes |
u32 |
No | No |
u64 |
No | No |
u128 |
No | No |
usize |
Yes | Yes |
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 don't know how to address this, my preference is implementing it as it currently stands, and this concern was raised after the FCP. Would the changes need a new FCP? Am I allowed to edit the PR after the reviews?
Implement Step for NonZero unsigned integers as discussed in libs-team#130.
step_nonzero_impls
was adapted fromstep_integer_impls
and the tests were adapted from the step tests.It seems to compile and pass the tests c:
I would like to test the edge cases, specially around overflows. To ensure safe code cannot generate a 0
NonZero
, but I don't know how to go about it. I would love some feedback on that (and the PR overall).The impls are tagges with
#[unstable(feature = "step_trait", reason = "recently redesigned", issue = "42168")]
. I assumed this was appropriate, but I am not sure.