about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-06-11 02:43:45 +0000
committerbors <bors@rust-lang.org>2023-06-11 02:43:45 +0000
commitf93df98b84232ab08f7e3bba0ef18826eaf9bf80 (patch)
tree7e988300b45e2017903dc2dcfc238cce6949742f
parentff3b49cfcb7f226d2d8dd4ab9e36fa3363e46b96 (diff)
parentbbb9204008297fc326fcf4dfbc07cee12f173081 (diff)
downloadrust-f93df98b84232ab08f7e3bba0ef18826eaf9bf80.tar.gz
rust-f93df98b84232ab08f7e3bba0ef18826eaf9bf80.zip
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
-rw-r--r--clippy_utils/src/numeric_literal.rs2
-rw-r--r--rustfmt.toml1
-rw-r--r--tests/ui/crashes/ice-10912.rs4
-rw-r--r--tests/ui/crashes/ice-10912.stderr16
4 files changed, 22 insertions, 1 deletions
diff --git a/clippy_utils/src/numeric_literal.rs b/clippy_utils/src/numeric_literal.rs
index c225398ad2a..bbe4149fe2a 100644
--- a/clippy_utils/src/numeric_literal.rs
+++ b/clippy_utils/src/numeric_literal.rs
@@ -161,7 +161,7 @@ impl<'a> NumericLiteral<'a> {
         }
 
         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);
             }
diff --git a/rustfmt.toml b/rustfmt.toml
index 10d39762043..18b2a33469d 100644
--- a/rustfmt.toml
+++ b/rustfmt.toml
@@ -5,3 +5,4 @@ wrap_comments = true
 edition = "2021"
 error_on_line_overflow = true
 version = "Two"
+ignore = ["tests/ui/crashes/ice-10912.rs"]
diff --git a/tests/ui/crashes/ice-10912.rs b/tests/ui/crashes/ice-10912.rs
new file mode 100644
index 00000000000..69d7f2f395f
--- /dev/null
+++ b/tests/ui/crashes/ice-10912.rs
@@ -0,0 +1,4 @@
+#![warn(clippy::unreadable_literal)]
+fn f2() -> impl Sized { && 3.14159265358979323846E }
+
+fn main() {}
diff --git a/tests/ui/crashes/ice-10912.stderr b/tests/ui/crashes/ice-10912.stderr
new file mode 100644
index 00000000000..a74ce731577
--- /dev/null
+++ b/tests/ui/crashes/ice-10912.stderr
@@ -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
+