Skip to content

Commit 01a9ff0

Browse files
committed
Clarify that [iu]size bounds were only defined for the target arch
1 parent a51fb2b commit 01a9ff0

File tree

3 files changed

+32
-24
lines changed

3 files changed

+32
-24
lines changed

library/core/src/num/int_macros.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ macro_rules! int_impl {
22
($SelfT:ty, $ActualT:ident, $UnsignedT:ty, $BITS:expr, $BITS_MINUS_ONE:expr, $Min:expr, $Max:expr,
33
$rot:expr, $rot_op:expr, $rot_result:expr, $swap_op:expr, $swapped:expr,
44
$reversed:expr, $le_bytes:expr, $be_bytes:expr,
5-
$to_xe_bytes_doc:expr, $from_xe_bytes_doc:expr) => {
6-
/// The smallest value that can be represented by this integer type,
7-
#[doc = concat!("&minus;2<sup>", $BITS_MINUS_ONE, "</sup>.")]
5+
$to_xe_bytes_doc:expr, $from_xe_bytes_doc:expr,
6+
$bound_condition:expr) => {
7+
/// The smallest value that can be represented by this integer type
8+
#[doc = concat!("(&minus;2<sup>", $BITS_MINUS_ONE, "</sup>", $bound_condition, ")")]
89
///
910
/// # Examples
1011
///
@@ -16,8 +17,8 @@ macro_rules! int_impl {
1617
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
1718
pub const MIN: Self = !0 ^ ((!0 as $UnsignedT) >> 1) as Self;
1819

19-
/// The largest value that can be represented by this integer type,
20-
#[doc = concat!("2<sup>", $BITS_MINUS_ONE, "</sup> &minus; 1.")]
20+
/// The largest value that can be represented by this integer type
21+
#[doc = concat!("(2<sup>", $BITS_MINUS_ONE, "</sup> &minus; 1", $bound_condition, ")")]
2122
///
2223
/// # Examples
2324
///

library/core/src/num/mod.rs

+22-16
Original file line numberDiff line numberDiff line change
@@ -196,25 +196,25 @@ macro_rules! widening_impl {
196196

197197
impl i8 {
198198
int_impl! { i8, i8, u8, 8, 7, -128, 127, 2, "-0x7e", "0xa", "0x12", "0x12", "0x48",
199-
"[0x12]", "[0x12]", "", "" }
199+
"[0x12]", "[0x12]", "", "", "" }
200200
}
201201

202202
impl i16 {
203203
int_impl! { i16, i16, u16, 16, 15, -32768, 32767, 4, "-0x5ffd", "0x3a", "0x1234", "0x3412",
204-
"0x2c48", "[0x34, 0x12]", "[0x12, 0x34]", "", "" }
204+
"0x2c48", "[0x34, 0x12]", "[0x12, 0x34]", "", "", "" }
205205
}
206206

207207
impl i32 {
208208
int_impl! { i32, i32, u32, 32, 31, -2147483648, 2147483647, 8, "0x10000b3", "0xb301",
209209
"0x12345678", "0x78563412", "0x1e6a2c48", "[0x78, 0x56, 0x34, 0x12]",
210-
"[0x12, 0x34, 0x56, 0x78]", "", "" }
210+
"[0x12, 0x34, 0x56, 0x78]", "", "", "" }
211211
}
212212

213213
impl i64 {
214214
int_impl! { i64, i64, u64, 64, 63, -9223372036854775808, 9223372036854775807, 12,
215215
"0xaa00000000006e1", "0x6e10aa", "0x1234567890123456", "0x5634129078563412",
216216
"0x6a2c48091e6a2c48", "[0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12]",
217-
"[0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56]", "", "" }
217+
"[0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56]", "", "", "" }
218218
}
219219

220220
impl i128 {
@@ -225,22 +225,24 @@ impl i128 {
225225
"[0x12, 0x90, 0x78, 0x56, 0x34, 0x12, 0x90, 0x78, \
226226
0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12]",
227227
"[0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, \
228-
0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12]", "", "" }
228+
0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12]", "", "", "" }
229229
}
230230

231231
#[cfg(target_pointer_width = "16")]
232232
impl isize {
233233
int_impl! { isize, i16, usize, 16, 15, -32768, 32767, 4, "-0x5ffd", "0x3a", "0x1234",
234234
"0x3412", "0x2c48", "[0x34, 0x12]", "[0x12, 0x34]",
235-
usize_isize_to_xe_bytes_doc!(), usize_isize_from_xe_bytes_doc!() }
235+
usize_isize_to_xe_bytes_doc!(), usize_isize_from_xe_bytes_doc!(),
236+
" on 16-bit targets" }
236237
}
237238

238239
#[cfg(target_pointer_width = "32")]
239240
impl isize {
240241
int_impl! { isize, i32, usize, 32, 31, -2147483648, 2147483647, 8, "0x10000b3", "0xb301",
241242
"0x12345678", "0x78563412", "0x1e6a2c48", "[0x78, 0x56, 0x34, 0x12]",
242243
"[0x12, 0x34, 0x56, 0x78]",
243-
usize_isize_to_xe_bytes_doc!(), usize_isize_from_xe_bytes_doc!() }
244+
usize_isize_to_xe_bytes_doc!(), usize_isize_from_xe_bytes_doc!(),
245+
" on 32-bit targets" }
244246
}
245247

246248
#[cfg(target_pointer_width = "64")]
@@ -249,15 +251,16 @@ impl isize {
249251
12, "0xaa00000000006e1", "0x6e10aa", "0x1234567890123456", "0x5634129078563412",
250252
"0x6a2c48091e6a2c48", "[0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12]",
251253
"[0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56]",
252-
usize_isize_to_xe_bytes_doc!(), usize_isize_from_xe_bytes_doc!() }
254+
usize_isize_to_xe_bytes_doc!(), usize_isize_from_xe_bytes_doc!(),
255+
" on 64-bit targets" }
253256
}
254257

