@@ -3,21 +3,26 @@ macro_rules! int_impl {
3
3
Self = $SelfT: ty,
4
4
ActualT = $ActualT: ident,
5
5
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,
18
23
to_xe_bytes_doc = $to_xe_bytes_doc: expr,
19
24
from_xe_bytes_doc = $from_xe_bytes_doc: expr,
20
- bound_condition = $bound_condition: expr ,
25
+ bound_condition = $bound_condition: literal ,
21
26
) => {
22
27
/// The smallest value that can be represented by this integer type
23
28
#[ doc = concat!( "(−2<sup>" , $BITS_MINUS_ONE, "</sup>" , $bound_condition, ")." ) ]
@@ -30,7 +35,7 @@ macro_rules! int_impl {
30
35
#[ doc = concat!( "assert_eq!(" , stringify!( $SelfT) , "::MIN, " , stringify!( $Min) , ");" ) ]
31
36
/// ```
32
37
#[ 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 ;
34
39
35
40
/// The largest value that can be represented by this integer type
36
41
#[ doc = concat!( "(2<sup>" , $BITS_MINUS_ONE, "</sup> − 1" , $bound_condition, ")." ) ]
@@ -43,7 +48,7 @@ macro_rules! int_impl {
43
48
#[ doc = concat!( "assert_eq!(" , stringify!( $SelfT) , "::MAX, " , stringify!( $Max) , ");" ) ]
44
49
/// ```
45
50
#[ 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 ;
47
52
48
53
/// The size of this integer type in bits.
49
54
///
@@ -53,7 +58,7 @@ macro_rules! int_impl {
53
58
#[ doc = concat!( "assert_eq!(" , stringify!( $SelfT) , "::BITS, " , stringify!( $BITS) , ");" ) ]
54
59
/// ```
55
60
#[ stable( feature = "int_bits_const" , since = "1.53.0" ) ]
56
- pub const BITS : u32 = $ BITS;
61
+ pub const BITS : u32 = <$UnsignedT> :: BITS ;
57
62
58
63
/// Converts a string slice in a given base to an integer.
59
64
///
@@ -1380,7 +1385,7 @@ macro_rules! int_impl {
1380
1385
// SAFETY: the masking by the bitsize of the type ensures that we do not shift
1381
1386
// out of bounds
1382
1387
unsafe {
1383
- self . unchecked_shl( rhs & ( $ BITS - 1 ) )
1388
+ self . unchecked_shl( rhs & ( Self :: BITS - 1 ) )
1384
1389
}
1385
1390
}
1386
1391
@@ -1410,7 +1415,7 @@ macro_rules! int_impl {
1410
1415
// SAFETY: the masking by the bitsize of the type ensures that we do not shift
1411
1416
// out of bounds
1412
1417
unsafe {
1413
- self . unchecked_shr( rhs & ( $ BITS - 1 ) )
1418
+ self . unchecked_shr( rhs & ( Self :: BITS - 1 ) )
1414
1419
}
1415
1420
}
1416
1421
@@ -1916,7 +1921,7 @@ macro_rules! int_impl {
1916
1921
without modifying the original"]
1917
1922
#[ inline]
1918
1923
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 )
1920
1925
}
1921
1926
1922
1927
/// Shifts self right by `rhs` bits.
@@ -1939,7 +1944,7 @@ macro_rules! int_impl {
1939
1944
without modifying the original"]
1940
1945
#[ inline]
1941
1946
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 )
1943
1948
}
1944
1949
1945
1950
/// Computes the absolute value of `self`.
0 commit comments