Skip to content

Commit da3b4b4

Browse files
committed
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()`
2 parents fe999e8 + 6bf5c0b commit da3b4b4

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

clippy_utils/src/numeric_literal.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,13 @@ impl<'a> NumericLiteral<'a> {
177177

178178
let mut digits = input.chars().filter(|&c| c != '_');
179179

180+
// The exponent may have a sign, output it early, otherwise it will be
181+
// treated as a digit
182+
if let Some('-') = digits.clone().next() {
183+
let _ = digits.next();
184+
output.push('-');
185+
}
186+
180187
let first_group_size;
181188

182189
if partial_group_first {

tests/ui/excessive_precision.fixed

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,7 @@ fn main() {
6060

6161
// issue #2840
6262
let num = 0.000_000_000_01e-10f64;
63+
64+
// issue #7744
65+
let _ = 2.225_073_858_507_201e-308_f64;
6366
}

tests/ui/excessive_precision.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,7 @@ fn main() {
6060

6161
// issue #2840
6262
let num = 0.000_000_000_01e-10f64;
63+
64+
// issue #7744
65+
let _ = 2.225_073_858_507_201_1e-308_f64;
6366
}

tests/ui/excessive_precision.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,11 @@ error: float has excessive precision
7878
LL | let bad_bige32: f32 = 1.123_456_788_888E-10;
7979
| ^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.123_456_8E-10`
8080

81-
error: aborting due to 13 previous errors
81+
error: float has excessive precision
82+
--> $DIR/excessive_precision.rs:65:13
83+
|
84+
LL | let _ = 2.225_073_858_507_201_1e-308_f64;
85+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `2.225_073_858_507_201e-308_f64`
86+
87+
error: aborting due to 14 previous errors
8288

0 commit comments

Comments
 (0)