Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Oct 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions clippy_utils/src/numeric_literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions tests/ui/excessive_precision.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
3 changes: 3 additions & 0 deletions tests/ui/excessive_precision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
8 changes: 7 additions & 1 deletion tests/ui/excessive_precision.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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