@@ -3,21 +3,26 @@ macro_rules! int_impl {
33 Self = $SelfT: ty,
44 ActualT = $ActualT: ident,
55 UnsignedT = $UnsignedT: ty,
6- BITS = $BITS: expr,
7- BITS_MINUS_ONE = $BITS_MINUS_ONE: expr,
8- Min = $Min: expr,
9- Max = $Max: expr,
10- rot = $rot: expr,
11- rot_op = $rot_op: expr,
12- rot_result = $rot_result: expr,
13- swap_op = $swap_op: expr,
14- swapped = $swapped: expr,
15- reversed = $reversed: expr,
16- le_bytes = $le_bytes: expr,
17- be_bytes = $be_bytes: expr,
6+
7+ // There are all for use *only* in doc comments.
8+ // As such, they're all passed as literals -- passing them as a string
9+ // literal is fine if they need to be multiple code tokens.
10+ // In non-comments, use the associated constants rather than these.
11+ BITS = $BITS: literal,
12+ BITS_MINUS_ONE = $BITS_MINUS_ONE: literal,
13+ Min = $Min: literal,
14+ Max = $Max: literal,
15+ rot = $rot: literal,
16+ rot_op = $rot_op: literal,
17+ rot_result = $rot_result: literal,
18+ swap_op = $swap_op: literal,
19+ swapped = $swapped: literal,
20+ reversed = $reversed: literal,
21+ le_bytes = $le_bytes: literal,
22+ be_bytes = $be_bytes: literal,
1823 to_xe_bytes_doc = $to_xe_bytes_doc: expr,
1924 from_xe_bytes_doc = $from_xe_bytes_doc: expr,
20- bound_condition = $bound_condition: expr ,
25+ bound_condition = $bound_condition: literal ,
2126 ) => {
2227 /// The smallest value that can be represented by this integer type
2328 #[ doc = concat!( "(−2<sup>" , $BITS_MINUS_ONE, "</sup>" , $bound_condition, ")." ) ]
@@ -30,7 +35,7 @@ macro_rules! int_impl {
3035 #[ doc = concat!( "assert_eq!(" , stringify!( $SelfT) , "::MIN, " , stringify!( $Min) , ");" ) ]
3136 /// ```
3237 #[ stable( feature = "assoc_int_consts" , since = "1.43.0" ) ]
33- pub const MIN : Self = !0 ^ ( ( ! 0 as $UnsignedT ) >> 1 ) as Self ;
38+ pub const MIN : Self = !Self :: MAX ;
3439
3540 /// The largest value that can be represented by this integer type
3641 #[ doc = concat!( "(2<sup>" , $BITS_MINUS_ONE, "</sup> − 1" , $bound_condition, ")." ) ]
@@ -43,7 +48,7 @@ macro_rules! int_impl {
4348 #[ doc = concat!( "assert_eq!(" , stringify!( $SelfT) , "::MAX, " , stringify!( $Max) , ");" ) ]
4449 /// ```
4550 #[ stable( feature = "assoc_int_consts" , since = "1.43.0" ) ]
46- pub const MAX : Self = ! Self :: MIN ;
51+ pub const MAX : Self = ( <$UnsignedT> :: MAX >> 1 ) as Self ;
4752
4853 /// The size of this integer type in bits.
4954 ///
@@ -53,7 +58,7 @@ macro_rules! int_impl {
5358 #[ doc = concat!( "assert_eq!(" , stringify!( $SelfT) , "::BITS, " , stringify!( $BITS) , ");" ) ]
5459 /// ```
5560 #[ stable( feature = "int_bits_const" , since = "1.53.0" ) ]
56- pub const BITS : u32 = $ BITS;
61+ pub const BITS : u32 = <$UnsignedT> :: BITS ;
5762
5863 /// Converts a string slice in a given base to an integer.
5964 ///
@@ -1380,7 +1385,7 @@ macro_rules! int_impl {
13801385 // SAFETY: the masking by the bitsize of the type ensures that we do not shift
13811386 // out of bounds
13821387 unsafe {
1383- self . unchecked_shl( rhs & ( $ BITS - 1 ) )
1388+ self . unchecked_shl( rhs & ( Self :: BITS - 1 ) )
13841389 }
13851390 }
13861391
@@ -1410,7 +1415,7 @@ macro_rules! int_impl {
14101415 // SAFETY: the masking by the bitsize of the type ensures that we do not shift
14111416 // out of bounds
14121417 unsafe {
1413- self . unchecked_shr( rhs & ( $ BITS - 1 ) )
1418+ self . unchecked_shr( rhs & ( Self :: BITS - 1 ) )
14141419 }
14151420 }
14161421
@@ -1916,7 +1921,7 @@ macro_rules! int_impl {
19161921 without modifying the original"]
19171922 #[ inline]
19181923 pub const fn overflowing_shl( self , rhs: u32 ) -> ( Self , bool ) {
1919- ( self . wrapping_shl( rhs) , ( rhs > ( $ BITS - 1 ) ) )
1924+ ( self . wrapping_shl( rhs) , rhs >= Self :: BITS )
19201925 }
19211926
19221927 /// Shifts self right by `rhs` bits.
@@ -1939,7 +1944,7 @@ macro_rules! int_impl {
19391944 without modifying the original"]
19401945 #[ inline]
19411946 pub const fn overflowing_shr( self , rhs: u32 ) -> ( Self , bool ) {
1942- ( self . wrapping_shr( rhs) , ( rhs > ( $ BITS - 1 ) ) )
1947+ ( self . wrapping_shr( rhs) , rhs >= Self :: BITS )
19431948 }
19441949
19451950 /// Computes the absolute value of `self`.
0 commit comments