Skip to content

Commit 4780141

Browse files
authored
Rollup merge of #95359 - jhpratt:int_roundings, r=joshtriplett
Update `int_roundings` methods from feedback This updates `#![feature(int_roundings)]` (#88581) from feedback. All methods now take `NonZeroX`. The documentation makes clear that they panic in debug mode and wrap in release mode. r? `@joshtriplett` `@rustbot` label +T-libs +T-libs-api +S-waiting-on-review
2 parents 322a149 + dde590d commit 4780141

File tree

14 files changed

+46
-24
lines changed

14 files changed

+46
-24
lines changed

library/core/src/num/int_macros.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -2015,7 +2015,12 @@ macro_rules! int_impl {
20152015
///
20162016
/// # Panics
20172017
///
2018-
/// This function will panic if `rhs` is 0 or the division results in overflow.
2018+
/// This function will panic if `rhs` is zero.
2019+
///
2020+
/// ## Overflow behavior
2021+
///
2022+
/// On overflow, this function will panic if overflow checks are enabled (default in debug
2023+
/// mode) and wrap if overflow checks are disabled (default in release mode).
20192024
///
20202025
/// # Examples
20212026
///
@@ -2050,7 +2055,12 @@ macro_rules! int_impl {
20502055
///
20512056
/// # Panics
20522057
///
2053-
/// This function will panic if `rhs` is 0 or the division results in overflow.
2058+
/// This function will panic if `rhs` is zero.
2059+
///
2060+
/// ## Overflow behavior
2061+
///
2062+
/// On overflow, this function will panic if overflow checks are enabled (default in debug
2063+
/// mode) and wrap if overflow checks are disabled (default in release mode).
20542064
///
20552065
/// # Examples
20562066
///
@@ -2088,7 +2098,12 @@ macro_rules! int_impl {
20882098
///
20892099
/// # Panics
20902100
///
2091-
/// This function will panic if `rhs` is 0 or the operation results in overflow.
2101+
/// This function will panic if `rhs` is zero.
2102+
///
2103+
/// ## Overflow behavior
2104+
///
2105+
/// On overflow, this function will panic if overflow checks are enabled (default in debug
2106+
/// mode) and wrap if overflow checks are disabled (default in release mode).
20922107
///
20932108
/// # Examples
20942109
///
@@ -2157,7 +2172,6 @@ macro_rules! int_impl {
21572172
#[must_use = "this returns the result of the operation, \
21582173
without modifying the original"]
21592174
#[inline]
2160-
#[rustc_inherit_overflow_checks]
21612175
pub const fn checked_next_multiple_of(self, rhs: Self) -> Option<Self> {
21622176
// This would otherwise fail when calculating `r` when self == T::MIN.
21632177
if rhs == -1 {

library/core/src/num/uint_macros.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -2020,7 +2020,7 @@ macro_rules! uint_impl {
20202020
///
20212021
/// # Panics
20222022
///
2023-
/// This function will panic if `rhs` is 0.
2023+
/// This function will panic if `rhs` is zero.
20242024
///
20252025
/// # Examples
20262026
///
@@ -2034,7 +2034,6 @@ macro_rules! uint_impl {
20342034
#[must_use = "this returns the result of the operation, \
20352035
without modifying the original"]
20362036
#[inline(always)]
2037-
#[rustc_inherit_overflow_checks]
20382037
pub const fn div_floor(self, rhs: Self) -> Self {
20392038
self / rhs
20402039
}
@@ -2043,7 +2042,12 @@ macro_rules! uint_impl {
20432042
///
20442043
/// # Panics
20452044
///
2046-
/// This function will panic if `rhs` is 0.
2045+
/// This function will panic if `rhs` is zero.
2046+
///
2047+
/// ## Overflow behavior
2048+
///
2049+
/// On overflow, this function will panic if overflow checks are enabled (default in debug
2050+
/// mode) and wrap if overflow checks are disabled (default in release mode).
20472051
///
20482052
/// # Examples
20492053
///
@@ -2073,7 +2077,12 @@ macro_rules! uint_impl {
20732077
///
20742078
/// # Panics
20752079
///
2076-
/// This function will panic if `rhs` is 0 or the operation results in overflow.
2080+
/// This function will panic if `rhs` is zero.
2081+
///
2082+
/// ## Overflow behavior
2083+
///
2084+
/// On overflow, this function will panic if overflow checks are enabled (default in debug
2085+
/// mode) and wrap if overflow checks are disabled (default in release mode).
20772086
///
20782087
/// # Examples
20792088
///
@@ -2097,7 +2106,7 @@ macro_rules! uint_impl {
20972106
}
20982107

20992108
/// Calculates the smallest value greater than or equal to `self` that
2100-
/// is a multiple of `rhs`. Returns `None` is `rhs` is zero or the
2109+
/// is a multiple of `rhs`. Returns `None` if `rhs` is zero or the
21012110
/// operation would result in overflow.
21022111
///
21032112
/// # Examples
@@ -2115,7 +2124,6 @@ macro_rules! uint_impl {
21152124
#[must_use = "this returns the result of the operation, \
21162125
without modifying the original"]
21172126
#[inline]
2118-
#[rustc_inherit_overflow_checks]
21192127
pub const fn checked_next_multiple_of(self, rhs: Self) -> Option<Self> {
21202128
match try_opt!(self.checked_rem(rhs)) {
21212129
0 => Some(self),

library/core/tests/num/i128.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
int_module!(i128, i128);
1+
int_module!(i128);

library/core/tests/num/i16.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
int_module!(i16, i16);
1+
int_module!(i16);

library/core/tests/num/i32.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
int_module!(i32, i32);
1+
int_module!(i32);
22

33
#[test]
44
fn test_arith_operation() {

library/core/tests/num/i64.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
int_module!(i64, i64);
1+
int_module!(i64);

library/core/tests/num/i8.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
int_module!(i8, i8);
1+
int_module!(i8);

library/core/tests/num/int_macros.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
macro_rules! int_module {
2-
($T:ident, $T_i:ident) => {
2+
($T:ident) => {
33
#[cfg(test)]
44
mod tests {
55
use core::ops::{BitAnd, BitOr, BitXor, Not, Shl, Shr};
6-
use core::$T_i::*;
6+
use core::$T::*;
77

88
use crate::num;
99

library/core/tests/num/u128.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
uint_module!(u128, u128);
1+
uint_module!(u128);

library/core/tests/num/u16.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
uint_module!(u16, u16);
1+
uint_module!(u16);

library/core/tests/num/u32.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
uint_module!(u32, u32);
1+
uint_module!(u32);

library/core/tests/num/u64.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
uint_module!(u64, u64);
1+
uint_module!(u64);

library/core/tests/num/u8.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
uint_module!(u8, u8);
1+
uint_module!(u8);

library/core/tests/num/uint_macros.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
macro_rules! uint_module {
2-
($T:ident, $T_i:ident) => {
2+
($T:ident) => {
33
#[cfg(test)]
44
mod tests {
55
use core::ops::{BitAnd, BitOr, BitXor, Not, Shl, Shr};
6-
use core::$T_i::*;
6+
use core::$T::*;
77
use std::str::FromStr;
88

99
use crate::num;

0 commit comments

Comments
 (0)