Skip to content

Commit d03e4dd

Browse files
committed
Use LitKind::Err for floats with empty exponents.
This prevents a follow-up type error in a test, which seems fine.
1 parent 1e4f9e3 commit d03e4dd

File tree

3 files changed

+5
-23
lines changed

3 files changed

+5
-23
lines changed

compiler/rustc_parse/src/lexer/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,9 +501,11 @@ impl<'sess, 'src> StringReader<'sess, 'src> {
501501
(kind, self.symbol_from_to(start, end))
502502
}
503503
rustc_lexer::LiteralKind::Float { base, empty_exponent } => {
504+
let mut kind = token::Float;
504505
if empty_exponent {
505506
let span = self.mk_sp(start, self.pos);
506-
self.dcx().emit_err(errors::EmptyExponentFloat { span });
507+
let guar = self.dcx().emit_err(errors::EmptyExponentFloat { span });
508+
kind = token::Err(guar);
507509
}
508510
let base = match base {
509511
Base::Hexadecimal => Some("hexadecimal"),
@@ -515,7 +517,7 @@ impl<'sess, 'src> StringReader<'sess, 'src> {
515517
let span = self.mk_sp(start, end);
516518
self.dcx().emit_err(errors::FloatLiteralUnsupportedBase { span, base });
517519
}
518-
(token::Float, self.symbol_from_to(start, end))
520+
(kind, self.symbol_from_to(start, end))
519521
}
520522
}
521523
}
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const UNIVERSAL_GRAVITATIONAL_CONSTANT: f64 = 6.674e−11; // m³⋅kg⁻¹⋅s⁻²
22
//~^ ERROR expected at least one digit in exponent
33
//~| ERROR unknown start of token: \u{2212}
4-
//~| ERROR cannot subtract `{integer}` from `{float}`
54

65
fn main() {}

tests/ui/did_you_mean/issue-49746-unicode-confusable-in-float-literal-expt.stderr

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,5 @@ help: Unicode character '−' (Minus Sign) looks like '-' (Minus/Hyphen), but it
1515
LL | const UNIVERSAL_GRAVITATIONAL_CONSTANT: f64 = 6.674e-11; // m³⋅kg⁻¹⋅s⁻²
1616
| ~
1717

18-
error[E0277]: cannot subtract `{integer}` from `{float}`
19-
--> $DIR/issue-49746-unicode-confusable-in-float-literal-expt.rs:1:53
20-
|
21-
LL | const UNIVERSAL_GRAVITATIONAL_CONSTANT: f64 = 6.674e−11; // m³⋅kg⁻¹⋅s⁻²
22-
| ^ no implementation for `{float} - {integer}`
23-
|
24-
= help: the trait `Sub<{integer}>` is not implemented for `{float}`
25-
= help: the following other types implement trait `Sub<Rhs>`:
26-
<isize as Sub>
27-
<isize as Sub<&isize>>
28-
<i8 as Sub>
29-
<i8 as Sub<&i8>>
30-
<i16 as Sub>
31-
<i16 as Sub<&i16>>
32-
<i32 as Sub>
33-
<i32 as Sub<&i32>>
34-
and 48 others
35-
36-
error: aborting due to 3 previous errors
18+
error: aborting due to 2 previous errors
3719

38-
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)