Tracking Issue for inherent unchecked integer methods · Issue #85122 · rust-lang/rust (original) (raw)
This is a tracking issue for the unchecked_*
methods on integers.
unchecked_math
(stable as of #122520)
impl uN { pub const unsafe fn unchecked_add(self, rhs: uN) -> uN; pub const unsafe fn unchecked_sub(self, rhs: uN) -> uN; pub const unsafe fn unchecked_mul(self, rhs: uN) -> uN; } impl iN { pub const unsafe fn unchecked_add(self, rhs: iN) -> iN; pub const unsafe fn unchecked_sub(self, rhs: iN) -> iN; pub const unsafe fn unchecked_mul(self, rhs: iN) -> iN; }
Steps / History
- Rework the std::iter::Step trait #69659 added
unchecked_{add,sub,mul}
- Make unchecked_{add,sub,mul} inherent methods unstably const #85096
- Clean up unchecked_math, separate out unchecked_shifts #115626
- Stabilize unchecked_{add,sub,mul} #122520
- Add assert_unsafe_precondition to unchecked_{add,sub,neg,mul,shl,shr} methods #121571
unchecked_neg
impl iN { pub const unsafe fn unchecked_neg(self) -> iN; }
Steps / History
- Clean up unchecked_math, separate out unchecked_shifts #115626 added
unchecked_neg
- Add assert_unsafe_precondition to unchecked_{add,sub,neg,mul,shl,shr} methods #121571
unchecked_shifts
impl uN { pub const unsafe fn unchecked_shl(self, rhs: u32) -> uN; pub const unsafe fn unchecked_shr(self, rhs: u32) -> uN; } impl iN { pub const unsafe fn unchecked_shl(self, rhs: u32) -> iN; pub const unsafe fn unchecked_shr(self, rhs: u32) -> iN; }
Steps / History
- Add inherent unchecked_shl, unchecked_shr to integers #85703
- unchecked_{shl|shr} should use u32 as the RHS #103456
- Clean up unchecked_math, separate out unchecked_shifts #115626
- Add assert_unsafe_precondition to unchecked_{add,sub,neg,mul,shl,shr} methods #121571
unchecked_*
(aggregate)
impl uN { pub const unsafe fn unchecked_add(self, rhs: uN) -> uN; pub const unsafe fn unchecked_sub(self, rhs: uN) -> uN; pub const unsafe fn unchecked_mul(self, rhs: uN) -> uN; pub const unsafe fn unchecked_shl(self, rhs: u32) -> uN; pub const unsafe fn unchecked_shr(self, rhs: u32) -> uN; } impl iN { pub const unsafe fn unchecked_add(self, rhs: iN) -> iN; pub const unsafe fn unchecked_sub(self, rhs: iN) -> iN; pub const unsafe fn unchecked_mul(self, rhs: iN) -> iN; pub const unsafe fn unchecked_shl(self, rhs: u32) -> iN; pub const unsafe fn unchecked_shr(self, rhs: u32) -> iN; pub const unsafe fn unchecked_neg(self) -> iN; }
Steps / History
- Rework the std::iter::Step trait #69659 added
unchecked_{add,sub,mul}
- Make unchecked_{add,sub,mul} inherent methods unstably const #85096
- Add inherent unchecked_shl, unchecked_shr to integers #85703
- unchecked_{shl|shr} should use u32 as the RHS #103456
- Clean up unchecked_math, separate out unchecked_shifts #115626 added
unchecked_neg
- Stabilize unchecked_{add,sub,mul} #122520
- Add assert_unsafe_precondition to unchecked_{add,sub,neg,mul,shl,shr} methods #121571
- Final commenting period (FCP)
- Stabilization PR
Unresolved Questions
- Should the other unchecked intrinsics like
exact_div
also get inherent versions? - From Add inherent unchecked_shl, unchecked_shr to integers #85703, consider if distinguishing the different kinds of ub could be useful (UB from overflow like
MIN/-1
orMAX+1
, LLVM'sn[us]w
; UB from input range likex/0
orx << -1
; UB from lossy like2/4
or3 >> 1
, LLVM'sexact
)
Resolved unresolved questions:
IsWe stabilisedunchecked_*
the best naming for these?unchecked_{add,sub,mul}
already, so, yes.