@@ -471,7 +471,7 @@ macro_rules! int_impl {
471
471
) ]
472
472
#[ must_use = "this returns the result of the operation, \
473
473
without modifying the original"]
474
- #[ rustc_const_unstable( feature = "const_inherent_unchecked_arith " , issue = "85122" ) ]
474
+ #[ rustc_const_unstable( feature = "unchecked_math " , issue = "85122" ) ]
475
475
#[ inline( always) ]
476
476
#[ cfg_attr( miri, track_caller) ] // even without panics, this helps for Miri backtraces
477
477
pub const unsafe fn unchecked_add( self , rhs: Self ) -> Self {
@@ -539,7 +539,7 @@ macro_rules! int_impl {
539
539
) ]
540
540
#[ must_use = "this returns the result of the operation, \
541
541
without modifying the original"]
542
- #[ rustc_const_unstable( feature = "const_inherent_unchecked_arith " , issue = "85122" ) ]
542
+ #[ rustc_const_unstable( feature = "unchecked_math " , issue = "85122" ) ]
543
543
#[ inline( always) ]
544
544
#[ cfg_attr( miri, track_caller) ] // even without panics, this helps for Miri backtraces
545
545
pub const unsafe fn unchecked_sub( self , rhs: Self ) -> Self {
@@ -607,7 +607,7 @@ macro_rules! int_impl {
607
607
) ]
608
608
#[ must_use = "this returns the result of the operation, \
609
609
without modifying the original"]
610
- #[ rustc_const_unstable( feature = "const_inherent_unchecked_arith " , issue = "85122" ) ]
610
+ #[ rustc_const_unstable( feature = "unchecked_math " , issue = "85122" ) ]
611
611
#[ inline( always) ]
612
612
#[ cfg_attr( miri, track_caller) ] // even without panics, this helps for Miri backtraces
613
613
pub const unsafe fn unchecked_mul( self , rhs: Self ) -> Self {
@@ -740,6 +740,31 @@ macro_rules! int_impl {
740
740
if unlikely!( b) { None } else { Some ( a) }
741
741
}
742
742
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
+
743
768
/// Checked shift left. Computes `self << rhs`, returning `None` if `rhs` is larger
744
769
/// than or equal to the number of bits in `self`.
745
770
///
@@ -772,13 +797,13 @@ macro_rules! int_impl {
772
797
///
773
798
#[ doc = concat!( "[`checked_shl`]: " , stringify!( $SelfT) , "::checked_shl" ) ]
774
799
#[ unstable(
775
- feature = "unchecked_math " ,
800
+ feature = "unchecked_shifts " ,
776
801
reason = "niche optimization path" ,
777
802
issue = "85122" ,
778
803
) ]
779
804
#[ must_use = "this returns the result of the operation, \
780
805
without modifying the original"]
781
- #[ rustc_const_unstable( feature = "const_inherent_unchecked_arith " , issue = "85122" ) ]
806
+ #[ rustc_const_unstable( feature = "unchecked_shifts " , issue = "85122" ) ]
782
807
#[ inline( always) ]
783
808
#[ cfg_attr( miri, track_caller) ] // even without panics, this helps for Miri backtraces
784
809
pub const unsafe fn unchecked_shl( self , rhs: u32 ) -> Self {
@@ -820,13 +845,13 @@ macro_rules! int_impl {
820
845
///
821
846
#[ doc = concat!( "[`checked_shr`]: " , stringify!( $SelfT) , "::checked_shr" ) ]
822
847
#[ unstable(
823
- feature = "unchecked_math " ,
848
+ feature = "unchecked_shifts " ,
824
849
reason = "niche optimization path" ,
825
850
issue = "85122" ,
826
851
) ]
827
852
#[ must_use = "this returns the result of the operation, \
828
853
without modifying the original"]
829
- #[ rustc_const_unstable( feature = "const_inherent_unchecked_arith " , issue = "85122" ) ]
854
+ #[ rustc_const_unstable( feature = "unchecked_shifts " , issue = "85122" ) ]
830
855
#[ inline( always) ]
831
856
#[ cfg_attr( miri, track_caller) ] // even without panics, this helps for Miri backtraces
832
857
pub const unsafe fn unchecked_shr( self , rhs: u32 ) -> Self {
@@ -1404,7 +1429,7 @@ macro_rules! int_impl {
1404
1429
#[ must_use = "this returns the result of the operation, \
1405
1430
without modifying the original"]
1406
1431
#[ inline( always) ]
1407
- #[ rustc_allow_const_fn_unstable( const_inherent_unchecked_arith ) ]
1432
+ #[ rustc_allow_const_fn_unstable( unchecked_shifts ) ]
1408
1433
pub const fn wrapping_shl( self , rhs: u32 ) -> Self {
1409
1434
// SAFETY: the masking by the bitsize of the type ensures that we do not shift
1410
1435
// out of bounds
@@ -1434,7 +1459,7 @@ macro_rules! int_impl {
1434
1459
#[ must_use = "this returns the result of the operation, \
1435
1460
without modifying the original"]
1436
1461
#[ inline( always) ]
1437
- #[ rustc_allow_const_fn_unstable( const_inherent_unchecked_arith ) ]
1462
+ #[ rustc_allow_const_fn_unstable( unchecked_shifts ) ]
1438
1463
pub const fn wrapping_shr( self , rhs: u32 ) -> Self {
1439
1464
// SAFETY: the masking by the bitsize of the type ensures that we do not shift
1440
1465
// out of bounds
0 commit comments