Auto merge of #41990 - qnighy:disallow-underscore-suffix-for-string-like-literals, r=nikomatsakis
Disallow underscore suffix for string-like literals. This patch turns string/bytestring/char/byte literals followed by an underscore, like `"Foo"_`, to an error. `scan_optional_raw_name` will parse `_` as a valid raw name, but it will be rejected by the parser. I also considered just stopping parsing when the suffix is `_`, but in that case `"Foo"_` will be lexed as two valid tokens. Fixes the latter half of #41723.
This commit is contained in:
@@ -480,6 +480,15 @@ impl<'a> StringReader<'a> {
|
||||
|
||||
self.with_str_from(start, |string| {
|
||||
if string == "_" {
|
||||
self.sess.span_diagnostic
|
||||
.struct_span_warn(mk_sp(start, self.pos),
|
||||
"underscore literal suffix is not allowed")
|
||||
.warn("this was previously accepted by the compiler but is \
|
||||
being phased out; it will become a hard error in \
|
||||
a future release!")
|
||||
.note("for more information, see issue #42326 \
|
||||
<https://github.com/rust-lang/rust/issues/42326>")
|
||||
.emit();
|
||||
None
|
||||
} else {
|
||||
Some(Symbol::intern(string))
|
||||
|
||||
Reference in New Issue
Block a user