diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index 0bcd457851890..e2656bea48339 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -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 \ + ") + .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 new file mode 100644 index 0000000000000..05de5f8e1941b --- /dev/null +++ b/src/test/parse-fail/underscore-suffix-for-string.rs @@ -0,0 +1,20 @@ +// 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 _ = "Foo"_; + //~^ WARNING underscore literal suffix is not allowed + //~| WARNING this was previously accepted + //~| NOTE issue #42326 +} + +FAIL +//~^ ERROR +//~| NOTE