From ed6c6c9a11f7deddbd1f209c5e7de12bc420c550 Mon Sep 17 00:00:00 2001 From: Masaki Hara Date: Sun, 14 May 2017 21:37:50 +0900 Subject: [PATCH] Disallow underscore suffix for string-like literals. --- src/libsyntax/parse/lexer/mod.rs | 6 +----- src/test/parse-fail/underscore-suffix-for-string.rs | 13 +++++++++++++ 2 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 src/test/parse-fail/underscore-suffix-for-string.rs 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 @@ fn scan_optional_raw_name(&mut self) -> Option { } self.with_str_from(start, |string| { - if string == "_" { - None - } else { - Some(Symbol::intern(string)) - } + 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 new file mode 100644 index 00000000000..a19bbe08377 --- /dev/null +++ b/src/test/parse-fail/underscore-suffix-for-string.rs @@ -0,0 +1,13 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + let a = "Foo"_; //~ ERROR string literal with a suffix is invalid +} -- 2.44.0