255258
/// If 6th bit set ascii is upper case.
256259
const ASCII_CASE_MASK: u8 = 0b0010_0000;
257260

258261
impl u8 {
259262
uint_impl! { u8, u8, i8, NonZeroU8, 8, 255, 2, "0x82", "0xa", "0x12", "0x12", "0x48", "[0x12]",
260-
"[0x12]", "", "" }
263+
"[0x12]", "", "", "" }
261264
widening_impl! { u8, u16, 8, unsigned }
262265

263266
/// Checks if the value is within the ASCII range.
@@ -810,7 +813,7 @@ impl u8 {
810813

811814
impl u16 {
812815
uint_impl! { u16, u16, i16, NonZeroU16, 16, 65535, 4, "0xa003", "0x3a", "0x1234", "0x3412", "0x2c48",
813-
"[0x34, 0x12]", "[0x12, 0x34]", "", "" }
816+
"[0x34, 0x12]", "[0x12, 0x34]", "", "", "" }
814817
widening_impl! { u16, u32, 16, unsigned }
815818

816819
/// Checks if the value is a Unicode surrogate code point, which are disallowed values for [`char`].
@@ -841,7 +844,7 @@ impl u16 {
841844

842845
impl u32 {
843846
uint_impl! { u32, u32, i32, NonZeroU32, 32, 4294967295, 8, "0x10000b3", "0xb301", "0x12345678",
844-
"0x78563412", "0x1e6a2c48", "[0x78, 0x56, 0x34, 0x12]", "[0x12, 0x34, 0x56, 0x78]", "", "" }
847+
"0x78563412", "0x1e6a2c48", "[0x78, 0x56, 0x34, 0x12]", "[0x12, 0x34, 0x56, 0x78]", "", "", "" }
845848
widening_impl! { u32, u64, 32, unsigned }
846849
}
847850

@@ -850,7 +853,7 @@ impl u64 {
850853
"0x1234567890123456", "0x5634129078563412", "0x6a2c48091e6a2c48",
851854
"[0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12]",
852855
"[0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56]",
853-
"", ""}
856+
"", "", ""}
854857
widening_impl! { u64, u128, 64, unsigned }
855858
}
856859

@@ -862,21 +865,23 @@ impl u128 {
862865
0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12]",
863866
"[0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, \
864867
0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12]",
865-
"", ""}
868+
"", "", ""}
866869
}
867870

868871
#[cfg(target_pointer_width = "16")]
869872
impl usize {
870873
uint_impl! { usize, u16, isize, NonZeroUsize, 16, 65535, 4, "0xa003", "0x3a", "0x1234", "0x3412", "0x2c48",
871874
"[0x34, 0x12]", "[0x12, 0x34]",
872-
usize_isize_to_xe_bytes_doc!(), usize_isize_from_xe_bytes_doc!() }
875+
usize_isize_to_xe_bytes_doc!(), usize_isize_from_xe_bytes_doc!(),
876+
" on 16-bit targets" }
873877
widening_impl! { usize, u32, 16, unsigned }
874878
}
875879
#[cfg(target_pointer_width = "32")]
876880
impl usize {
877881
uint_impl! { usize, u32, isize, NonZeroUsize, 32, 4294967295, 8, "0x10000b3", "0xb301", "0x12345678",
878882
"0x78563412", "0x1e6a2c48", "[0x78, 0x56, 0x34, 0x12]", "[0x12, 0x34, 0x56, 0x78]",
879-
usize_isize_to_xe_bytes_doc!(), usize_isize_from_xe_bytes_doc!() }
883+
usize_isize_to_xe_bytes_doc!(), usize_isize_from_xe_bytes_doc!(),
884+
" on 32-bit targets" }
880885
widening_impl! { usize, u64, 32, unsigned }
881886
}
882887

@@ -886,7 +891,8 @@ impl usize {
886891
"0x1234567890123456", "0x5634129078563412", "0x6a2c48091e6a2c48",
887892
"[0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12]",
888893
"[0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56]",
889-
usize_isize_to_xe_bytes_doc!(), usize_isize_from_xe_bytes_doc!() }
894+
usize_isize_to_xe_bytes_doc!(), usize_isize_from_xe_bytes_doc!(),
895+
" on 64-bit targets" }
890896
widening_impl! { usize, u128, 64, unsigned }
891897
}
892898

library/core/src/num/uint_macros.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ macro_rules! uint_impl {
33
$BITS:expr, $MaxV:expr,
44
$rot:expr, $rot_op:expr, $rot_result:expr, $swap_op:expr, $swapped:expr,
55
$reversed:expr, $le_bytes:expr, $be_bytes:expr,
6-
$to_xe_bytes_doc:expr, $from_xe_bytes_doc:expr) => {
6+
$to_xe_bytes_doc:expr, $from_xe_bytes_doc:expr,
7+
$bound_condition:expr) => {
78
/// The smallest value that can be represented by this integer type.
89
///
910
/// # Examples
@@ -16,8 +17,8 @@ macro_rules! uint_impl {
1617
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
1718
pub const MIN: Self = 0;
1819

19-
/// The largest value that can be represented by this integer type,
20-
#[doc = concat!("2<sup>", $BITS, "</sup> &minus; 1.")]
20+
/// The largest value that can be represented by this integer type
21+
#[doc = concat!("(2<sup>", $BITS, "</sup> &minus; 1", $bound_condition, ")")]
2122
///
2223
/// # Examples
2324
///

0 commit comments

Comments
 (0)