From 3d6afbe539f13cd1f7284d0b7f17adc72bcbf3ff Mon Sep 17 00:00:00 2001 From: York Xiang Date: Sun, 5 Jul 2015 09:25:18 +0800 Subject: [PATCH] Show better error message for incorrect unicode escape sequences syntax --- src/libsyntax/parse/lexer/mod.rs | 10 ++++++++++ src/test/compile-fail/unicode-escape-sequences.rs | 15 +++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 src/test/compile-fail/unicode-escape-sequences.rs 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}`