diff options
| author | bors <bors@rust-lang.org> | 2016-02-06 13:16:03 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2016-02-06 13:16:03 +0000 |
| commit | 695c907dcc7c81c5fc052f426f7764476c12cf15 (patch) | |
| tree | 31579fe2c0d9619d1a2101e5021cb266a8e7e4af /src/libcoretest | |
| parent | 35635aebab321ff2a4708aeb172351356ad63cf7 (diff) | |
| parent | a76cb45e340f762d83a9501452db0581ba56db52 (diff) | |
| download | rust-695c907dcc7c81c5fc052f426f7764476c12cf15.tar.gz rust-695c907dcc7c81c5fc052f426f7764476c12cf15.zip | |
Auto merge of #31410 - rkruppe:issue31109, r=pnkfelix
Issue #31109 uncovered two semi-related problems: * A panic in `str::parse::<f64>` * A panic in `rustc::middle::const_eval::lit_to_const` where the result of float parsing was unwrapped. This series of commits fixes both issues and also drive-by-fixes some things I noticed while tracking down the parsing panic.
Diffstat (limited to 'src/libcoretest')
| -rw-r--r-- | src/libcoretest/num/dec2flt/mod.rs | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/libcoretest/num/dec2flt/mod.rs b/src/libcoretest/num/dec2flt/mod.rs index 7b25333e21e..fe6f52406fb 100644 --- a/src/libcoretest/num/dec2flt/mod.rs +++ b/src/libcoretest/num/dec2flt/mod.rs @@ -25,13 +25,11 @@ macro_rules! test_literal { let x64: f64 = $x; let inputs = &[stringify!($x).into(), format!("{:?}", x64), format!("{:e}", x64)]; for input in inputs { - if input != "inf" { - assert_eq!(input.parse(), Ok(x64)); - assert_eq!(input.parse(), Ok(x32)); - let neg_input = &format!("-{}", input); - assert_eq!(neg_input.parse(), Ok(-x64)); - assert_eq!(neg_input.parse(), Ok(-x32)); - } + assert_eq!(input.parse(), Ok(x64)); + assert_eq!(input.parse(), Ok(x32)); + let neg_input = &format!("-{}", input); + assert_eq!(neg_input.parse(), Ok(-x64)); + assert_eq!(neg_input.parse(), Ok(-x32)); } }) } @@ -136,6 +134,17 @@ fn massive_exponent() { assert_eq!(format!("1e{}000", max).parse(), Ok(f64::INFINITY)); } +#[test] +fn borderline_overflow() { + let mut s = "0.".to_string(); + for _ in 0..375 { + s.push('3'); + } + // At the time of this writing, this returns Err(..), but this is a bug that should be fixed. + // It makes no sense to enshrine that in a test, the important part is that it doesn't panic. + let _ = s.parse::<f64>(); +} + #[bench] fn bench_0(b: &mut test::Bencher) { b.iter(|| "0.0".parse::<f64>()); |
