From dde590d1801a0f18c5903b7ed6c53074faceec83 Mon Sep 17 00:00:00 2001 From: Jacob Pratt Date: Sun, 27 Mar 2022 03:15:21 -0400 Subject: [PATCH] Update `int_roundings` methods from feedback --- library/core/src/num/int_macros.rs | 22 ++++++++++++++++++---- library/core/src/num/uint_macros.rs | 20 ++++++++++++++------ library/core/tests/num/i128.rs | 2 +- library/core/tests/num/i16.rs | 2 +- library/core/tests/num/i32.rs | 2 +- library/core/tests/num/i64.rs | 2 +- library/core/tests/num/i8.rs | 2 +- library/core/tests/num/int_macros.rs | 4 ++-- library/core/tests/num/u128.rs | 2 +- library/core/tests/num/u16.rs | 2 +- library/core/tests/num/u32.rs | 2 +- library/core/tests/num/u64.rs | 2 +- library/core/tests/num/u8.rs | 2 +- library/core/tests/num/uint_macros.rs | 4 ++-- 14 files changed, 46 insertions(+), 24 deletions(-) diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs index 1bf447347408d..b5c7982a5a871 100644 --- a/library/core/src/num/int_macros.rs +++ b/library/core/src/num/int_macros.rs @@ -2015,7 +2015,12 @@ macro_rules! int_impl { /// /// # Panics /// - /// This function will panic if `rhs` is 0 or the division results in overflow. + /// This function will panic if `rhs` is zero. + /// + /// ## Overflow behavior + /// + /// On overflow, this function will panic if overflow checks are enabled (default in debug + /// mode) and wrap if overflow checks are disabled (default in release mode). /// /// # Examples /// @@ -2050,7 +2055,12 @@ macro_rules! int_impl { /// /// # Panics /// - /// This function will panic if `rhs` is 0 or the division results in overflow. + /// This function will panic if `rhs` is zero. + /// + /// ## Overflow behavior + /// + /// On overflow, this function will panic if overflow checks are enabled (default in debug + /// mode) and wrap if overflow checks are disabled (default in release mode). /// /// # Examples /// @@ -2088,7 +2098,12 @@ macro_rules! int_impl { /// /// # Panics /// - /// This function will panic if `rhs` is 0 or the operation results in overflow. + /// This function will panic if `rhs` is zero. + /// + /// ## Overflow behavior + /// + /// On overflow, this function will panic if overflow checks are enabled (default in debug + /// mode) and wrap if overflow checks are disabled (default in release mode). /// /// # Examples /// @@ -2157,7 +2172,6 @@ macro_rules! int_impl { #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] - #[rustc_inherit_overflow_checks] pub const fn checked_next_multiple_of(self, rhs: Self) -> Option { // This would otherwise fail when calculating `r` when self == T::MIN. if rhs == -1 { diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index ce52e4773ce1f..048d6bafcdecd 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -2020,7 +2020,7 @@ macro_rules! uint_impl { /// /// # Panics /// - /// This function will panic if `rhs` is 0. + /// This function will panic if `rhs` is zero. /// /// # Examples /// @@ -2034,7 +2034,6 @@ macro_rules! uint_impl { #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline(always)] - #[rustc_inherit_overflow_checks] pub const fn div_floor(self, rhs: Self) -> Self { self / rhs } @@ -2043,7 +2042,12 @@ macro_rules! uint_impl { /// /// # Panics /// - /// This function will panic if `rhs` is 0. + /// This function will panic if `rhs` is zero. + /// + /// ## Overflow behavior + /// + /// On overflow, this function will panic if overflow checks are enabled (default in debug + /// mode) and wrap if overflow checks are disabled (default in release mode). /// /// # Examples /// @@ -2073,7 +2077,12 @@ macro_rules! uint_impl { /// /// # Panics /// - /// This function will panic if `rhs` is 0 or the operation results in overflow. + /// This function will panic if `rhs` is zero. + /// + /// ## Overflow behavior + /// + /// On overflow, this function will panic if overflow checks are enabled (default in debug + /// mode) and wrap if overflow checks are disabled (default in release mode). /// /// # Examples /// @@ -2097,7 +2106,7 @@ macro_rules! uint_impl { } /// Calculates the smallest value greater than or equal to `self` that - /// is a multiple of `rhs`. Returns `None` is `rhs` is zero or the + /// is a multiple of `rhs`. Returns `None` if `rhs` is zero or the /// operation would result in overflow. /// /// # Examples @@ -2115,7 +2124,6 @@ macro_rules! uint_impl { #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] - #[rustc_inherit_overflow_checks] pub const fn checked_next_multiple_of(self, rhs: Self) -> Option { match try_opt!(self.checked_rem(rhs)) { 0 => Some(self), diff --git a/library/core/tests/num/i128.rs b/library/core/tests/num/i128.rs index 72c0b225991f6..1ddd20f33d0b1 100644 --- a/library/core/tests/num/i128.rs +++ b/library/core/tests/num/i128.rs @@ -1 +1 @@ -int_module!(i128, i128); +int_module!(i128); diff --git a/library/core/tests/num/i16.rs b/library/core/tests/num/i16.rs index f5544b914b73d..c7aa9fff964ed 100644 --- a/library/core/tests/num/i16.rs +++ b/library/core/tests/num/i16.rs @@ -1 +1 @@ -int_module!(i16, i16); +int_module!(i16); diff --git a/library/core/tests/num/i32.rs b/library/core/tests/num/i32.rs index 4acc760ffac99..efd5b1596a80d 100644 --- a/library/core/tests/num/i32.rs +++ b/library/core/tests/num/i32.rs @@ -1,4 +1,4 @@ -int_module!(i32, i32); +int_module!(i32); #[test] fn test_arith_operation() { diff --git a/library/core/tests/num/i64.rs b/library/core/tests/num/i64.rs index fa4d2ab6638d7..93d23c10adf7e 100644 --- a/library/core/tests/num/i64.rs +++ b/library/core/tests/num/i64.rs @@ -1 +1 @@ -int_module!(i64, i64); +int_module!(i64); diff --git a/library/core/tests/num/i8.rs b/library/core/tests/num/i8.rs index ccec6915fe090..887d4f17d25ff 100644 --- a/library/core/tests/num/i8.rs +++ b/library/core/tests/num/i8.rs @@ -1 +1 @@ -int_module!(i8, i8); +int_module!(i8); diff --git a/library/core/tests/num/int_macros.rs b/library/core/tests/num/int_macros.rs index d2d655ea2c750..8b84a78e6be08 100644 --- a/library/core/tests/num/int_macros.rs +++ b/library/core/tests/num/int_macros.rs @@ -1,9 +1,9 @@ macro_rules! int_module { - ($T:ident, $T_i:ident) => { + ($T:ident) => { #[cfg(test)] mod tests { use core::ops::{BitAnd, BitOr, BitXor, Not, Shl, Shr}; - use core::$T_i::*; + use core::$T::*; use crate::num; diff --git a/library/core/tests/num/u128.rs b/library/core/tests/num/u128.rs index 716d1836f2c0e..a7b0f9effefb9 100644 --- a/library/core/tests/num/u128.rs +++ b/library/core/tests/num/u128.rs @@ -1 +1 @@ -uint_module!(u128, u128); +uint_module!(u128); diff --git a/library/core/tests/num/u16.rs b/library/core/tests/num/u16.rs index 435b914224c5a..010596a34a56c 100644 --- a/library/core/tests/num/u16.rs +++ b/library/core/tests/num/u16.rs @@ -1 +1 @@ -uint_module!(u16, u16); +uint_module!(u16); diff --git a/library/core/tests/num/u32.rs b/library/core/tests/num/u32.rs index 71dc005dea370..687d3bbaa907f 100644 --- a/library/core/tests/num/u32.rs +++ b/library/core/tests/num/u32.rs @@ -1 +1 @@ -uint_module!(u32, u32); +uint_module!(u32); diff --git a/library/core/tests/num/u64.rs b/library/core/tests/num/u64.rs index b498ebc52042e..ee55071e94996 100644 --- a/library/core/tests/num/u64.rs +++ b/library/core/tests/num/u64.rs @@ -1 +1 @@ -uint_module!(u64, u64); +uint_module!(u64); diff --git a/library/core/tests/num/u8.rs b/library/core/tests/num/u8.rs index 68e938be704ac..12b038ce0f75c 100644 --- a/library/core/tests/num/u8.rs +++ b/library/core/tests/num/u8.rs @@ -1 +1 @@ -uint_module!(u8, u8); +uint_module!(u8); diff --git a/library/core/tests/num/uint_macros.rs b/library/core/tests/num/uint_macros.rs index 49f8f1f13fad4..93ae620c23302 100644 --- a/library/core/tests/num/uint_macros.rs +++ b/library/core/tests/num/uint_macros.rs @@ -1,9 +1,9 @@ macro_rules! uint_module { - ($T:ident, $T_i:ident) => { + ($T:ident) => { #[cfg(test)] mod tests { use core::ops::{BitAnd, BitOr, BitXor, Not, Shl, Shr}; - use core::$T_i::*; + use core::$T::*; use std::str::FromStr; use crate::num;