File tree 4 files changed +28
-23
lines changed
4 files changed +28
-23
lines changed Original file line number Diff line number Diff line change @@ -88,7 +88,9 @@ pub enum TokenKind {
88
88
/// tokens.
89
89
UnknownPrefix ,
90
90
91
- /// Examples: `"12_u8"`, `"1.0e-40"`, `b"123`.
91
+ /// Examples: `12u8`, `1.0e-40`, `b"123"`. Note that `_` is an invalid
92
+ /// suffix, but may be present here on string and float literals. Users of
93
+ /// this type will need to check for and reject that case.
92
94
///
93
95
/// See [LiteralKind] for more details.
94
96
Literal { kind : LiteralKind , suffix_start : u32 } ,
@@ -840,12 +842,13 @@ impl Cursor<'_> {
840
842
self . eat_decimal_digits ( )
841
843
}
842
844
843
- // Eats the suffix of the literal, e.g. "_u8 ".
845
+ // Eats the suffix of the literal, e.g. "u8 ".
844
846
fn eat_literal_suffix ( & mut self ) {
845
847
self . eat_identifier ( ) ;
846
848
}
847
849
848
- // Eats the identifier.
850
+ // Eats the identifier. Note: succeeds on `_`, which isn't a valid
851
+ // identifer.
849
852
fn eat_identifier ( & mut self ) {
850
853
if !is_id_start ( self . first ( ) ) {
851
854
return ;
Original file line number Diff line number Diff line change @@ -175,20 +175,10 @@ impl<'a> StringReader<'a> {
175
175
if string == "_" {
176
176
self . sess
177
177
. span_diagnostic
178
- . struct_span_warn (
178
+ . struct_span_err (
179
179
self . mk_sp ( suffix_start, self . pos ) ,
180
180
"underscore literal suffix is not allowed" ,
181
181
)
182
- . warn (
183
- "this was previously accepted by the compiler but is \
184
- being phased out; it will become a hard error in \
185
- a future release!",
186
- )
187
- . note (
188
- "see issue #42326 \
189
- <https://github.com/rust-lang/rust/issues/42326> \
190
- for more information",
191
- )
192
182
. emit ( ) ;
193
183
None
194
184
} else {
Original file line number Diff line number Diff line change 1
- // check-pass
1
+ macro_rules! sink {
2
+ ( $tt: tt) => { ( ) }
3
+ }
2
4
3
5
fn main ( ) {
4
6
let _ = "Foo" _;
5
- //~^ WARNING underscore literal suffix is not allowed
6
- //~| WARNING this was previously accepted
7
- //~| NOTE issue #42326
7
+ //~^ ERROR underscore literal suffix is not allowed
8
+
9
+ // This is ok, because `__` is a valid identifier and the macro consumes it
10
+ // before proper parsing happens.
11
+ let _ = sink ! ( "Foo" __) ;
12
+
13
+ // This is not ok, even as an input to a macro, because the `_` suffix is
14
+ // never allowed.
15
+ sink ! ( "Foo" _) ;
16
+ //~^ ERROR underscore literal suffix is not allowed
8
17
}
Original file line number Diff line number Diff line change 1
- warning : underscore literal suffix is not allowed
2
- --> $DIR/underscore-suffix-for-string.rs:4 :18
1
+ error : underscore literal suffix is not allowed
2
+ --> $DIR/underscore-suffix-for-string.rs:6 :18
3
3
|
4
4
LL | let _ = "Foo"_;
5
5
| ^
6
+
7
+ error: underscore literal suffix is not allowed
8
+ --> $DIR/underscore-suffix-for-string.rs:15:16
6
9
|
7
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8
- = note: see issue #42326 <https://github.com/rust-lang/rust/issues/42326> for more information
10
+ LL | sink!("Foo"_);
11
+ | ^
9
12
10
- warning: 1 warning emitted
13
+ error: aborting due to 2 previous errors
11
14
You can’t perform that action at this time.
0 commit comments