Skip to content

Commit 6bf5c0b

Browse files
committed
Correctly handle signs in exponents in numeric_literal::format()
1 parent 5116080 commit 6bf5c0b

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,5 @@ fn main() {
6262
let num = 0.000_000_000_01e-10f64;
6363

6464
// issue #7744
65-
let _ = 2.225_073_858_507_201e-_308_f64;
65+
let _ = 2.225_073_858_507_201e-308_f64;
6666
}

tests/ui/excessive_precision.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ error: float has excessive precision
8282
--> $DIR/excessive_precision.rs:65:13
8383
|
8484
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`
85+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `2.225_073_858_507_201e-308_f64`
8686

8787
error: aborting due to 14 previous errors
8888

0 commit comments

Comments
 (0)