From ed6c6c9a11f7deddbd1f209c5e7de12bc420c550 Mon Sep 17 00:00:00 2001 From: Masaki Hara Date: Sun, 14 May 2017 21:37:50 +0900 Subject: Disallow underscore suffix for string-like literals. --- src/libsyntax/parse/lexer/mod.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'src/libsyntax/parse') diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index a83b19c7334..480049f845c 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -479,11 +479,7 @@ impl<'a> StringReader<'a> { } self.with_str_from(start, |string| { - if string == "_" { - None - } else { - Some(Symbol::intern(string)) - } + Some(Symbol::intern(string)) }) } -- cgit 1.4.1-3-g733a5 From 0b8c3de678065b82ae955b65192b7927b467f7a6 Mon Sep 17 00:00:00 2001 From: Masaki Hara Date: Wed, 31 May 2017 16:43:47 +0900 Subject: Add warning cycle #42326. --- src/libsyntax/parse/lexer/mod.rs | 15 ++++++++++++++- src/test/parse-fail/underscore-suffix-for-string.rs | 9 ++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) (limited to 'src/libsyntax/parse') diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index 480049f845c..e8fbc00d36f 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -479,7 +479,20 @@ impl<'a> StringReader<'a> { } self.with_str_from(start, |string| { - Some(Symbol::intern(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 \ + ") + .emit(); + None + } else { + Some(Symbol::intern(string)) + } }) } diff --git a/src/test/parse-fail/underscore-suffix-for-string.rs b/src/test/parse-fail/underscore-suffix-for-string.rs index a19bbe08377..05de5f8e194 100644 --- a/src/test/parse-fail/underscore-suffix-for-string.rs +++ b/src/test/parse-fail/underscore-suffix-for-string.rs @@ -9,5 +9,12 @@ // except according to those terms. fn main() { - let a = "Foo"_; //~ ERROR string literal with a suffix is invalid + let _ = "Foo"_; + //~^ WARNING underscore literal suffix is not allowed + //~| WARNING this was previously accepted + //~| NOTE issue #42326 } + +FAIL +//~^ ERROR +//~| NOTE -- cgit 1.4.1-3-g733a5