diff options
| author | bors <bors@rust-lang.org> | 2017-02-05 16:57:29 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-02-05 16:57:29 +0000 |
| commit | fc02736d59252fe408dd6c2f7e2c4b6f229e4443 (patch) | |
| tree | a5b61777e069dac44c179cba88a836166639a8c9 /src/libcore | |
| parent | 9c8cdb2923a69177017165a4cdb0e1ea673fc49f (diff) | |
| parent | a2de6e22858a02cfcf6bfc18ff40ebb163ebb07c (diff) | |
| download | rust-fc02736d59252fe408dd6c2f7e2c4b6f229e4443.tar.gz rust-fc02736d59252fe408dd6c2f7e2c4b6f229e4443.zip | |
Auto merge of #39408 - ollie27:i128_try_from, r=alexcrichton
Fix TryFrom for i128/u128 Another case of `as` cast silent truncation being error prone. This also adds a few missing TryFrom tests to libcoretest. cc #33417 cc #35118
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/num/mod.rs | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index e907eae18bc..97ea6bb347b 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -2626,8 +2626,8 @@ macro_rules! cross_sign_from_int_impl { type Err = TryFromIntError; fn try_from(u: $unsigned) -> Result<$signed, TryFromIntError> { - let max = <$signed as FromStrRadixHelper>::max_value() as u64; - if u as u64 > max { + let max = <$signed as FromStrRadixHelper>::max_value() as u128; + if u as u128 > max { Err(TryFromIntError(())) } else { Ok(u as $signed) @@ -2640,8 +2640,8 @@ macro_rules! cross_sign_from_int_impl { type Err = TryFromIntError; fn try_from(u: $signed) -> Result<$unsigned, TryFromIntError> { - let max = <$unsigned as FromStrRadixHelper>::max_value() as u64; - if u < 0 || u as u64 > max { + let max = <$unsigned as FromStrRadixHelper>::max_value() as u128; + if u < 0 || u as u128 > max { Err(TryFromIntError(())) } else { Ok(u as $unsigned) |
