Auto merge of #10914 - y21:issue10912, r=giraffate
handle exponent without digits in `numeric_literal`
Fixes #10912
The numeric literal util module didn't check for exponents with no digits.
So:
384cf37612/clippy_utils/src/numeric_literal.rs (L163-L168)
`exponent` here would be the empty string, which passed the `!= "0"` check (when it shouldn't have, it should probably be treated as if the user wrote `E0`), then later fails when counting the digits and subtracting one (0 - 1 = overflow).
Also, interestingly I can't even write a test for this because exponents with no digits is some kind of error by itself and `cargo dev fmt` fails on it.
changelog: [`unreadable_literal`]: don't (debug) ICE on numeric literal with empty exponent
This commit is contained in:
commit
f93df98b84
@ -161,7 +161,7 @@ pub fn format(&self) -> String {
|
||||
}
|
||||
|
||||
if let Some((separator, exponent)) = self.exponent {
|
||||
if exponent != "0" {
|
||||
if !exponent.is_empty() && exponent != "0" {
|
||||
output.push_str(separator);
|
||||
Self::group_digits(&mut output, exponent, group_size, true, false);
|
||||
}
|
||||
|
@ -5,3 +5,4 @@ wrap_comments = true
|
||||
edition = "2021"
|
||||
error_on_line_overflow = true
|
||||
version = "Two"
|
||||
ignore = ["tests/ui/crashes/ice-10912.rs"]
|
||||
|
4
tests/ui/crashes/ice-10912.rs
Normal file
4
tests/ui/crashes/ice-10912.rs
Normal file
@ -0,0 +1,4 @@
|
||||
#![warn(clippy::unreadable_literal)]
|
||||
fn f2() -> impl Sized { && 3.14159265358979323846E }
|
||||
|
||||
fn main() {}
|
16
tests/ui/crashes/ice-10912.stderr
Normal file
16
tests/ui/crashes/ice-10912.stderr
Normal file
@ -0,0 +1,16 @@
|
||||
error: expected at least one digit in exponent
|
||||
--> $DIR/ice-10912.rs:2:28
|
||||
|
|
||||
LL | fn f2() -> impl Sized { && 3.14159265358979323846E }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: long literal lacking separators
|
||||
--> $DIR/ice-10912.rs:2:28
|
||||
|
|
||||
LL | fn f2() -> impl Sized { && 3.14159265358979323846E }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: consider: `3.141_592_653_589_793_238_46`
|
||||
|
|
||||
= note: `-D clippy::unreadable-literal` implied by `-D warnings`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
Loading…
Reference in New Issue
Block a user