@@ -42,7 +42,8 @@ macro_rules! nonzero_integers {
42
42
pub struct $Ty( $Int) ;
43
43
44
44
impl $Ty {
45
- /// Creates a non-zero without checking the value.
45
+ /// Creates a non-zero without checking whether the value is non-zero.
46
+ /// This results in undefined behaviour if the value is zero.
46
47
///
47
48
/// # Safety
48
49
///
@@ -291,7 +292,9 @@ macro_rules! nonzero_unsigned_operations {
291
292
$(
292
293
impl $Ty {
293
294
/// Add an unsigned integer to a non-zero value.
294
- /// Return [`None`] on overflow.
295
+ /// Check for overflow and return [`None`] on overflow
296
+ /// As a consequence, the result cannot wrap to zero.
297
+ ///
295
298
///
296
299
/// # Examples
297
300
///
@@ -354,7 +357,9 @@ macro_rules! nonzero_unsigned_operations {
354
357
355
358
/// Add an unsigned integer to a non-zero value,
356
359
/// assuming overflow cannot occur.
357
- /// This results in undefined behaviour when
360
+ /// Overflow is unchecked, and it is undefined behaviour to overflow
361
+ /// *even if the result would wrap to a non-zero value*.
362
+ /// The behaviour is undefined as soon as
358
363
#[ doc = concat!( "`self + rhs > " , stringify!( $Int) , "::MAX`" ) ]
359
364
#[ doc = concat!( " or `self + rhs < " , stringify!( $Int) , "::MIN`." ) ]
360
365
///
@@ -381,8 +386,9 @@ macro_rules! nonzero_unsigned_operations {
381
386
}
382
387
383
388
/// Returns the smallest power of two greater than or equal to n.
384
- /// If the next power of two is greater than the type’s maximum value,
385
- /// [`None`] is returned, otherwise the power of two is wrapped in [`Some`].
389
+ /// Check for overflow and return [`None`]
390
+ /// if the next power of two is greater than the type’s maximum value.
391
+ /// As a consequence, the result cannot wrap to zero.
386
392
///
387
393
/// # Examples
388
394
///
@@ -462,8 +468,9 @@ macro_rules! nonzero_signed_operations {
462
468
}
463
469
464
470
/// Checked absolute value.
465
- /// Returns [`None`] if
471
+ /// Check for overflow and returns [`None`] if
466
472
#[ doc = concat!( "`self == " , stringify!( $Int) , "::MIN`." ) ]
473
+ /// The result cannot be zero.
467
474
///
468
475
/// # Example
469
476
///
@@ -647,7 +654,8 @@ macro_rules! nonzero_unsigned_signed_operations {
647
654
$(
648
655
impl $Ty {
649
656
/// Multiply two non-zero integers together.
650
- /// Return [`None`] on overflow.
657
+ /// Check for overflow and return [`None`] on overflow.
658
+ /// As a consequence, the result cannot wrap to zero.
651
659
///
652
660
/// # Examples
653
661
///
@@ -712,7 +720,9 @@ macro_rules! nonzero_unsigned_signed_operations {
712
720
713
721
/// Multiply two non-zero integers together,
714
722
/// assuming overflow cannot occur.
715
- /// This results in undefined behavior when
723
+ /// Overflow is unchecked, and it is undefined behaviour to overflow
724
+ /// *even if the result would wrap to a non-zero value*.
725
+ /// The behaviour is undefined as soon as
716
726
#[ doc = concat!( "`self * rhs > " , stringify!( $Int) , "::MAX`, " ) ]
717
727
#[ doc = concat!( "or `self * rhs < " , stringify!( $Int) , "::MIN`." ) ]
718
728
///
@@ -739,7 +749,8 @@ macro_rules! nonzero_unsigned_signed_operations {
739
749
}
740
750
741
751
/// Raise non-zero value to an integer power.
742
- /// Return [`None`] on overflow.
752
+ /// Check for overflow and return [`None`] on overflow.
753
+ /// As a consequence, the result cannot wrap to zero.
743
754
///
744
755
/// # Examples
745
756
///
0 commit comments