This approach doesn't seem to work converting u64 -> i64
Closed this issue · 1 comments
pjkundert commented
The is_safely_convertible
in impl_unsigned_to_signed_internal
takes the u64 as LargestSignedType
(i64), which will fail to retain the value if it exceeds i64::MAX.
It should return false if the u64 value exceeds i64::MAX, not fail (allow over/underflow, in release compilations) or panic (in debug compilations). I'm not certain how to achieve that.
phimuemue commented
I think we can solve this by casting to LargestUnsignedType
instead of LargestSignedType
.
self as LargestUnsignedType
works sinceself
is unsigned.<$dest as SignedInt>::max() as LargestUnsignedType
works since we assume thatLargestUnsignedType
has at least as many bytes as$dest
($dest
is signed)