-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Update int_roundings
methods from feedback
#95359
Conversation
I'm kinda hesitant about the NonZero switchover. Looking at my own uses of div_ceil and next_multiple_of, most of them use compile-time constants, but a few don't. Leaving aside the non-zero numeric literals work (which I am impressed by), I'm wondering if we really want to move this far from the original num-integer trait methods. The original methods took the same type on both sides of the operation. And panic-on-zero seems normal for a divide operation. In constant cases, I'd expect the panic to get compiled out anyway. Normally I'm all for "convince the type system an error can never happen". But this feels like we're adding a tiny fraction of dependent types, and a substantial amount of complexity to go along with it. Among other things, to make this fully usable, it'd need more impls (including impls on NonZero types that return NonZero types where appropriate), and it'd still require a lot of I'd like to propose that we keep the change to overflow handling, but switch back to the non-NonZero types. cc @scottmcm; @jhpratt suggested that you had opinions in this area. |
@joshtriplett My thoughts being mentioned are probably those in #88581 (comment) I actually agree that it would be completely reasonable for The problem for me comes in the Taking nonzero types as the RHS for All that, however, I think applies only to the
I'll note that we have a bunch of these where appropriate -- for example, checked/saturating add/mul/pow are there for the unsigned ones, EDIT: To make a concrete proposal, I suggest that |
I likely won't be a user of |
@scottmcm I disagree; I think using |
We talked about this very briefly in today's @rust-lang/libs-api meeting. It seemed to me that a few people (not sure about overall team consensus) agreed that we should just use the same integer types here, rather than trying to use NonZero types, and just panic on zero as we already do for division. |
Rebased and pushed the amended commit. It now alters documentation and removes |
@jhpratt I posted a comment on the phrasing of the documentation about overflow checks. (People can enable overflow checks in release mode, or disable them in debug mode.) Otherwise, this LGTM; r=me with the comment updated. |
I'm not a reviewer, so I don't think I can actually do this. Can't hurt to try, though. @bors r=@joshtriplett rollup |
@jhpratt: 🔑 Insufficient privileges: Not in reviewers |
@jhpratt: 🔑 Insufficient privileges: not in try users |
@bors r+ rollup |
📌 Commit dde590d has been approved by |
…askrgr Rollup of 7 pull requests Successful merges: - rust-lang#95359 (Update `int_roundings` methods from feedback) - rust-lang#95843 (Improve Rc::new_cyclic and Arc::new_cyclic documentation) - rust-lang#96507 (Suggest calling `Self::associated_function()`) - rust-lang#96635 (Use "strict" mode in JS scripts) - rust-lang#96673 (Report that opaque types are not allowed in impls even in the presence of other errors) - rust-lang#96682 (Show invisible delimeters (within comments) when pretty printing.) - rust-lang#96714 (interpret/validity: debug-check ScalarPair layout information) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This updates
#![feature(int_roundings)]
(#88581) from feedback. All methods now takeNonZeroX
. The documentation makes clear that they panic in debug mode and wrap in release mode.r? @joshtriplett
@rustbot label +T-libs +T-libs-api +S-waiting-on-review