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.
This commit is contained in:
commit
8e0a8cdecb
@ -2126,6 +2126,7 @@ pub const fn div_euclid(self, rhs: Self) -> Self {
|
|||||||
/// assert_eq!(a.rem_euclid(-b), 3);
|
/// assert_eq!(a.rem_euclid(-b), 3);
|
||||||
/// assert_eq!((-a).rem_euclid(-b), 1);
|
/// assert_eq!((-a).rem_euclid(-b), 1);
|
||||||
/// ```
|
/// ```
|
||||||
|
#[doc(alias = "modulo", alias = "mod")]
|
||||||
#[stable(feature = "euclidean_division", since = "1.38.0")]
|
#[stable(feature = "euclidean_division", since = "1.38.0")]
|
||||||
#[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.52.0")]
|
#[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.52.0")]
|
||||||
#[must_use = "this returns the result of the operation, \
|
#[must_use = "this returns the result of the operation, \
|
||||||
|
@ -2024,6 +2024,7 @@ pub const fn div_euclid(self, rhs: Self) -> Self {
|
|||||||
/// ```
|
/// ```
|
||||||
#[doc = concat!("assert_eq!(7", stringify!($SelfT), ".rem_euclid(4), 3); // or any other integer type")]
|
#[doc = concat!("assert_eq!(7", stringify!($SelfT), ".rem_euclid(4), 3); // or any other integer type")]
|
||||||
/// ```
|
/// ```
|
||||||
|
#[doc(alias = "modulo", alias = "mod")]
|
||||||
#[stable(feature = "euclidean_division", since = "1.38.0")]
|
#[stable(feature = "euclidean_division", since = "1.38.0")]
|
||||||
#[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.52.0")]
|
#[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.52.0")]
|
||||||
#[must_use = "this returns the result of the operation, \
|
#[must_use = "this returns the result of the operation, \
|
||||||
|
@ -323,6 +323,7 @@ pub fn div_euclid(self, rhs: f32) -> f32 {
|
|||||||
/// // limitation due to round-off error
|
/// // limitation due to round-off error
|
||||||
/// assert!((-f32::EPSILON).rem_euclid(3.0) != 0.0);
|
/// assert!((-f32::EPSILON).rem_euclid(3.0) != 0.0);
|
||||||
/// ```
|
/// ```
|
||||||
|
#[doc(alias = "modulo", alias = "mod")]
|
||||||
#[rustc_allow_incoherent_impl]
|
#[rustc_allow_incoherent_impl]
|
||||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -323,6 +323,7 @@ pub fn div_euclid(self, rhs: f64) -> f64 {
|
|||||||
/// // limitation due to round-off error
|
/// // limitation due to round-off error
|
||||||
/// assert!((-f64::EPSILON).rem_euclid(3.0) != 0.0);
|
/// assert!((-f64::EPSILON).rem_euclid(3.0) != 0.0);
|
||||||
/// ```
|
/// ```
|
||||||
|
#[doc(alias = "modulo", alias = "mod")]
|
||||||
#[rustc_allow_incoherent_impl]
|
#[rustc_allow_incoherent_impl]
|
||||||
#[must_use = "method returns a new number and does not mutate the original value"]
|
#[must_use = "method returns a new number and does not mutate the original value"]
|
||||||
#[inline]
|
#[inline]
|
||||||
|
Loading…
Reference in New Issue
Block a user