@@ -1027,7 +1027,7 @@ macro_rules! uint_impl {
1027
1027
///
1028
1028
/// # Safety
1029
1029
///
1030
- /// This results in undefined behavior when `rhs == 0`
1030
+ /// This results in undefined behavior when `rhs == 0`,
1031
1031
/// i.e. when [`checked_div`] would return `None`.
1032
1032
///
1033
1033
/// [`unwrap_unchecked`]: option/enum.Option.html#method.unwrap_unchecked
@@ -1169,6 +1169,33 @@ macro_rules! uint_impl {
1169
1169
}
1170
1170
}
1171
1171
1172
+ /// Unchecked integer remainder. Computes `self % rhs`, assuming `rhs` is not zero.
1173
+ ///
1174
+ /// # Safety
1175
+ ///
1176
+ /// This results in undefined behavior when `rhs == 0`,
1177
+ /// i.e. when [`checked_rem`] would return `None`.
1178
+ ///
1179
+ #[ doc = concat!( "[`checked_rem`]: " , stringify!( $SelfT) , "::checked_rem" ) ]
1180
+ #[ unstable( feature = "unchecked_div_rem" , issue = "136716" ) ]
1181
+ #[ must_use = "this returns the result of the operation, \
1182
+ without modifying the original"]
1183
+ #[ cfg_attr( miri, track_caller) ] // even without panics, this helps for Miri backtraces
1184
+ pub const unsafe fn unchecked_rem( self , rhs: Self ) -> Self {
1185
+ assert_unsafe_precondition!(
1186
+ check_language_ub,
1187
+ concat!( stringify!( $SelfT) , "::unchecked_rem cannot divide by zero" ) ,
1188
+ (
1189
+ rhs: $SelfT = rhs
1190
+ ) => rhs != 0 ,
1191
+ ) ;
1192
+
1193
+ // SAFETY: this is guaranteed to be safe by the caller.
1194
+ unsafe {
1195
+ intrinsics:: unchecked_rem( self , rhs)
1196
+ }
1197
+ }
1198
+
1172
1199
/// Strict integer remainder. Computes `self % rhs`.
1173
1200
///
1174
1201
/// Strict remainder calculation on unsigned types is just the regular
0 commit comments