File tree Expand file tree Collapse file tree 4 files changed +28
-23
lines changed Expand file tree Collapse file tree 4 files changed +28
-23
lines changed Original file line number Diff line number Diff line change @@ -88,7 +88,9 @@ pub enum TokenKind {
8888 /// tokens.
8989 UnknownPrefix ,
9090
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.
9294 ///
9395 /// See [LiteralKind] for more details.
9496 Literal { kind : LiteralKind , suffix_start : u32 } ,
@@ -840,12 +842,13 @@ impl Cursor<'_> {
840842 self . eat_decimal_digits ( )
841843 }
842844
843- // Eats the suffix of the literal, e.g. "_u8 ".
845+ // Eats the suffix of the literal, e.g. "u8 ".
844846 fn eat_literal_suffix ( & mut self ) {
845847 self . eat_identifier ( ) ;
846848 }
847849
848- // Eats the identifier.
850+ // Eats the identifier. Note: succeeds on `_`, which isn't a valid
851+ // identifer.
849852 fn eat_identifier ( & mut self ) {
850853 if !is_id_start ( self . first ( ) ) {
851854 return ;
Original file line number Diff line number Diff line change @@ -175,20 +175,10 @@ impl<'a> StringReader<'a> {
175175 if string == "_" {
176176 self . sess
177177 . span_diagnostic
178- . struct_span_warn (
178+ . struct_span_err (
179179 self . mk_sp ( suffix_start, self . pos ) ,
180180 "underscore literal suffix is not allowed" ,
181181 )
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- )
192182 . emit ( ) ;
193183 None
194184 } else {
Original file line number Diff line number Diff line change 1- // check-pass
1+ macro_rules! sink {
2+ ( $tt: tt) => { ( ) }
3+ }
24
35fn main ( ) {
46 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
817}
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
33 |
44LL | let _ = "Foo"_;
55 | ^
6+
7+ error: underscore literal suffix is not allowed
8+ --> $DIR/underscore-suffix-for-string.rs:15:16
69 |
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+ | ^
912
10- warning: 1 warning emitted
13+ error: aborting due to 2 previous errors
1114
You can’t perform that action at this time.
0 commit comments