From 4d65ef45491b62fbecdb9a24822c216aa96bb34e Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Fri, 10 Jul 2015 22:31:44 +0300 Subject: [PATCH] =?UTF-8?q?Tell=20unicode=20escapes=20can=E2=80=99t=20be?= =?UTF-8?q?=20used=20as=20bytes=20earlier/more?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/libsyntax/parse/lexer/mod.rs | 30 +++++++++---------- .../parse-fail/issue-23620-invalid-escapes.rs | 8 +++-- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index edaac3b09bad..b6a3788dacc3 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -738,26 +738,24 @@ impl<'a> StringReader<'a> { return match e { 'n' | 'r' | 't' | '\\' | '\'' | '"' | '0' => true, 'x' => self.scan_byte_escape(delim, !ascii_only), - 'u' if self.curr_is('{') => { - let valid = self.scan_unicode_escape(delim); - if valid && ascii_only { - self.err_span_( - start, - self.last_pos, + 'u' => { + let valid = if self.curr_is('{') { + self.scan_unicode_escape(delim) && !ascii_only + } else { + self.err_span_(start, self.last_pos, + "incorrect unicode escape sequence"); + self.help_span_(start, self.last_pos, + "format of unicode escape sequences is `\\u{…}`"); + false + }; + if ascii_only { + self.err_span_(start, self.last_pos, "unicode escape sequences cannot be used as a byte or in \ a byte string" ); - false - } else { - valid } - } - 'u' if !ascii_only => { - self.err_span_(start, self.last_pos, - "incomplete unicode escape sequence"); - self.help_span_(start, self.last_pos, - "format of unicode escape sequences is `\\u{…}`"); - false + valid + } '\n' if delim == '"' => { self.consume_whitespace(); diff --git a/src/test/parse-fail/issue-23620-invalid-escapes.rs b/src/test/parse-fail/issue-23620-invalid-escapes.rs index 98db3efe114b..1790b9164b7e 100644 --- a/src/test/parse-fail/issue-23620-invalid-escapes.rs +++ b/src/test/parse-fail/issue-23620-invalid-escapes.rs @@ -16,7 +16,8 @@ fn main() { //~^ ERROR unicode escape sequences cannot be used as a byte or in a byte string let _ = b'\u'; - //~^ ERROR unknown byte escape: u + //~^ ERROR incorrect unicode escape sequence + //~^^ ERROR unicode escape sequences cannot be used as a byte or in a byte string let _ = b'\x5'; //~^ ERROR numeric character escape is too short @@ -35,11 +36,12 @@ fn main() { let _ = b"\u{a4a4} \xf \u"; //~^ ERROR unicode escape sequences cannot be used as a byte or in a byte string //~^^ ERROR illegal character in numeric character escape: - //~^^^ ERROR unknown byte escape: u + //~^^^ ERROR incorrect unicode escape sequence + //~^^^^ ERROR unicode escape sequences cannot be used as a byte or in a byte string let _ = "\u{ffffff} \xf \u"; //~^ ERROR illegal unicode character escape //~^^ ERROR illegal character in numeric character escape: //~^^^ ERROR form of character escape may only be used with characters in the range [\x00-\x7f] - //~^^^^ ERROR incomplete unicode escape sequence + //~^^^^ ERROR incorrect unicode escape sequence }