Skip to content

Commit 8e0a8cd

Browse files
authored
Rollup merge of #114977 - kpreid:modulo, r=thomcc
Add `modulo` and `mod` as doc aliases for `rem_euclid`. When I was learning Rust I looked for “a modulo function” and couldn’t find one, so thought I had to write my own; it wasn't at all obvious that a function with “rem” in the name was the function I wanted. Hopefully this will save the next learner from that. However, it does have the disadvantage that the top results in rustdoc for “mod” are now these aliases instead of the Rust keyword, which probably isn't ideal.
2 parents d8bde48 + 2c21635 commit 8e0a8cd

File tree

4 files changed

+4
-0
lines changed

4 files changed

+4
-0
lines changed

library/core/src/num/int_macros.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2126,6 +2126,7 @@ macro_rules! int_impl {
21262126
/// assert_eq!(a.rem_euclid(-b), 3);
21272127
/// assert_eq!((-a).rem_euclid(-b), 1);
21282128
/// ```
2129+
#[doc(alias = "modulo", alias = "mod")]
21292130
#[stable(feature = "euclidean_division", since = "1.38.0")]
21302131
#[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.52.0")]
21312132
#[must_use = "this returns the result of the operation, \

library/core/src/num/uint_macros.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2024,6 +2024,7 @@ macro_rules! uint_impl {
20242024
/// ```
20252025
#[doc = concat!("assert_eq!(7", stringify!($SelfT), ".rem_euclid(4), 3); // or any other integer type")]
20262026
/// ```
2027+
#[doc(alias = "modulo", alias = "mod")]
20272028
#[stable(feature = "euclidean_division", since = "1.38.0")]
20282029
#[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.52.0")]
20292030
#[must_use = "this returns the result of the operation, \

library/std/src/f32.rs

+1
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ impl f32 {
323323
/// // limitation due to round-off error
324324
/// assert!((-f32::EPSILON).rem_euclid(3.0) != 0.0);
325325
/// ```
326+
#[doc(alias = "modulo", alias = "mod")]
326327
#[rustc_allow_incoherent_impl]
327328
#[must_use = "method returns a new number and does not mutate the original value"]
328329
#[inline]

library/std/src/f64.rs

+1
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ impl f64 {
323323
/// // limitation due to round-off error
324324
/// assert!((-f64::EPSILON).rem_euclid(3.0) != 0.0);
325325
/// ```
326+
#[doc(alias = "modulo", alias = "mod")]
326327
#[rustc_allow_incoherent_impl]
327328
#[must_use = "method returns a new number and does not mutate the original value"]
328329
#[inline]

0 commit comments

Comments
 (0)