提交 ed09d6df 编写于 作者: M Mark Simulacrum 提交者: GitHub

Rollup merge of #43471 - ollie27:try_from_ints, r=nagisa

Add missing impl and tests for int to int TryFrom impls

These were missing from #43248.

r? @nagisa
...@@ -2622,8 +2622,11 @@ fn try_from(u: $source) -> Result<$target, TryFromIntError> { ...@@ -2622,8 +2622,11 @@ fn try_from(u: $source) -> Result<$target, TryFromIntError> {
try_from_both_bounded!(i64, u32, u16, u8); try_from_both_bounded!(i64, u32, u16, u8);
try_from_both_bounded!(i128, u64, u32, u16, u8); try_from_both_bounded!(i128, u64, u32, u16, u8);
#[unstable(feature = "try_from", issue = "33417")] // usize/isize
pub use self::ptr_try_from_impls::*; try_from_unbounded!(usize, usize);
try_from_upper_bounded!(usize, isize);
try_from_lower_bounded!(isize, usize);
try_from_unbounded!(isize, isize);
#[cfg(target_pointer_width = "16")] #[cfg(target_pointer_width = "16")]
mod ptr_try_from_impls { mod ptr_try_from_impls {
...@@ -2631,12 +2634,12 @@ mod ptr_try_from_impls { ...@@ -2631,12 +2634,12 @@ mod ptr_try_from_impls {
use convert::TryFrom; use convert::TryFrom;
try_from_upper_bounded!(usize, u8); try_from_upper_bounded!(usize, u8);
try_from_unbounded!(usize, usize, u16, u32, u64, u128); try_from_unbounded!(usize, u16, u32, u64, u128);
try_from_upper_bounded!(usize, i8, i16, isize); try_from_upper_bounded!(usize, i8, i16);
try_from_unbounded!(usize, i32, i64, i128); try_from_unbounded!(usize, i32, i64, i128);
try_from_both_bounded!(isize, u8); try_from_both_bounded!(isize, u8);
try_from_lower_bounded!(isize, usize, u16, u32, u64, u128); try_from_lower_bounded!(isize, u16, u32, u64, u128);
try_from_both_bounded!(isize, i8); try_from_both_bounded!(isize, i8);
try_from_unbounded!(isize, i16, i32, i64, i128); try_from_unbounded!(isize, i16, i32, i64, i128);
...@@ -2657,12 +2660,12 @@ mod ptr_try_from_impls { ...@@ -2657,12 +2660,12 @@ mod ptr_try_from_impls {
use convert::TryFrom; use convert::TryFrom;
try_from_upper_bounded!(usize, u8, u16); try_from_upper_bounded!(usize, u8, u16);
try_from_unbounded!(usize, usize, u32, u64, u128); try_from_unbounded!(usize, u32, u64, u128);
try_from_upper_bounded!(usize, i8, i16, i32, isize); try_from_upper_bounded!(usize, i8, i16, i32);
try_from_unbounded!(usize, i64, i128); try_from_unbounded!(usize, i64, i128);
try_from_both_bounded!(isize, u8, u16); try_from_both_bounded!(isize, u8, u16);
try_from_lower_bounded!(isize, usize, u32, u64, u128); try_from_lower_bounded!(isize, u32, u64, u128);
try_from_both_bounded!(isize, i8, i16); try_from_both_bounded!(isize, i8, i16);
try_from_unbounded!(isize, i32, i64, i128); try_from_unbounded!(isize, i32, i64, i128);
...@@ -2683,12 +2686,12 @@ mod ptr_try_from_impls { ...@@ -2683,12 +2686,12 @@ mod ptr_try_from_impls {
use convert::TryFrom; use convert::TryFrom;
try_from_upper_bounded!(usize, u8, u16, u32); try_from_upper_bounded!(usize, u8, u16, u32);
try_from_unbounded!(usize, usize, u64, u128); try_from_unbounded!(usize, u64, u128);
try_from_upper_bounded!(usize, i8, i16, i32, i64, isize); try_from_upper_bounded!(usize, i8, i16, i32, i64);
try_from_unbounded!(usize, i128); try_from_unbounded!(usize, i128);
try_from_both_bounded!(isize, u8, u16, u32); try_from_both_bounded!(isize, u8, u16, u32);
try_from_lower_bounded!(isize, usize, u64, u128); try_from_lower_bounded!(isize, u64, u128);
try_from_both_bounded!(isize, i8, i16, i32); try_from_both_bounded!(isize, i8, i16, i32);
try_from_unbounded!(isize, i64, i128); try_from_unbounded!(isize, i64, i128);
......
...@@ -279,7 +279,7 @@ fn $fn_name() { ...@@ -279,7 +279,7 @@ fn $fn_name() {
test_impl_try_from_always_ok! { test_try_u64u128, u64, u128 } test_impl_try_from_always_ok! { test_try_u64u128, u64, u128 }
test_impl_try_from_always_ok! { test_try_u64i128, u64, i128 } test_impl_try_from_always_ok! { test_try_u64i128, u64, i128 }
test_impl_try_from_always_ok! { test_try_u128, u128, u128 } test_impl_try_from_always_ok! { test_try_u128u128, u128, u128 }
test_impl_try_from_always_ok! { test_try_i8i8, i8, i8 } test_impl_try_from_always_ok! { test_try_i8i8, i8, i8 }
test_impl_try_from_always_ok! { test_try_i8i16, i8, i16 } test_impl_try_from_always_ok! { test_try_i8i16, i8, i16 }
...@@ -301,8 +301,12 @@ fn $fn_name() { ...@@ -301,8 +301,12 @@ fn $fn_name() {
test_impl_try_from_always_ok! { test_try_i128i128, i128, i128 } test_impl_try_from_always_ok! { test_try_i128i128, i128, i128 }
test_impl_try_from_always_ok! { test_try_usizeusize, usize, usize }
test_impl_try_from_always_ok! { test_try_isizeisize, isize, isize }
assume_usize_width! { assume_usize_width! {
test_impl_try_from_always_ok! { test_try_u8usize, u8, usize } test_impl_try_from_always_ok! { test_try_u8usize, u8, usize }
test_impl_try_from_always_ok! { test_try_u8isize, u8, isize }
test_impl_try_from_always_ok! { test_try_i8isize, i8, isize } test_impl_try_from_always_ok! { test_try_i8isize, i8, isize }
test_impl_try_from_always_ok! { test_try_u16usize, u16, usize } test_impl_try_from_always_ok! { test_try_u16usize, u16, usize }
...@@ -317,19 +321,27 @@ fn $fn_name() { ...@@ -317,19 +321,27 @@ fn $fn_name() {
cfg_block!( cfg_block!(
#[cfg(target_pointer_width = "16")] { #[cfg(target_pointer_width = "16")] {
test_impl_try_from_always_ok! { test_try_u16usize, u16, usize } test_impl_try_from_always_ok! { test_try_usizeu16, usize, u16 }
test_impl_try_from_always_ok! { test_try_i16isize, i16, isize } test_impl_try_from_always_ok! { test_try_isizei16, isize, i16 }
test_impl_try_from_always_ok! { test_try_usizeu32, usize, u32 }
test_impl_try_from_always_ok! { test_try_usizei32, usize, i32 }
test_impl_try_from_always_ok! { test_try_isizei32, isize, i32 }
test_impl_try_from_always_ok! { test_try_usizei64, usize, i64 }
} }
#[cfg(target_pointer_width = "32")] { #[cfg(target_pointer_width = "32")] {
test_impl_try_from_always_ok! { test_try_u16isize, u16, isize }
test_impl_try_from_always_ok! { test_try_usizeu32, usize, u32 } test_impl_try_from_always_ok! { test_try_usizeu32, usize, u32 }
test_impl_try_from_always_ok! { test_try_isizei32, isize, i32 } test_impl_try_from_always_ok! { test_try_isizei32, isize, i32 }
test_impl_try_from_always_ok! { test_try_u32usize, u32, usize } test_impl_try_from_always_ok! { test_try_u32usize, u32, usize }
test_impl_try_from_always_ok! { test_try_i32isize, i32, isize } test_impl_try_from_always_ok! { test_try_i32isize, i32, isize }
test_impl_try_from_always_ok! { test_try_usizei64, usize, i64 }
} }
#[cfg(target_pointer_width = "64")] { #[cfg(target_pointer_width = "64")] {
test_impl_try_from_always_ok! { test_try_u16isize, u16, isize }
test_impl_try_from_always_ok! { test_try_u32usize, u32, usize } test_impl_try_from_always_ok! { test_try_u32usize, u32, usize }
test_impl_try_from_always_ok! { test_try_u32isize, u32, isize }
test_impl_try_from_always_ok! { test_try_i32isize, i32, isize } test_impl_try_from_always_ok! { test_try_i32isize, i32, isize }
test_impl_try_from_always_ok! { test_try_u64usize, u64, usize } test_impl_try_from_always_ok! { test_try_u64usize, u64, usize }
test_impl_try_from_always_ok! { test_try_i64isize, i64, isize } test_impl_try_from_always_ok! { test_try_i64isize, i64, isize }
...@@ -451,8 +463,8 @@ fn $fn_name() { ...@@ -451,8 +463,8 @@ fn $fn_name() {
cfg_block!( cfg_block!(
#[cfg(target_pointer_width = "16")] { #[cfg(target_pointer_width = "16")] {
test_impl_try_from_unsigned_to_signed_upper_err! { test_try_u16isize, u16, isize }
test_impl_try_from_unsigned_to_signed_upper_err! { test_try_u32isize, u32, isize } test_impl_try_from_unsigned_to_signed_upper_err! { test_try_u32isize, u32, isize }
test_impl_try_from_unsigned_to_signed_upper_err! { test_try_u32isize, u64, isize }
} }
#[cfg(target_pointer_width = "32")] { #[cfg(target_pointer_width = "32")] {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册