File tree 3 files changed +45
-1
lines changed
3 files changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -964,6 +964,13 @@ impl Cursor<'_> {
964
964
debug_assert ! ( self . prev( ) == 'e' || self . prev( ) == 'E' ) ;
965
965
if self . first ( ) == '-' || self . first ( ) == '+' {
966
966
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
+ }
967
974
}
968
975
self . eat_decimal_digits ( )
969
976
}
Original file line number Diff line number Diff line change @@ -32,4 +32,11 @@ fn main() {
32
32
0o123 . 456 ; //~ ERROR: octal float literal is not supported
33
33
0b101f64 ; //~ ERROR: binary float literal is not supported
34
34
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
35
42
}
Original file line number Diff line number Diff line change @@ -106,6 +106,36 @@ error: binary float literal is not supported
106
106
LL | 0b111.101;
107
107
| ^^^^^^^^^
108
108
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
+
109
139
error: octal float literal is not supported
110
140
--> $DIR/lex-bad-numeric-literals.rs:5:5
111
141
|
@@ -164,6 +194,6 @@ error: binary float literal is not supported
164
194
LL | 0b101f64;
165
195
| ^^^^^^^^ not supported
166
196
167
- error: aborting due to 26 previous errors
197
+ error: aborting due to 31 previous errors
168
198
169
199
For more information about this error, try `rustc --explain E0768`.
You can’t perform that action at this time.
0 commit comments