Skip to content

Commit 0f2eaa2

Browse files
committed
Add additional automatic conversions to usize/isize.
Also, improve the documentation related to the range of usize and isize.
1 parent 7bb0ac5 commit 0f2eaa2

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/libcore/num/mod.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,9 +1473,12 @@ impl fmt::Display for ParseIntError {
14731473

14741474
pub use num::dec2flt::ParseFloatError;
14751475

1476-
// Conversion traits for primitive integer types
1477-
// Conversions T -> T are covered by a blanket impl and therefore excluded
1478-
// Some conversions from and to usize/isize are not implemented due to portability concerns
1476+
// Conversion traits for primitive integer types (only) where the conversion is
1477+
// guaranteed to be lossless on all platforms. Conversions T -> T are covered
1478+
// by a blanket impl and therefore excluded. Conversions from `usize` and
1479+
// `isize` to other types are not implemented because there are no primitive
1480+
// integer types that are defined to be at least as large as them on all
1481+
// architectures.
14791482
macro_rules! impl_from {
14801483
($Small: ty, $Large: ty) => {
14811484
#[stable(feature = "lossless_int_conv", since = "1.5.0")]
@@ -1496,6 +1499,7 @@ impl_from! { u8, u64 }
14961499
impl_from! { u8, usize }
14971500
impl_from! { u16, u32 }
14981501
impl_from! { u16, u64 }
1502+
impl_from! { u16, usize }
14991503
impl_from! { u32, u64 }
15001504

15011505
// Signed -> Signed
@@ -1505,12 +1509,14 @@ impl_from! { i8, i64 }
15051509
impl_from! { i8, isize }
15061510
impl_from! { i16, i32 }
15071511
impl_from! { i16, i64 }
1512+
impl_from! { i16, isize }
15081513
impl_from! { i32, i64 }
15091514

15101515
// Unsigned -> Signed
15111516
impl_from! { u8, i16 }
15121517
impl_from! { u8, i32 }
15131518
impl_from! { u8, i64 }
1519+
impl_from! { u8, isize }
15141520
impl_from! { u16, i32 }
15151521
impl_from! { u16, i64 }
15161522
impl_from! { u32, i64 }

src/libstd/primitive_docs.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,8 @@ mod prim_u64 { }
405405
//
406406
/// The pointer-sized signed integer type.
407407
///
408+
/// `isize` is guaranteed to at least as large as `i16`.
409+
///
408410
/// *[See also the `std::isize` module](isize/index.html).*
409411
///
410412
mod prim_isize { }
@@ -413,6 +415,8 @@ mod prim_isize { }
413415
//
414416
/// The pointer-sized unsigned integer type.
415417
///
418+
/// `usize` is guaranteed to be at least as large as `u16`.
419+
///
416420
/// *[See also the `std::usize` module](usize/index.html).*
417421
///
418422
mod prim_usize { }

0 commit comments

Comments
 (0)