@@ -2279,9 +2279,8 @@ macro_rules! int_impl {
2279
2279
///
2280
2280
/// # Panics
2281
2281
///
2282
- /// When the number is negative, zero, or if the base is not at least 2; it
2283
- /// panics in debug mode and the return value is 0 in release
2284
- /// mode.
2282
+ /// This function will panic if `self` is less than or equal to zero,
2283
+ /// or if `base` is less then 2.
2285
2284
///
2286
2285
/// # Examples
2287
2286
///
@@ -2297,24 +2296,15 @@ macro_rules! int_impl {
2297
2296
#[ rustc_inherit_overflow_checks]
2298
2297
#[ allow( arithmetic_overflow) ]
2299
2298
pub const fn ilog( self , base: Self ) -> u32 {
2300
- match self . checked_ilog( base) {
2301
- Some ( n) => n,
2302
- None => {
2303
- // In debug builds, trigger a panic on None.
2304
- // This should optimize completely out in release builds.
2305
- let _ = Self :: MAX + 1 ;
2306
-
2307
- 0
2308
- } ,
2309
- }
2299
+ assert!( base >= 2 , "base of integer logarithm must be at least 2" ) ;
2300
+ self . checked_ilog( base) . expect( "argument of integer logarithm must be positive" )
2310
2301
}
2311
2302
2312
2303
/// Returns the base 2 logarithm of the number, rounded down.
2313
2304
///
2314
2305
/// # Panics
2315
2306
///
2316
- /// When the number is negative or zero it panics in debug mode and the return value
2317
- /// is 0 in release mode.
2307
+ /// This function will panic if `self` is less than or equal to zero.
2318
2308
///
2319
2309
/// # Examples
2320
2310
///
@@ -2330,24 +2320,14 @@ macro_rules! int_impl {
2330
2320
#[ rustc_inherit_overflow_checks]
2331
2321
#[ allow( arithmetic_overflow) ]
2332
2322
pub const fn ilog2( self ) -> u32 {
2333
- match self . checked_ilog2( ) {
2334
- Some ( n) => n,
2335
- None => {
2336
- // In debug builds, trigger a panic on None.
2337
- // This should optimize completely out in release builds.
2338
- let _ = Self :: MAX + 1 ;
2339
-
2340
- 0
2341
- } ,
2342
- }
2323
+ self . checked_ilog2( ) . expect( "argument of integer logarithm must be positive" )
2343
2324
}
2344
2325
2345
2326
/// Returns the base 10 logarithm of the number, rounded down.
2346
2327
///
2347
2328
/// # Panics
2348
2329
///
2349
- /// When the number is negative or zero it panics in debug mode and the return value
2350
- /// is 0 in release mode.
2330
+ /// This function will panic if `self` is less than or equal to zero.
2351
2331
///
2352
2332
/// # Example
2353
2333
///
@@ -2363,16 +2343,7 @@ macro_rules! int_impl {
2363
2343
#[ rustc_inherit_overflow_checks]
2364
2344
#[ allow( arithmetic_overflow) ]
2365
2345
pub const fn ilog10( self ) -> u32 {
2366
- match self . checked_ilog10( ) {
2367
- Some ( n) => n,
2368
- None => {
2369
- // In debug builds, trigger a panic on None.
2370
- // This should optimize completely out in release builds.
2371
- let _ = Self :: MAX + 1 ;
2372
-
2373
- 0
2374
- } ,
2375
- }
2346
+ self . checked_ilog10( ) . expect( "argument of integer logarithm must be positive" )
2376
2347
}
2377
2348
2378
2349
/// Returns the logarithm of the number with respect to an arbitrary base,
0 commit comments