@@ -37,6 +37,15 @@ mod flt2dec;
3737mod dec2flt;
3838mod bignum;
3939
40+
41+ /// Adds the attribute to all items in the block.
42+ macro_rules! cfg_block {
43+ ( $( #[ $attr: meta] { $( $it: item) * } ) * ) => { $( $(
44+ #[ $attr]
45+ $it
46+ ) * ) * }
47+ }
48+
4049/// Groups items that assume the pointer width is either 16/32/64, and has to be altered if
4150/// support for larger/smaller pointer widths are added in the future.
4251macro_rules! assume_usize_width {
@@ -330,6 +339,42 @@ assume_usize_width! {
330339
331340 test_impl_try_from_always_ok! { test_try_u16usize, u16 , usize }
332341 test_impl_try_from_always_ok! { test_try_i16isize, i16 , isize }
342+
343+ test_impl_try_from_always_ok! { test_try_usizeu64, usize , u64 }
344+ test_impl_try_from_always_ok! { test_try_usizeu128, usize , u128 }
345+ test_impl_try_from_always_ok! { test_try_usizei128, usize , i128 }
346+
347+ test_impl_try_from_always_ok! { test_try_isizei64, isize , i64 }
348+ test_impl_try_from_always_ok! { test_try_isizei128, isize , i128 }
349+
350+ cfg_block!(
351+ #[ cfg( target_pointer_width = "16" ) ] {
352+ test_impl_try_from_always_ok! { test_try_usizeu16, usize , u16 }
353+ test_impl_try_from_always_ok! { test_try_isizei16, isize , i16 }
354+ test_impl_try_from_always_ok! { test_try_usizeu32, usize , u32 }
355+ test_impl_try_from_always_ok! { test_try_usizei32, usize , i32 }
356+ test_impl_try_from_always_ok! { test_try_isizei32, isize , i32 }
357+ test_impl_try_from_always_ok! { test_try_usizei64, usize , i64 }
358+ }
359+
360+ #[ cfg( target_pointer_width = "32" ) ] {
361+ test_impl_try_from_always_ok! { test_try_u16isize, u16 , isize }
362+ test_impl_try_from_always_ok! { test_try_usizeu32, usize , u32 }
363+ test_impl_try_from_always_ok! { test_try_isizei32, isize , i32 }
364+ test_impl_try_from_always_ok! { test_try_u32usize, u32 , usize }
365+ test_impl_try_from_always_ok! { test_try_i32isize, i32 , isize }
366+ test_impl_try_from_always_ok! { test_try_usizei64, usize , i64 }
367+ }
368+
369+ #[ cfg( target_pointer_width = "64" ) ] {
370+ test_impl_try_from_always_ok! { test_try_u16isize, u16 , isize }
371+ test_impl_try_from_always_ok! { test_try_u32usize, u32 , usize }
372+ test_impl_try_from_always_ok! { test_try_u32isize, u32 , isize }
373+ test_impl_try_from_always_ok! { test_try_i32isize, i32 , isize }
374+ test_impl_try_from_always_ok! { test_try_u64usize, u64 , usize }
375+ test_impl_try_from_always_ok! { test_try_i64isize, i64 , isize }
376+ }
377+ ) ;
333378}
334379
335380/// Conversions where max of $source can be represented as $target,
@@ -378,6 +423,24 @@ assume_usize_width! {
378423 test_impl_try_from_signed_to_unsigned_upper_ok! { test_try_isizeu64, isize , u64 }
379424 test_impl_try_from_signed_to_unsigned_upper_ok! { test_try_isizeu128, isize , u128 }
380425 test_impl_try_from_signed_to_unsigned_upper_ok! { test_try_isizeusize, isize , usize }
426+
427+ cfg_block!(
428+ #[ cfg( target_pointer_width = "16" ) ] {
429+ test_impl_try_from_signed_to_unsigned_upper_ok! { test_try_isizeu16, isize , u16 }
430+ test_impl_try_from_signed_to_unsigned_upper_ok! { test_try_isizeu32, isize , u32 }
431+ }
432+
433+ #[ cfg( target_pointer_width = "32" ) ] {
434+ test_impl_try_from_signed_to_unsigned_upper_ok! { test_try_isizeu32, isize , u32 }
435+
436+ test_impl_try_from_signed_to_unsigned_upper_ok! { test_try_i32usize, i32 , usize }
437+ }
438+
439+ #[ cfg( target_pointer_width = "64" ) ] {
440+ test_impl_try_from_signed_to_unsigned_upper_ok! { test_try_i32usize, i32 , usize }
441+ test_impl_try_from_signed_to_unsigned_upper_ok! { test_try_i64usize, i64 , usize }
442+ }
443+ ) ;
381444}
382445
383446/// Conversions where max of $source can not be represented as $target,
@@ -419,9 +482,29 @@ test_impl_try_from_unsigned_to_signed_upper_err! { test_try_u128i64, u128, i64 }
419482test_impl_try_from_unsigned_to_signed_upper_err ! { test_try_u128i128, u128 , i128 }
420483
421484assume_usize_width ! {
485+ test_impl_try_from_unsigned_to_signed_upper_err! { test_try_u64isize, u64 , isize }
486+ test_impl_try_from_unsigned_to_signed_upper_err! { test_try_u128isize, u128 , isize }
487+
422488 test_impl_try_from_unsigned_to_signed_upper_err! { test_try_usizei8, usize , i8 }
423489 test_impl_try_from_unsigned_to_signed_upper_err! { test_try_usizei16, usize , i16 }
424490 test_impl_try_from_unsigned_to_signed_upper_err! { test_try_usizeisize, usize , isize }
491+
492+ cfg_block!(
493+ #[ cfg( target_pointer_width = "16" ) ] {
494+ test_impl_try_from_unsigned_to_signed_upper_err! { test_try_u16isize, u16 , isize }
495+ test_impl_try_from_unsigned_to_signed_upper_err! { test_try_u32isize, u32 , isize }
496+ }
497+
498+ #[ cfg( target_pointer_width = "32" ) ] {
499+ test_impl_try_from_unsigned_to_signed_upper_err! { test_try_u32isize, u32 , isize }
500+ test_impl_try_from_unsigned_to_signed_upper_err! { test_try_usizei32, usize , i32 }
501+ }
502+
503+ #[ cfg( target_pointer_width = "64" ) ] {
504+ test_impl_try_from_unsigned_to_signed_upper_err! { test_try_usizei32, usize , i32 }
505+ test_impl_try_from_unsigned_to_signed_upper_err! { test_try_usizei64, usize , i64 }
506+ }
507+ ) ;
425508}
426509
427510/// Conversions where min/max of $source can not be represented as $target.
@@ -481,6 +564,34 @@ test_impl_try_from_same_sign_err! { test_try_i128i64, i128, i64 }
481564
482565assume_usize_width ! {
483566 test_impl_try_from_same_sign_err! { test_try_usizeu8, usize , u8 }
567+ test_impl_try_from_same_sign_err! { test_try_u128usize, u128 , usize }
568+ test_impl_try_from_same_sign_err! { test_try_i128isize, i128 , isize }
569+
570+ cfg_block!(
571+ #[ cfg( target_pointer_width = "16" ) ] {
572+ test_impl_try_from_same_sign_err! { test_try_u32usize, u32 , usize }
573+ test_impl_try_from_same_sign_err! { test_try_u64usize, u64 , usize }
574+
575+ test_impl_try_from_same_sign_err! { test_try_i32isize, i32 , isize }
576+ test_impl_try_from_same_sign_err! { test_try_i64isize, i64 , isize }
577+ }
578+
579+ #[ cfg( target_pointer_width = "32" ) ] {
580+ test_impl_try_from_same_sign_err! { test_try_u64usize, u64 , usize }
581+ test_impl_try_from_same_sign_err! { test_try_usizeu16, usize , u16 }
582+
583+ test_impl_try_from_same_sign_err! { test_try_i64isize, i64 , isize }
584+ test_impl_try_from_same_sign_err! { test_try_isizei16, isize , i16 }
585+ }
586+
587+ #[ cfg( target_pointer_width = "64" ) ] {
588+ test_impl_try_from_same_sign_err! { test_try_usizeu16, usize , u16 }
589+ test_impl_try_from_same_sign_err! { test_try_usizeu32, usize , u32 }
590+
591+ test_impl_try_from_same_sign_err! { test_try_isizei16, isize , i16 }
592+ test_impl_try_from_same_sign_err! { test_try_isizei32, isize , i32 }
593+ }
594+ ) ;
484595}
485596
486597/// Conversions where neither the min nor the max of $source can be represented by
@@ -525,6 +636,22 @@ test_impl_try_from_signed_to_unsigned_err! { test_try_i128u64, i128, u64 }
525636assume_usize_width ! {
526637 test_impl_try_from_signed_to_unsigned_err! { test_try_isizeu8, isize , u8 }
527638 test_impl_try_from_signed_to_unsigned_err! { test_try_i128usize, i128 , usize }
639+
640+ cfg_block! {
641+ #[ cfg( target_pointer_width = "16" ) ] {
642+ test_impl_try_from_signed_to_unsigned_err! { test_try_i32usize, i32 , usize }
643+ test_impl_try_from_signed_to_unsigned_err! { test_try_i64usize, i64 , usize }
644+ }
645+ #[ cfg( target_pointer_width = "32" ) ] {
646+ test_impl_try_from_signed_to_unsigned_err! { test_try_i64usize, i64 , usize }
647+
648+ test_impl_try_from_signed_to_unsigned_err! { test_try_isizeu16, isize , u16 }
649+ }
650+ #[ cfg( target_pointer_width = "64" ) ] {
651+ test_impl_try_from_signed_to_unsigned_err! { test_try_isizeu16, isize , u16 }
652+ test_impl_try_from_signed_to_unsigned_err! { test_try_isizeu32, isize , u32 }
653+ }
654+ }
528655}
529656
530657macro_rules! test_float {
0 commit comments