@@ -709,6 +709,34 @@ macro_rules! nonzero_unsigned_signed_operations {
709
709
// so the result cannot be zero.
710
710
unsafe { $Ty:: new_unchecked( self . get( ) . saturating_mul( other. get( ) ) ) }
711
711
}
712
+
713
+ /// Multiply two non-zero integers together,
714
+ /// assuming overflow cannot occur.
715
+ /// This results in undefined behavior when
716
+ #[ doc = concat!( "`self * rhs > " , stringify!( $Int) , "::MAX`, " ) ]
717
+ #[ doc = concat!( "or `self * rhs < " , stringify!( $Int) , "::MIN`." ) ]
718
+ ///
719
+ /// # Examples
720
+ ///
721
+ /// ```
722
+ /// #![feature(nonzero_ops)]
723
+ /// # #![feature(try_trait)]
724
+ #[ doc = concat!( "# use std::num::" , stringify!( $Ty) , ";" ) ]
725
+ ///
726
+ /// # fn main() -> Result<(), std::option::NoneError> {
727
+ #[ doc = concat!( "let two = " , stringify!( $Ty) , "::new(2)?;" ) ]
728
+ #[ doc = concat!( "let four = " , stringify!( $Ty) , "::new(4)?;" ) ]
729
+ ///
730
+ /// assert_eq!(four, unsafe { two.unchecked_mul(two) });
731
+ /// # Ok(())
732
+ /// # }
733
+ /// ```
734
+ #[ unstable( feature = "nonzero_ops" , issue = "84186" ) ]
735
+ #[ inline]
736
+ pub unsafe fn unchecked_mul( self , other: $Ty) -> $Ty {
737
+ // SAFETY: The caller ensures there is no overflow.
738
+ unsafe { $Ty:: new_unchecked( self . get( ) . unchecked_mul( other. get( ) ) ) }
739
+ }
712
740
}
713
741
) +
714
742
}
0 commit comments