Auto merge of #7747 - Manishearth:excessive-precision, r=xFrednet

Correctly handle signs in exponents in numeric_literal::format()

Fixes #7744

changelog: Correctly handle signs in exponents in `numeric_literal::format()`
This commit is contained in:
bors 2021-10-02 16:12:30 +00:00
commit da3b4b4594
4 changed files with 20 additions and 1 deletions

View File

@ -177,6 +177,13 @@ pub fn group_digits(output: &mut String, input: &str, group_size: usize, partial
let mut digits = input.chars().filter(|&c| c != '_');
// The exponent may have a sign, output it early, otherwise it will be
// treated as a digit
if let Some('-') = digits.clone().next() {
let _ = digits.next();
output.push('-');
}
let first_group_size;
if partial_group_first {

View File

@ -60,4 +60,7 @@ fn main() {
// issue #2840
let num = 0.000_000_000_01e-10f64;
// issue #7744
let _ = 2.225_073_858_507_201e-308_f64;
}

View File

@ -60,4 +60,7 @@ fn main() {
// issue #2840
let num = 0.000_000_000_01e-10f64;
// issue #7744
let _ = 2.225_073_858_507_201_1e-308_f64;
}

View File

@ -78,5 +78,11 @@ error: float has excessive precision
LL | let bad_bige32: f32 = 1.123_456_788_888E-10;
| ^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.123_456_8E-10`
error: aborting due to 13 previous errors
error: float has excessive precision
--> $DIR/excessive_precision.rs:65:13
|
LL | let _ = 2.225_073_858_507_201_1e-308_f64;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `2.225_073_858_507_201e-308_f64`
error: aborting due to 14 previous errors