From d4e0e5228111cd47294342a60b5f8af44c65e206 Mon Sep 17 00:00:00 2001 From: Malo Jaffré Date: Thu, 17 Aug 2017 20:02:13 +0200 Subject: Accept underscores in unicode escapes Fixes #43692. --- src/test/parse-fail/issue-23620-invalid-escapes.rs | 9 ++++----- src/test/parse-fail/issue-43692.rs | 15 +++++++++++++++ src/test/parse-fail/new-unicode-escapes-2.rs | 2 +- src/test/parse-fail/new-unicode-escapes-3.rs | 3 ++- src/test/parse-fail/new-unicode-escapes-4.rs | 2 -- src/test/run-pass/issue-43692.rs | 14 ++++++++++++++ 6 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 src/test/parse-fail/issue-43692.rs create mode 100644 src/test/run-pass/issue-43692.rs (limited to 'src/test') diff --git a/src/test/parse-fail/issue-23620-invalid-escapes.rs b/src/test/parse-fail/issue-23620-invalid-escapes.rs index 821149d1d00..dfeaae49002 100644 --- a/src/test/parse-fail/issue-23620-invalid-escapes.rs +++ b/src/test/parse-fail/issue-23620-invalid-escapes.rs @@ -41,9 +41,8 @@ fn main() { //~^^^ 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 invalid unicode character escape - //~^^ ERROR invalid character in numeric character escape: - //~^^^ ERROR form of character escape may only be used with characters in the range [\x00-\x7f] - //~^^^^ ERROR incorrect unicode escape sequence + let _ = "\xf \u"; + //~^ ERROR invalid character in numeric character escape: + //~^^ ERROR form of character escape may only be used with characters in the range [\x00-\x7f] + //~^^^ ERROR incorrect unicode escape sequence } diff --git a/src/test/parse-fail/issue-43692.rs b/src/test/parse-fail/issue-43692.rs new file mode 100644 index 00000000000..eb5d050e102 --- /dev/null +++ b/src/test/parse-fail/issue-43692.rs @@ -0,0 +1,15 @@ +// 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. + +// compile-flags: -Z parse-only + +fn main() { + '\u{_10FFFF}'; //~ ERROR invalid start of unicode escape +} diff --git a/src/test/parse-fail/new-unicode-escapes-2.rs b/src/test/parse-fail/new-unicode-escapes-2.rs index 3eaea86b8bc..cdadaef1b59 100644 --- a/src/test/parse-fail/new-unicode-escapes-2.rs +++ b/src/test/parse-fail/new-unicode-escapes-2.rs @@ -11,5 +11,5 @@ // compile-flags: -Z parse-only pub fn main() { - let s = "\u{260311111111}"; //~ ERROR overlong unicode escape (can have at most 6 hex digits) + let s = "\u{260311111111}"; //~ ERROR overlong unicode escape (must have at most 6 hex digits) } diff --git a/src/test/parse-fail/new-unicode-escapes-3.rs b/src/test/parse-fail/new-unicode-escapes-3.rs index d12bb63111b..8189bf67712 100644 --- a/src/test/parse-fail/new-unicode-escapes-3.rs +++ b/src/test/parse-fail/new-unicode-escapes-3.rs @@ -11,5 +11,6 @@ // compile-flags: -Z parse-only pub fn main() { - let s = "\u{d805}"; //~ ERROR invalid unicode character escape + let s1 = "\u{d805}"; //~ ERROR invalid unicode character escape + let s2 = "\u{ffffff}"; //~ ERROR invalid unicode character escape } diff --git a/src/test/parse-fail/new-unicode-escapes-4.rs b/src/test/parse-fail/new-unicode-escapes-4.rs index 5615ac8df01..8770fb319df 100644 --- a/src/test/parse-fail/new-unicode-escapes-4.rs +++ b/src/test/parse-fail/new-unicode-escapes-4.rs @@ -13,6 +13,4 @@ pub fn main() { let s = "\u{lol}"; //~^ ERROR invalid character in unicode escape: l - //~^^ ERROR invalid character in unicode escape: o - //~^^^ ERROR invalid character in unicode escape: l } diff --git a/src/test/run-pass/issue-43692.rs b/src/test/run-pass/issue-43692.rs new file mode 100644 index 00000000000..23e96f8c1bf --- /dev/null +++ b/src/test/run-pass/issue-43692.rs @@ -0,0 +1,14 @@ +// 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() { + assert_eq!('\u{10__FFFF}', '\u{10FFFF}'); + assert_eq!("\u{10_F0FF__}foo\u{1_0_0_0__}", "\u{10F0FF}foo\u{1000}"); +} -- cgit 1.4.1-3-g733a5