Rollup merge of #128103 - folkertdev:unsigned-int-is-multiple-of, r=A… · model-checking/verify-rust-std@2a70839
@@ -2853,6 +2853,35 @@ macro_rules! uint_impl {
28532853}
28542854}
285528552856+/// Returns `true` if `self` is an integer multiple of `rhs`, and false otherwise.
2857+ ///
2858+ /// This function is equivalent to `self % rhs == 0`, except that it will not panic
2859+ /// for `rhs == 0`. Instead, `0.is_multiple_of(0) == true`, and for any non-zero `n`,
2860+ /// `n.is_multiple_of(0) == false`.
2861+ ///
2862+ /// # Examples
2863+ ///
2864+ /// Basic usage:
2865+ ///
2866+ /// ```
2867+ /// #![feature(unsigned_is_multiple_of)]
2868+ #[doc = concat!("assert!(6_", stringify!($SelfT), ".is_multiple_of(2));")]
2869+ #[doc = concat!("assert!(!5_", stringify!($SelfT), ".is_multiple_of(2));")]
2870+///
2871+ #[doc = concat!("assert!(0_", stringify!($SelfT), ".is_multiple_of(0));")]
2872+ #[doc = concat!("assert!(!6_", stringify!($SelfT), ".is_multiple_of(0));")]
2873+/// ```
2874+ #[unstable(feature = "unsigned_is_multiple_of", issue = "128101")]
2875+ #[must_use]
2876+ #[inline]
2877+ #[rustc_inherit_overflow_checks]
2878+pub const fn is_multiple_of(self, rhs: Self) -> bool {
2879+match rhs {
2880+0 => self == 0,
2881+ _ => self % rhs == 0,
2882+}
2883+}
2884+28562885/// Returns `true` if and only if `self == 2^k` for some `k`.
28572886 ///
28582887 /// # Examples