Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update int_roundings methods from feedback #95359

Merged
merged 1 commit into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions library/core/src/num/int_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand Down Expand Up @@ -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
///
Expand Down Expand Up @@ -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
///
Expand Down Expand Up @@ -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<Self> {
// This would otherwise fail when calculating `r` when self == T::MIN.
if rhs == -1 {
Expand Down
20 changes: 14 additions & 6 deletions library/core/src/num/uint_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand All @@ -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
}
Expand All @@ -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
///
Expand Down Expand Up @@ -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
///
Expand All @@ -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
Expand All @@ -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<Self> {
match try_opt!(self.checked_rem(rhs)) {
0 => Some(self),
Expand Down
2 changes: 1 addition & 1 deletion library/core/tests/num/i128.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
int_module!(i128, i128);
int_module!(i128);
2 changes: 1 addition & 1 deletion library/core/tests/num/i16.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
int_module!(i16, i16);
int_module!(i16);
2 changes: 1 addition & 1 deletion library/core/tests/num/i32.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
int_module!(i32, i32);
int_module!(i32);

#[test]
fn test_arith_operation() {
Expand Down
2 changes: 1 addition & 1 deletion library/core/tests/num/i64.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
int_module!(i64, i64);
int_module!(i64);
2 changes: 1 addition & 1 deletion library/core/tests/num/i8.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
int_module!(i8, i8);
int_module!(i8);
4 changes: 2 additions & 2 deletions library/core/tests/num/int_macros.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
2 changes: 1 addition & 1 deletion library/core/tests/num/u128.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
uint_module!(u128, u128);
uint_module!(u128);
2 changes: 1 addition & 1 deletion library/core/tests/num/u16.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
uint_module!(u16, u16);
uint_module!(u16);
2 changes: 1 addition & 1 deletion library/core/tests/num/u32.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
uint_module!(u32, u32);
uint_module!(u32);
2 changes: 1 addition & 1 deletion library/core/tests/num/u64.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
uint_module!(u64, u64);
uint_module!(u64);
2 changes: 1 addition & 1 deletion library/core/tests/num/u8.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
uint_module!(u8, u8);
uint_module!(u8);
4 changes: 2 additions & 2 deletions library/core/tests/num/uint_macros.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down