@@ -417,8 +417,15 @@ macro_rules! uint_impl {
417417 }
418418
419419 /// Unchecked integer addition. Computes `self + rhs`, assuming overflow
420- /// cannot occur. This results in undefined behavior when
421- #[ doc = concat!( "`self + rhs > " , stringify!( $SelfT) , "::MAX` or `self + rhs < " , stringify!( $SelfT) , "::MIN`." ) ]
420+ /// cannot occur.
421+ ///
422+ /// # Safety
423+ ///
424+ /// This results in undefined behavior when
425+ #[ doc = concat!( "`self + rhs > " , stringify!( $SelfT) , "::MAX` or `self + rhs < " , stringify!( $SelfT) , "::MIN`," ) ]
426+ /// i.e. when [`checked_add`] would return `None`.
427+ ///
428+ #[ doc = concat!( "[`checked_add`]: " , stringify!( $SelfT) , "::checked_add" ) ]
422429 #[ unstable(
423430 feature = "unchecked_math" ,
424431 reason = "niche optimization path" ,
@@ -456,8 +463,15 @@ macro_rules! uint_impl {
456463 }
457464
458465 /// Unchecked integer subtraction. Computes `self - rhs`, assuming overflow
459- /// cannot occur. This results in undefined behavior when
460- #[ doc = concat!( "`self - rhs > " , stringify!( $SelfT) , "::MAX` or `self - rhs < " , stringify!( $SelfT) , "::MIN`." ) ]
466+ /// cannot occur.
467+ ///
468+ /// # Safety
469+ ///
470+ /// This results in undefined behavior when
471+ #[ doc = concat!( "`self - rhs > " , stringify!( $SelfT) , "::MAX` or `self - rhs < " , stringify!( $SelfT) , "::MIN`," ) ]
472+ /// i.e. when [`checked_sub`] would return `None`.
473+ ///
474+ #[ doc = concat!( "[`checked_sub`]: " , stringify!( $SelfT) , "::checked_sub" ) ]
461475 #[ unstable(
462476 feature = "unchecked_math" ,
463477 reason = "niche optimization path" ,
@@ -495,8 +509,15 @@ macro_rules! uint_impl {
495509 }
496510
497511 /// Unchecked integer multiplication. Computes `self * rhs`, assuming overflow
498- /// cannot occur. This results in undefined behavior when
499- #[ doc = concat!( "`self * rhs > " , stringify!( $SelfT) , "::MAX` or `self * rhs < " , stringify!( $SelfT) , "::MIN`." ) ]
512+ /// cannot occur.
513+ ///
514+ /// # Safety
515+ ///
516+ /// This results in undefined behavior when
517+ #[ doc = concat!( "`self * rhs > " , stringify!( $SelfT) , "::MAX` or `self * rhs < " , stringify!( $SelfT) , "::MIN`," ) ]
518+ /// i.e. when [`checked_mul`] would return `None`.
519+ ///
520+ #[ doc = concat!( "[`checked_mul`]: " , stringify!( $SelfT) , "::checked_mul" ) ]
500521 #[ unstable(
501522 feature = "unchecked_math" ,
502523 reason = "niche optimization path" ,
@@ -655,6 +676,31 @@ macro_rules! uint_impl {
655676 if unlikely!( b) { None } else { Some ( a) }
656677 }
657678
679+ /// Unchecked shift left. Computes `self << rhs`, assuming that
680+ /// `rhs` is less than the number of bits in `self`.
681+ ///
682+ /// # Safety
683+ ///
684+ /// This results in undefined behavior if `rhs` is larger than
685+ /// or equal to the number of bits in `self`,
686+ /// i.e. when [`checked_shl`] would return `None`.
687+ ///
688+ #[ doc = concat!( "[`checked_shl`]: " , stringify!( $SelfT) , "::checked_shl" ) ]
689+ #[ unstable(
690+ feature = "unchecked_math" ,
691+ reason = "niche optimization path" ,
692+ issue = "85122" ,
693+ ) ]
694+ #[ must_use = "this returns the result of the operation, \
695+ without modifying the original"]
696+ #[ rustc_const_unstable( feature = "const_inherent_unchecked_arith" , issue = "85122" ) ]
697+ #[ inline( always) ]
698+ pub const unsafe fn unchecked_shl( self , rhs: Self ) -> Self {
699+ // SAFETY: the caller must uphold the safety contract for
700+ // `unchecked_shl`.
701+ unsafe { intrinsics:: unchecked_shl( self , rhs) }
702+ }
703+
658704 /// Checked shift right. Computes `self >> rhs`, returning `None`
659705 /// if `rhs` is larger than or equal to the number of bits in `self`.
660706 ///
@@ -676,6 +722,31 @@ macro_rules! uint_impl {
676722 if unlikely!( b) { None } else { Some ( a) }
677723 }
678724
725+ /// Unchecked shift right. Computes `self >> rhs`, assuming that
726+ /// `rhs` is less than the number of bits in `self`.
727+ ///
728+ /// # Safety
729+ ///
730+ /// This results in undefined behavior if `rhs` is larger than
731+ /// or equal to the number of bits in `self`,
732+ /// i.e. when [`checked_shr`] would return `None`.
733+ ///
734+ #[ doc = concat!( "[`checked_shr`]: " , stringify!( $SelfT) , "::checked_shr" ) ]
735+ #[ unstable(
736+ feature = "unchecked_math" ,
737+ reason = "niche optimization path" ,
738+ issue = "85122" ,
739+ ) ]
740+ #[ must_use = "this returns the result of the operation, \
741+ without modifying the original"]
742+ #[ rustc_const_unstable( feature = "const_inherent_unchecked_arith" , issue = "85122" ) ]
743+ #[ inline( always) ]
744+ pub const unsafe fn unchecked_shr( self , rhs: Self ) -> Self {
745+ // SAFETY: the caller must uphold the safety contract for
746+ // `unchecked_shr`.
747+ unsafe { intrinsics:: unchecked_shr( self , rhs) }
748+ }
749+
679750 /// Checked exponentiation. Computes `self.pow(exp)`, returning `None` if
680751 /// overflow occurred.
681752 ///
0 commit comments