Skip to content

Commit 24a9bab

Browse files
authored
Rollup merge of #136019 - scottmcm:alias-unchecked-div, r=Mark-Simulacrum
Add an `unchecked_div` alias to the `Div<NonZero<_>>` impls Inspired by rust-lang/libs-team#526, if people are looking for `unchecked_div`, point them to `u32: Div<NonZero<u32>>` and friends which do no runtime checks -- and are safe! -- rather than today's behaviour of [the intrinsic being the top result](https://doc.rust-lang.org/std/?search=unchecked_div). ![image](https://github.com/user-attachments/assets/cf2a3c06-4876-49c1-8e33-64cd431c772a)
2 parents 530c695 + 2d11559 commit 24a9bab

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

library/core/src/num/nonzero.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1185,8 +1185,12 @@ macro_rules! nonzero_integer_signedness_dependent_impls {
11851185
impl Div<NonZero<$Int>> for $Int {
11861186
type Output = $Int;
11871187

1188+
/// Same as `self / other.get()`, but because `other` is a `NonZero<_>`,
1189+
/// there's never a runtime check for division-by-zero.
1190+
///
11881191
/// This operation rounds towards zero, truncating any fractional
11891192
/// part of the exact result, and cannot panic.
1193+
#[doc(alias = "unchecked_div")]
11901194
#[inline]
11911195
fn div(self, other: NonZero<$Int>) -> $Int {
11921196
// SAFETY: Division by zero is checked because `other` is non-zero,
@@ -1197,6 +1201,9 @@ macro_rules! nonzero_integer_signedness_dependent_impls {
11971201

11981202
#[stable(feature = "nonzero_div_assign", since = "1.79.0")]
11991203
impl DivAssign<NonZero<$Int>> for $Int {
1204+
/// Same as `self /= other.get()`, but because `other` is a `NonZero<_>`,
1205+
/// there's never a runtime check for division-by-zero.
1206+
///
12001207
/// This operation rounds towards zero, truncating any fractional
12011208
/// part of the exact result, and cannot panic.
12021209
#[inline]

0 commit comments

Comments
 (0)