File tree Expand file tree Collapse file tree 3 files changed +45
-1
lines changed Expand file tree Collapse file tree 3 files changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -964,6 +964,13 @@ impl Cursor<'_> {
964964 debug_assert ! ( self . prev( ) == 'e' || self . prev( ) == 'E' ) ;
965965 if self . first ( ) == '-' || self . first ( ) == '+' {
966966 self . bump ( ) ;
967+ // Reject floats like `1e+_2` and `1.2e+_3` to avoid introducing identifier
968+ // tokens into the possible "fine-grained" tokenization of floats.
969+ // (Note that `1e_2` and `1.2e_3` are still accepted below because
970+ // they don't introduce identifiers, only suffixed integers.)
971+ if self . first ( ) == '_' {
972+ return false ;
973+ }
967974 }
968975 self . eat_decimal_digits ( )
969976 }
Original file line number Diff line number Diff line change @@ -32,4 +32,11 @@ fn main() {
3232 0o123 . 456 ; //~ ERROR: octal float literal is not supported
3333 0b101f64 ; //~ ERROR: binary float literal is not supported
3434 0b111 . 101 ; //~ ERROR: binary float literal is not supported
35+ 1e_2 ; // OK for now
36+ 1.2e_3 ; // OK for now
37+ 1e+_2 ; //~ ERROR expected at least one digit in exponent
38+ 1e-_2 ; //~ ERROR expected at least one digit in exponent
39+ 1.2e+_3 ; //~ ERROR expected at least one digit in exponent
40+ 1.2e-_3 ; //~ ERROR expected at least one digit in exponent
41+ 0x539 . 0 ; //~ ERROR: hexadecimal float literal is not supported
3542}
Original file line number Diff line number Diff line change @@ -106,6 +106,36 @@ error: binary float literal is not supported
106106LL | 0b111.101;
107107 | ^^^^^^^^^
108108
109+ error: expected at least one digit in exponent
110+ --> $DIR/lex-bad-numeric-literals.rs:37:5
111+ |
112+ LL | 1e+_2;
113+ | ^^^^^
114+
115+ error: expected at least one digit in exponent
116+ --> $DIR/lex-bad-numeric-literals.rs:38:5
117+ |
118+ LL | 1e-_2;
119+ | ^^^^^
120+
121+ error: expected at least one digit in exponent
122+ --> $DIR/lex-bad-numeric-literals.rs:39:5
123+ |
124+ LL | 1.2e+_3;
125+ | ^^^^^^^
126+
127+ error: expected at least one digit in exponent
128+ --> $DIR/lex-bad-numeric-literals.rs:40:5
129+ |
130+ LL | 1.2e-_3;
131+ | ^^^^^^^
132+
133+ error: hexadecimal float literal is not supported
134+ --> $DIR/lex-bad-numeric-literals.rs:41:5
135+ |
136+ LL | 0x539.0;
137+ | ^^^^^^^
138+
109139error: octal float literal is not supported
110140 --> $DIR/lex-bad-numeric-literals.rs:5:5
111141 |
@@ -164,6 +194,6 @@ error: binary float literal is not supported
164194LL | 0b101f64;
165195 | ^^^^^^^^ not supported
166196
167- error: aborting due to 26 previous errors
197+ error: aborting due to 31 previous errors
168198
169199For more information about this error, try `rustc --explain E0768`.
You can’t perform that action at this time.
0 commit comments