From 6bf5c0b185e37f64661e16938e18d68abd2accc4 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Fri, 1 Oct 2021 17:27:47 -0700 Subject: [PATCH] Correctly handle signs in exponents in numeric_literal::format() --- clippy_utils/src/numeric_literal.rs | 7 +++++++ tests/ui/excessive_precision.fixed | 2 +- tests/ui/excessive_precision.stderr | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/clippy_utils/src/numeric_literal.rs b/clippy_utils/src/numeric_literal.rs index 4a28c7dd9a04a..98f65039b7da9 100644 --- a/clippy_utils/src/numeric_literal.rs +++ b/clippy_utils/src/numeric_literal.rs @@ -177,6 +177,13 @@ impl<'a> NumericLiteral<'a> { 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 { diff --git a/tests/ui/excessive_precision.fixed b/tests/ui/excessive_precision.fixed index f57191d2ae5e0..65096d6b219e3 100644 --- a/tests/ui/excessive_precision.fixed +++ b/tests/ui/excessive_precision.fixed @@ -62,5 +62,5 @@ fn main() { let num = 0.000_000_000_01e-10f64; // issue #7744 - let _ = 2.225_073_858_507_201e-_308_f64; + let _ = 2.225_073_858_507_201e-308_f64; } diff --git a/tests/ui/excessive_precision.stderr b/tests/ui/excessive_precision.stderr index 4c8194b1d862b..c9418f73d9874 100644 --- a/tests/ui/excessive_precision.stderr +++ b/tests/ui/excessive_precision.stderr @@ -82,7 +82,7 @@ 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` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `2.225_073_858_507_201e-308_f64` error: aborting due to 14 previous errors