From 951f2d9ae2c3252e8076aebd54a519be83fcbab2 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 28 Feb 2024 15:49:48 +1100 Subject: [PATCH] Use `LitKind::Err` for floats with empty exponents. This prevents a follow-up type error in a test, which seems fine. --- compiler/rustc_parse/src/lexer/mod.rs | 6 ++++-- .../clippy/tests/ui/crashes/ice-10912.rs | 2 -- .../clippy/tests/ui/crashes/ice-10912.stderr | 11 +--------- ...nicode-confusable-in-float-literal-expt.rs | 1 - ...de-confusable-in-float-literal-expt.stderr | 21 +------------------ 5 files changed, 6 insertions(+), 35 deletions(-) diff --git a/compiler/rustc_parse/src/lexer/mod.rs b/compiler/rustc_parse/src/lexer/mod.rs index dc9f5bad765..4523276970d 100644 --- a/compiler/rustc_parse/src/lexer/mod.rs +++ b/compiler/rustc_parse/src/lexer/mod.rs @@ -501,9 +501,11 @@ impl<'sess, 'src> StringReader<'sess, 'src> { (kind, self.symbol_from_to(start, end)) } rustc_lexer::LiteralKind::Float { base, empty_exponent } => { + let mut kind = token::Float; if empty_exponent { let span = self.mk_sp(start, self.pos); - self.dcx().emit_err(errors::EmptyExponentFloat { span }); + let guar = self.dcx().emit_err(errors::EmptyExponentFloat { span }); + kind = token::Err(guar); } let base = match base { Base::Hexadecimal => Some("hexadecimal"), @@ -515,7 +517,7 @@ impl<'sess, 'src> StringReader<'sess, 'src> { let span = self.mk_sp(start, end); self.dcx().emit_err(errors::FloatLiteralUnsupportedBase { span, base }); } - (token::Float, self.symbol_from_to(start, end)) + (kind, self.symbol_from_to(start, end)) } } } diff --git a/src/tools/clippy/tests/ui/crashes/ice-10912.rs b/src/tools/clippy/tests/ui/crashes/ice-10912.rs index 8dfce194221..1d689e1d008 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-10912.rs +++ b/src/tools/clippy/tests/ui/crashes/ice-10912.rs @@ -2,7 +2,5 @@ //@no-rustfix fn f2() -> impl Sized { && 3.14159265358979323846E } //~^ ERROR: expected at least one digit in exponent -//~| ERROR: long literal lacking separators -//~| NOTE: `-D clippy::unreadable-literal` implied by `-D warnings` fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-10912.stderr b/src/tools/clippy/tests/ui/crashes/ice-10912.stderr index cc80354c7c6..c697e54679f 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-10912.stderr +++ b/src/tools/clippy/tests/ui/crashes/ice-10912.stderr @@ -4,14 +4,5 @@ error: expected at least one digit in exponent LL | fn f2() -> impl Sized { && 3.14159265358979323846E } | ^^^^^^^^^^^^^^^^^^^^^^^ -error: long literal lacking separators - --> tests/ui/crashes/ice-10912.rs:3: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` - = help: to override `-D warnings` add `#[allow(clippy::unreadable_literal)]` - -error: aborting due to 2 previous errors +error: aborting due to 1 previous error diff --git a/tests/ui/did_you_mean/issue-49746-unicode-confusable-in-float-literal-expt.rs b/tests/ui/did_you_mean/issue-49746-unicode-confusable-in-float-literal-expt.rs index 66d562d2eb5..5c2c3b8ec61 100644 --- a/tests/ui/did_you_mean/issue-49746-unicode-confusable-in-float-literal-expt.rs +++ b/tests/ui/did_you_mean/issue-49746-unicode-confusable-in-float-literal-expt.rs @@ -1,6 +1,5 @@ const UNIVERSAL_GRAVITATIONAL_CONSTANT: f64 = 6.674e−11; // m³⋅kg⁻¹⋅s⁻² //~^ ERROR expected at least one digit in exponent //~| ERROR unknown start of token: \u{2212} -//~| ERROR cannot subtract `{integer}` from `{float}` fn main() {} diff --git a/tests/ui/did_you_mean/issue-49746-unicode-confusable-in-float-literal-expt.stderr b/tests/ui/did_you_mean/issue-49746-unicode-confusable-in-float-literal-expt.stderr index 44bdbb93ff5..4b3d429c750 100644 --- a/tests/ui/did_you_mean/issue-49746-unicode-confusable-in-float-literal-expt.stderr +++ b/tests/ui/did_you_mean/issue-49746-unicode-confusable-in-float-literal-expt.stderr @@ -15,24 +15,5 @@ help: Unicode character '−' (Minus Sign) looks like '-' (Minus/Hyphen), but it LL | const UNIVERSAL_GRAVITATIONAL_CONSTANT: f64 = 6.674e-11; // m³⋅kg⁻¹⋅s⁻² | ~ -error[E0277]: cannot subtract `{integer}` from `{float}` - --> $DIR/issue-49746-unicode-confusable-in-float-literal-expt.rs:1:53 - | -LL | const UNIVERSAL_GRAVITATIONAL_CONSTANT: f64 = 6.674e−11; // m³⋅kg⁻¹⋅s⁻² - | ^ no implementation for `{float} - {integer}` - | - = help: the trait `Sub<{integer}>` is not implemented for `{float}` - = help: the following other types implement trait `Sub`: - - > - - > - - > - - > - and 48 others +error: aborting due to 2 previous errors -error: aborting due to 3 previous errors - -For more information about this error, try `rustc --explain E0277`.