Skip to content

Commit 0b8c3de

Browse files
committed
Add warning cycle #42326.
1 parent ed6c6c9 commit 0b8c3de

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/libsyntax/parse/lexer/mod.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,20 @@ impl<'a> StringReader<'a> {
479479
}
480480

481481
self.with_str_from(start, |string| {
482-
Some(Symbol::intern(string))
482+
if string == "_" {
483+
self.sess.span_diagnostic
484+
.struct_span_warn(mk_sp(start, self.pos),
485+
"underscore literal suffix is not allowed")
486+
.warn("this was previously accepted by the compiler but is \
487+
being phased out; it will become a hard error in \
488+
a future release!")
489+
.note("for more information, see issue #42326 \
490+
<https://github.com/rust-lang/rust/issues/42326>")
491+
.emit();
492+
None
493+
} else {
494+
Some(Symbol::intern(string))
495+
}
483496
})
484497
}
485498

src/test/parse-fail/underscore-suffix-for-string.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,12 @@
99
// except according to those terms.
1010

1111
fn main() {
12-
let a = "Foo"_; //~ ERROR string literal with a suffix is invalid
12+
let _ = "Foo"_;
13+
//~^ WARNING underscore literal suffix is not allowed
14+
//~| WARNING this was previously accepted
15+
//~| NOTE issue #42326
1316
}
17+
18+
FAIL
19+
//~^ ERROR
20+
//~| NOTE

0 commit comments

Comments
 (0)