Skip to content

Commit f93df98

Browse files
committed
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: https://github.com/rust-lang/rust-clippy/blob/384cf376120f09df7710d2ff39c986144a7b1517/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
2 parents ff3b49c + bbb9204 commit f93df98

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

clippy_utils/src/numeric_literal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ impl<'a> NumericLiteral<'a> {
161161
}
162162

163163
if let Some((separator, exponent)) = self.exponent {
164-
if exponent != "0" {
164+
if !exponent.is_empty() && exponent != "0" {
165165
output.push_str(separator);
166166
Self::group_digits(&mut output, exponent, group_size, true, false);
167167
}

rustfmt.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ wrap_comments = true
55
edition = "2021"
66
error_on_line_overflow = true
77
version = "Two"
8+
ignore = ["tests/ui/crashes/ice-10912.rs"]

tests/ui/crashes/ice-10912.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#![warn(clippy::unreadable_literal)]
2+
fn f2() -> impl Sized { && 3.14159265358979323846E }
3+
4+
fn main() {}

tests/ui/crashes/ice-10912.stderr

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error: expected at least one digit in exponent
2+
--> $DIR/ice-10912.rs:2:28
3+
|
4+
LL | fn f2() -> impl Sized { && 3.14159265358979323846E }
5+
| ^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: long literal lacking separators
8+
--> $DIR/ice-10912.rs:2:28
9+
|
10+
LL | fn f2() -> impl Sized { && 3.14159265358979323846E }
11+
| ^^^^^^^^^^^^^^^^^^^^^^^ help: consider: `3.141_592_653_589_793_238_46`
12+
|
13+
= note: `-D clippy::unreadable-literal` implied by `-D warnings`
14+
15+
error: aborting due to 2 previous errors
16+

0 commit comments

Comments
 (0)