diff --git a/library/backtrace b/library/backtrace index 72265bea21089..5e05efa87905f 160000 --- a/library/backtrace +++ b/library/backtrace @@ -1 +1 @@ -Subproject commit 72265bea210891ae47bbe6d4f17b493ef0606619 +Subproject commit 5e05efa87905fb5b351a2bc5644d60c57d6d9327 diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs index d40e02352a1d0..68382e506285b 100644 --- a/library/core/src/num/int_macros.rs +++ b/library/core/src/num/int_macros.rs @@ -2906,6 +2906,45 @@ macro_rules! int_impl { } } + /// Calculates the remainder of `self / rhs` if the quotient is rounded toward negative infinity. + /// + /// # Panics + /// + /// 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 + /// + /// Basic usage: + /// + /// ``` + /// #![feature(int_roundings)] + #[doc = concat!("let a: ", stringify!($SelfT)," = 8;")] + /// let b = 3; + /// + /// assert_eq!(a.rem_floor(b), 2); + /// assert_eq!(a.rem_floor(-b), -1); + /// assert_eq!((-a).rem_floor(b), 1); + /// assert_eq!((-a).rem_floor(-b), -2); + /// ``` + #[unstable(feature = "int_roundings", issue = "88581")] + #[must_use = "this returns the result of the operation, \ + without modifying the original"] + #[inline] + #[rustc_inherit_overflow_checks] + pub const fn rem_floor(self, rhs: Self) -> Self { + let r = self % rhs; + if (r > 0 && rhs < 0) || (r < 0 && rhs > 0) { + r + rhs + } else { + r + } + } + /// Calculates the quotient of `self` and `rhs`, rounding the result towards positive infinity. /// /// # Panics @@ -2942,6 +2981,48 @@ macro_rules! int_impl { } } + /// Calculates the remainder of `self / rhs` if the quotient is rounded towards positive infinity. + /// + /// This operation is *only* available for signed integers, + /// since the result would be negative if both operands are positive. + /// + /// # Panics + /// + /// 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 + /// + /// Basic usage: + /// + /// ``` + /// #![feature(rem_ceil)] + #[doc = concat!("let a: ", stringify!($SelfT)," = 8;")] + /// let b = 3; + /// + /// assert_eq!(a.rem_ceil(b), -1); + /// assert_eq!(a.rem_ceil(-b), 2); + /// assert_eq!((-a).rem_ceil(b), -2); + /// assert_eq!((-a).rem_ceil(-b), 1); + /// ``` + #[unstable(feature = "rem_ceil", issue = "88581")] + #[must_use = "this returns the result of the operation, \ + without modifying the original"] + #[inline] + #[rustc_inherit_overflow_checks] + pub const fn rem_ceil(self, rhs: Self) -> Self { + let r = self % rhs; + if (r > 0 && rhs > 0) || (r < 0 && rhs < 0) { + r - rhs + } else { + r + } + } + /// If `rhs` is positive, calculates the smallest value greater than or /// equal to `self` that is a multiple of `rhs`. If `rhs` is negative, /// calculates the largest value less than or equal to `self` that is a diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index ad72c29758bd7..ce7d5cadca65d 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -2704,6 +2704,32 @@ macro_rules! uint_impl { self / rhs } + /// Calculates the remainder of `self / rhs` if the quotient is rounded toward negative infinity. + /// + /// This is the same as performing `self % rhs` for all unsigned integers. + /// + /// # Panics + /// + /// This function will panic if `rhs` is zero. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// #![feature(int_roundings)] + #[doc = concat!("assert_eq!(7_", stringify!($SelfT), ".rem_floor(4), 3);")] + /// ``` + #[unstable(feature = "int_roundings", issue = "88581")] + #[must_use = "this returns the result of the operation, \ + without modifying the original"] + #[inline] + #[rustc_inherit_overflow_checks] + pub const fn rem_floor(self, rhs: Self) -> Self { + self % rhs + } + + /// Calculates the quotient of `self` and `rhs`, rounding the result towards positive infinity. /// /// # Panics @@ -2733,6 +2759,44 @@ macro_rules! uint_impl { } } + /// Calculates the remainder of `self / rhs` if the quotient is rounded towards positive infinity. + /// + /// Since this remainder can never be positive, we return the opposite of the actual remainder. + /// If you want the sign to reflect the actual remainder, you need to use the [signed version]. + /// + #[doc = concat!("[signed version]: primitive.", stringify!($SignedT), ".html#method.rem_ceil")] + /// + /// # Panics + /// + /// 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 + /// + /// Basic usage: + /// + /// ``` + /// #![feature(rem_ceil)] + #[doc = concat!("assert_eq!(7_", stringify!($SelfT), ".unsigned_rem_ceil(4), 1);")] + /// ``` + #[unstable(feature = "rem_ceil", issue = "88581")] + #[must_use = "this returns the result of the operation, \ + without modifying the original"] + #[inline] + #[rustc_inherit_overflow_checks] + pub const fn unsigned_rem_ceil(self, rhs: Self) -> Self { + let r = self % rhs; + if r != 0 { + rhs - r + } else { + r + } + } + /// Calculates the smallest value greater than or equal to `self` that /// is a multiple of `rhs`. /// diff --git a/src/doc/book b/src/doc/book index 45c1a6d69edfd..5e9051f71638a 160000 --- a/src/doc/book +++ b/src/doc/book @@ -1 +1 @@ -Subproject commit 45c1a6d69edfd1fc91fb7504cb73958dbd09441e +Subproject commit 5e9051f71638aa941cd5dda465e25c61cde9594f diff --git a/src/doc/edition-guide b/src/doc/edition-guide index cb58c430b4e80..0c68e90acaae5 160000 --- a/src/doc/edition-guide +++ b/src/doc/edition-guide @@ -1 +1 @@ -Subproject commit cb58c430b4e8054c2cb81d2d4434092c482a93d8 +Subproject commit 0c68e90acaae5a611f8f5098a3c2980de9845ab2 diff --git a/src/doc/embedded-book b/src/doc/embedded-book index b10c6acaf0f43..dd962bb82865a 160000 --- a/src/doc/embedded-book +++ b/src/doc/embedded-book @@ -1 +1 @@ -Subproject commit b10c6acaf0f43481f6600e95d4b5013446e29f7a +Subproject commit dd962bb82865a5284f2404e5234f1e3222b9c022 diff --git a/src/doc/nomicon b/src/doc/nomicon index 0ebdacadbda8c..0d5f88475fe28 160000 --- a/src/doc/nomicon +++ b/src/doc/nomicon @@ -1 +1 @@ -Subproject commit 0ebdacadbda8ce2cd8fbf93985e15af61a7ab895 +Subproject commit 0d5f88475fe285affa6dbbc806e9e44d730797c0 diff --git a/src/doc/reference b/src/doc/reference index 0b805c6580401..e356977fceaa8 160000 --- a/src/doc/reference +++ b/src/doc/reference @@ -1 +1 @@ -Subproject commit 0b805c65804019b0ac8f2fe3117afad82a6069b8 +Subproject commit e356977fceaa8591c762312d8d446769166d4b3e diff --git a/src/doc/rust-by-example b/src/doc/rust-by-example index b1d97bd6113ab..20482893d1a50 160000 --- a/src/doc/rust-by-example +++ b/src/doc/rust-by-example @@ -1 +1 @@ -Subproject commit b1d97bd6113aba732b2091ce093c76f2d05bb8a0 +Subproject commit 20482893d1a502df72f76762c97aed88854cdf81 diff --git a/src/doc/rustc-dev-guide b/src/doc/rustc-dev-guide index aec82168dd312..b6d4a4940bab8 160000 --- a/src/doc/rustc-dev-guide +++ b/src/doc/rustc-dev-guide @@ -1 +1 @@ -Subproject commit aec82168dd3121289a194b381f56076fc789a4d2 +Subproject commit b6d4a4940bab85cc91eec70cc2e3096dd48da62d diff --git a/src/llvm-project b/src/llvm-project index 5a5152f653959..b31c30a9bb4db 160000 --- a/src/llvm-project +++ b/src/llvm-project @@ -1 +1 @@ -Subproject commit 5a5152f653959d14d68613a3a8a033fb65eec021 +Subproject commit b31c30a9bb4dbbd13c359d0e2bea7f65d20adf3f diff --git a/src/tools/cargo b/src/tools/cargo index 4ed7bee47f7dd..431db31d0dbed 160000 --- a/src/tools/cargo +++ b/src/tools/cargo @@ -1 +1 @@ -Subproject commit 4ed7bee47f7dd4416b36fada1909e9a62c546246 +Subproject commit 431db31d0dbeda320caf8ef8535ea48eb3093407