@@ -471,7 +471,7 @@ macro_rules! int_impl {
471471 ) ]
472472 #[ must_use = "this returns the result of the operation, \
473473 without modifying the original"]
474- #[ rustc_const_unstable( feature = "const_inherent_unchecked_arith " , issue = "85122" ) ]
474+ #[ rustc_const_unstable( feature = "unchecked_math " , issue = "85122" ) ]
475475 #[ inline( always) ]
476476 #[ cfg_attr( miri, track_caller) ] // even without panics, this helps for Miri backtraces
477477 pub const unsafe fn unchecked_add( self , rhs: Self ) -> Self {
@@ -539,7 +539,7 @@ macro_rules! int_impl {
539539 ) ]
540540 #[ must_use = "this returns the result of the operation, \
541541 without modifying the original"]
542- #[ rustc_const_unstable( feature = "const_inherent_unchecked_arith " , issue = "85122" ) ]
542+ #[ rustc_const_unstable( feature = "unchecked_math " , issue = "85122" ) ]
543543 #[ inline( always) ]
544544 #[ cfg_attr( miri, track_caller) ] // even without panics, this helps for Miri backtraces
545545 pub const unsafe fn unchecked_sub( self , rhs: Self ) -> Self {
@@ -607,7 +607,7 @@ macro_rules! int_impl {
607607 ) ]
608608 #[ must_use = "this returns the result of the operation, \
609609 without modifying the original"]
610- #[ rustc_const_unstable( feature = "const_inherent_unchecked_arith " , issue = "85122" ) ]
610+ #[ rustc_const_unstable( feature = "unchecked_math " , issue = "85122" ) ]
611611 #[ inline( always) ]
612612 #[ cfg_attr( miri, track_caller) ] // even without panics, this helps for Miri backtraces
613613 pub const unsafe fn unchecked_mul( self , rhs: Self ) -> Self {
@@ -740,6 +740,31 @@ macro_rules! int_impl {
740740 if unlikely!( b) { None } else { Some ( a) }
741741 }
742742
743+ /// Unchecked negation. Computes `-self`, assuming overflow cannot occur.
744+ ///
745+ /// # Safety
746+ ///
747+ /// This results in undefined behavior when
748+ #[ doc = concat!( "`self == " , stringify!( $SelfT) , "::MIN`," ) ]
749+ /// i.e. when [`checked_neg`] would return `None`.
750+ ///
751+ #[ doc = concat!( "[`checked_neg`]: " , stringify!( $SelfT) , "::checked_neg" ) ]
752+ #[ unstable(
753+ feature = "unchecked_neg" ,
754+ reason = "niche optimization path" ,
755+ issue = "85122" ,
756+ ) ]
757+ #[ must_use = "this returns the result of the operation, \
758+ without modifying the original"]
759+ #[ rustc_const_unstable( feature = "unchecked_neg" , issue = "85122" ) ]
760+ #[ inline( always) ]
761+ #[ cfg_attr( miri, track_caller) ] // even without panics, this helps for Miri backtraces
762+ pub const unsafe fn unchecked_neg( self ) -> Self {
763+ // SAFETY: the caller must uphold the safety contract for
764+ // `unchecked_neg`.
765+ unsafe { intrinsics:: unchecked_sub( 0 , self ) }
766+ }
767+
743768 /// Checked shift left. Computes `self << rhs`, returning `None` if `rhs` is larger
744769 /// than or equal to the number of bits in `self`.
745770 ///
@@ -772,13 +797,13 @@ macro_rules! int_impl {
772797 ///
773798 #[ doc = concat!( "[`checked_shl`]: " , stringify!( $SelfT) , "::checked_shl" ) ]
774799 #[ unstable(
775- feature = "unchecked_math " ,
800+ feature = "unchecked_shifts " ,
776801 reason = "niche optimization path" ,
777802 issue = "85122" ,
778803 ) ]
779804 #[ must_use = "this returns the result of the operation, \
780805 without modifying the original"]
781- #[ rustc_const_unstable( feature = "const_inherent_unchecked_arith " , issue = "85122" ) ]
806+ #[ rustc_const_unstable( feature = "unchecked_shifts " , issue = "85122" ) ]
782807 #[ inline( always) ]
783808 #[ cfg_attr( miri, track_caller) ] // even without panics, this helps for Miri backtraces
784809 pub const unsafe fn unchecked_shl( self , rhs: u32 ) -> Self {
@@ -820,13 +845,13 @@ macro_rules! int_impl {
820845 ///
821846 #[ doc = concat!( "[`checked_shr`]: " , stringify!( $SelfT) , "::checked_shr" ) ]
822847 #[ unstable(
823- feature = "unchecked_math " ,
848+ feature = "unchecked_shifts " ,
824849 reason = "niche optimization path" ,
825850 issue = "85122" ,
826851 ) ]
827852 #[ must_use = "this returns the result of the operation, \
828853 without modifying the original"]
829- #[ rustc_const_unstable( feature = "const_inherent_unchecked_arith " , issue = "85122" ) ]
854+ #[ rustc_const_unstable( feature = "unchecked_shifts " , issue = "85122" ) ]
830855 #[ inline( always) ]
831856 #[ cfg_attr( miri, track_caller) ] // even without panics, this helps for Miri backtraces
832857 pub const unsafe fn unchecked_shr( self , rhs: u32 ) -> Self {
@@ -1380,7 +1405,7 @@ macro_rules! int_impl {
13801405 #[ must_use = "this returns the result of the operation, \
13811406 without modifying the original"]
13821407 #[ inline( always) ]
1383- #[ rustc_allow_const_fn_unstable( const_inherent_unchecked_arith ) ]
1408+ #[ rustc_allow_const_fn_unstable( unchecked_shifts ) ]
13841409 pub const fn wrapping_shl( self , rhs: u32 ) -> Self {
13851410 // SAFETY: the masking by the bitsize of the type ensures that we do not shift
13861411 // out of bounds
@@ -1410,7 +1435,7 @@ macro_rules! int_impl {
14101435 #[ must_use = "this returns the result of the operation, \
14111436 without modifying the original"]
14121437 #[ inline( always) ]
1413- #[ rustc_allow_const_fn_unstable( const_inherent_unchecked_arith ) ]
1438+ #[ rustc_allow_const_fn_unstable( unchecked_shifts ) ]
14141439 pub const fn wrapping_shr( self , rhs: u32 ) -> Self {
14151440 // SAFETY: the masking by the bitsize of the type ensures that we do not shift
14161441 // out of bounds
0 commit comments