diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index 507bd9de2a11a..84a13db987abe 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -742,6 +742,16 @@ impl<'a> StringReader<'a> { valid } } + 'u' => { + self.err_span_( + escaped_pos, + self.last_pos, + "`\\u` in string literals start unicode escape sequences; \ + for example, use `\\u{30a2}` to specify codepoint U+30A2, \ + or did you mean `\\\\u`?" + ); + false + } '\n' if delim == '"' => { self.consume_whitespace(); true diff --git a/src/test/compile-fail/unicode-escape-sequences.rs b/src/test/compile-fail/unicode-escape-sequences.rs new file mode 100644 index 0000000000000..1ed4b6d0de8d7 --- /dev/null +++ b/src/test/compile-fail/unicode-escape-sequences.rs @@ -0,0 +1,15 @@ +// Copyright 2015 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. + +// Test that a covariant struct permits the lifetime of a reference to +// be shortened. + +fn main() { "\u123"; } +//~^ error: `\u` in string literals start unicode escape sequences; for example, use `\u{30a2}`