Skip to content

Commit ad3c5a3

Browse files
committed
Auto merge of #128255 - stepancheg:doc-shl, r=scottmcm
Document 0x10.checked_shl(BITS - 1) does not overflow Not obvious.
2 parents a526d7c + 723336d commit ad3c5a3

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

library/core/src/num/int_macros.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1223,6 +1223,7 @@ macro_rules! int_impl {
12231223
/// ```
12241224
#[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".checked_shl(4), Some(0x10));")]
12251225
#[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".checked_shl(129), None);")]
1226+
#[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".checked_shl(", stringify!($BITS_MINUS_ONE), "), Some(0));")]
12261227
/// ```
12271228
#[stable(feature = "wrapping", since = "1.7.0")]
12281229
#[rustc_const_stable(feature = "const_checked_int_methods", since = "1.47.0")]
@@ -2600,6 +2601,7 @@ macro_rules! int_impl {
26002601
/// ```
26012602
#[doc = concat!("assert_eq!(0x1", stringify!($SelfT),".overflowing_shl(4), (0x10, false));")]
26022603
/// assert_eq!(0x1i32.overflowing_shl(36), (0x10, true));
2604+
#[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".overflowing_shl(", stringify!($BITS_MINUS_ONE), "), (0, false));")]
26032605
/// ```
26042606
#[stable(feature = "wrapping", since = "1.7.0")]
26052607
#[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]

library/core/src/num/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ impl u8 {
483483
ActualT = u8,
484484
SignedT = i8,
485485
BITS = 8,
486+
BITS_MINUS_ONE = 7,
486487
MAX = 255,
487488
rot = 2,
488489
rot_op = "0x82",
@@ -1097,6 +1098,7 @@ impl u16 {
10971098
ActualT = u16,
10981099
SignedT = i16,
10991100
BITS = 16,
1101+
BITS_MINUS_ONE = 15,
11001102
MAX = 65535,
11011103
rot = 4,
11021104
rot_op = "0xa003",
@@ -1145,6 +1147,7 @@ impl u32 {
11451147
ActualT = u32,
11461148
SignedT = i32,
11471149
BITS = 32,
1150+
BITS_MINUS_ONE = 31,
11481151
MAX = 4294967295,
11491152
rot = 8,
11501153
rot_op = "0x10000b3",
@@ -1168,6 +1171,7 @@ impl u64 {
11681171
ActualT = u64,
11691172
SignedT = i64,
11701173
BITS = 64,
1174+
BITS_MINUS_ONE = 63,
11711175
MAX = 18446744073709551615,
11721176
rot = 12,
11731177
rot_op = "0xaa00000000006e1",
@@ -1191,6 +1195,7 @@ impl u128 {
11911195
ActualT = u128,
11921196
SignedT = i128,
11931197
BITS = 128,
1198+
BITS_MINUS_ONE = 127,
11941199
MAX = 340282366920938463463374607431768211455,
11951200
rot = 16,
11961201
rot_op = "0x13f40000000000000000000000004f76",
@@ -1216,6 +1221,7 @@ impl usize {
12161221
ActualT = u16,
12171222
SignedT = isize,
12181223
BITS = 16,
1224+
BITS_MINUS_ONE = 15,
12191225
MAX = 65535,
12201226
rot = 4,
12211227
rot_op = "0xa003",
@@ -1240,6 +1246,7 @@ impl usize {
12401246
ActualT = u32,
12411247
SignedT = isize,
12421248
BITS = 32,
1249+
BITS_MINUS_ONE = 31,
12431250
MAX = 4294967295,
12441251
rot = 8,
12451252
rot_op = "0x10000b3",
@@ -1264,6 +1271,7 @@ impl usize {
12641271
ActualT = u64,
12651272
SignedT = isize,
12661273
BITS = 64,
1274+
BITS_MINUS_ONE = 63,
12671275
MAX = 18446744073709551615,
12681276
rot = 12,
12691277
rot_op = "0xaa00000000006e1",

library/core/src/num/uint_macros.rs

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ macro_rules! uint_impl {
99
// literal is fine if they need to be multiple code tokens.
1010
// In non-comments, use the associated constants rather than these.
1111
BITS = $BITS:literal,
12+
BITS_MINUS_ONE = $BITS_MINUS_ONE:literal,
1213
MAX = $MaxV:literal,
1314
rot = $rot:literal,
1415
rot_op = $rot_op:literal,
@@ -1413,6 +1414,7 @@ macro_rules! uint_impl {
14131414
/// ```
14141415
#[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".checked_shl(4), Some(0x10));")]
14151416
#[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".checked_shl(129), None);")]
1417+
#[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".checked_shl(", stringify!($BITS_MINUS_ONE), "), Some(0));")]
14161418
/// ```
14171419
#[stable(feature = "wrapping", since = "1.7.0")]
14181420
#[rustc_const_stable(feature = "const_checked_int_methods", since = "1.47.0")]
@@ -2541,6 +2543,7 @@ macro_rules! uint_impl {
25412543
/// ```
25422544
#[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".overflowing_shl(4), (0x10, false));")]
25432545
#[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".overflowing_shl(132), (0x10, true));")]
2546+
#[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".overflowing_shl(", stringify!($BITS_MINUS_ONE), "), (0, false));")]
25442547
/// ```
25452548
#[stable(feature = "wrapping", since = "1.7.0")]
25462549
#[rustc_const_stable(feature = "const_wrapping_math", since = "1.32.0")]

0 commit comments

Comments
 (0)