Skip to content

syntax: Remove deprecated unicode escapes #23132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 2 additions & 22 deletions src/libsyntax/parse/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,13 +777,6 @@ impl<'a> StringReader<'a> {
}
}

fn old_escape_warning(&mut self, sp: Span) {
self.span_diagnostic
.span_warn(sp, "\\U00ABCD12 and \\uABCD escapes are deprecated");
self.span_diagnostic
.fileline_help(sp, "use \\u{ABCD12} escapes instead");
}

/// Scan for a single (possibly escaped) byte or char
/// in a byte, (non-raw) byte string, char, or (non-raw) string literal.
/// `start` is the position of `first_source_char`, which is already consumed.
Expand All @@ -803,21 +796,8 @@ impl<'a> StringReader<'a> {
return match e {
'n' | 'r' | 't' | '\\' | '\'' | '"' | '0' => true,
'x' => self.scan_byte_escape(delim, !ascii_only),
'u' if !ascii_only => {
if self.curr == Some('{') {
self.scan_unicode_escape(delim)
} else {
let res = self.scan_hex_digits(4, delim, false);
let sp = codemap::mk_sp(escaped_pos, self.last_pos);
self.old_escape_warning(sp);
res
}
}
'U' if !ascii_only => {
let res = self.scan_hex_digits(8, delim, false);
let sp = codemap::mk_sp(escaped_pos, self.last_pos);
self.old_escape_warning(sp);
res
'u' if self.curr_is('{') => {
self.scan_unicode_escape(delim)
}
'\n' if delim == '"' => {
self.consume_whitespace();
Expand Down
22 changes: 0 additions & 22 deletions src/test/parse-fail/lex-bad-char-literals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,14 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

static c: char =
'\u539_' //~ ERROR: illegal character in numeric character escape
//~^ WARNING: \uABCD escapes are deprecated
;

static c2: char =
'\Uffffffff' //~ ERROR: illegal numeric character escape
//~^ WARNING: \uABCD escapes are deprecated
;

static c3: char =
'\x1' //~ ERROR: numeric character escape is too short
;

static c4: char =
'\u23q' //~ ERROR: illegal character in numeric character escape
//~^ WARNING: \uABCD escapes are deprecated
;
//~^^^ ERROR: numeric character escape is too short

static s: &'static str =
"\x1" //~ ERROR: numeric character escape is too short
;

static s2: &'static str =
"\u23q" //~ ERROR: illegal character in numeric character escape
//~^ ERROR: numeric character escape is too short
//~^^ WARNING: \uABCD escapes are deprecated
;

static c: char =
'\●' //~ ERROR: unknown character escape
;
Expand Down
9 changes: 5 additions & 4 deletions src/test/pretty/block-comment-wchar.pp
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,11 @@
fn main() {
// Taken from http://www.unicode.org/Public/UNIDATA/PropList.txt
let chars =
['\x0A', '\x0B', '\x0C', '\x0D', '\x20', '\u0085', '\u00A0', '\u1680',
'\u2000', '\u2001', '\u2002', '\u2003', '\u2004', '\u2005', '\u2006',
'\u2007', '\u2008', '\u2009', '\u200A', '\u2028', '\u2029', '\u202F',
'\u205F', '\u3000'];
['\x0A', '\x0B', '\x0C', '\x0D', '\x20', '\u{85}', '\u{A0}',
'\u{1680}', '\u{2000}', '\u{2001}', '\u{2002}', '\u{2003}',
'\u{2004}', '\u{2005}', '\u{2006}', '\u{2007}', '\u{2008}',
'\u{2009}', '\u{200A}', '\u{2028}', '\u{2029}', '\u{202F}',
'\u{205F}', '\u{3000}'];
for c in &chars {
let ws = c.is_whitespace();
println!("{} {}" , c , ws);
Expand Down
9 changes: 5 additions & 4 deletions src/test/pretty/block-comment-wchar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,11 @@ fn f() {
fn main() {
// Taken from http://www.unicode.org/Public/UNIDATA/PropList.txt
let chars =
['\x0A', '\x0B', '\x0C', '\x0D', '\x20', '\u0085', '\u00A0', '\u1680',
'\u2000', '\u2001', '\u2002', '\u2003', '\u2004', '\u2005', '\u2006',
'\u2007', '\u2008', '\u2009', '\u200A', '\u2028', '\u2029', '\u202F',
'\u205F', '\u3000'];
['\x0A', '\x0B', '\x0C', '\x0D', '\x20', '\u{85}', '\u{A0}',
'\u{1680}', '\u{2000}', '\u{2001}', '\u{2002}', '\u{2003}',
'\u{2004}', '\u{2005}', '\u{2006}', '\u{2007}', '\u{2008}',
'\u{2009}', '\u{200A}', '\u{2028}', '\u{2029}', '\u{202F}',
'\u{205F}', '\u{3000}'];
for c in &chars {
let ws = c.is_whitespace();
println!("{} {}", c , ws);
Expand Down
12 changes: 6 additions & 6 deletions src/test/run-pass/nul-characters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

pub fn main()
{
let all_nuls1 = "\0\x00\u0000\U00000000";
let all_nuls2 = "\U00000000\u0000\x00\0";
let all_nuls3 = "\u0000\U00000000\x00\0";
let all_nuls4 = "\x00\u0000\0\U00000000";
let all_nuls1 = "\0\x00\u{0}\u{0}";
let all_nuls2 = "\u{0}\u{0}\x00\0";
let all_nuls3 = "\u{0}\u{0}\x00\0";
let all_nuls4 = "\x00\u{0}\0\u{0}";

// sizes for two should suffice
assert_eq!(all_nuls1.len(), 4);
Expand All @@ -35,8 +35,8 @@ pub fn main()

// testing equality between explicit character literals
assert_eq!('\0', '\x00');
assert_eq!('\u0000', '\x00');
assert_eq!('\u0000', '\U00000000');
assert_eq!('\u{0}', '\x00');
assert_eq!('\u{0}', '\u{0}');

// NUL characters should make a difference
assert!("Hello World" != "Hello \0World");
Expand Down
Binary file modified src/test/run-pass/raw-str.rs
Binary file not shown.
10 changes: 5 additions & 5 deletions src/test/run-pass/utf8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub fn main() {
assert_eq!(y_diaeresis as int, 0xff);
assert_eq!(pi as int, 0x3a0);

assert_eq!(pi as int, '\u03a0' as int);
assert_eq!(pi as int, '\u{3a0}' as int);
assert_eq!('\x0a' as int, '\n' as int);

let bhutan: String = "འབྲུག་ཡུལ།".to_string();
Expand All @@ -33,11 +33,11 @@ pub fn main() {
let austria: String = "Österreich".to_string();

let bhutan_e: String =
"\u0f60\u0f56\u0fb2\u0f74\u0f42\u0f0b\u0f61\u0f74\u0f63\u0f0d".to_string();
let japan_e: String = "\u65e5\u672c".to_string();
"\u{f60}\u{f56}\u{fb2}\u{f74}\u{f42}\u{f0b}\u{f61}\u{f74}\u{f63}\u{f0d}".to_string();
let japan_e: String = "\u{65e5}\u{672c}".to_string();
let uzbekistan_e: String =
"\u040e\u0437\u0431\u0435\u043a\u0438\u0441\u0442\u043e\u043d".to_string();
let austria_e: String = "\u00d6sterreich".to_string();
"\u{40e}\u{437}\u{431}\u{435}\u{43a}\u{438}\u{441}\u{442}\u{43e}\u{43d}".to_string();
let austria_e: String = "\u{d6}sterreich".to_string();

let oo: char = 'Ö';
assert_eq!(oo as int, 0xd6);
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/utf8_chars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::str;

pub fn main() {
// Chars of 1, 2, 3, and 4 bytes
let chs: Vec<char> = vec!('e', 'é', '€', '\U00010000');
let chs: Vec<char> = vec!('e', 'é', '€', '\u{10000}');
let s: String = chs.iter().cloned().collect();
let schs: Vec<char> = s.chars().collect();

Expand Down