Tell unicode escapes can’t be used as bytes earlier/more
This commit is contained in:
@@ -738,26 +738,24 @@ impl<'a> StringReader<'a> {
|
|||||||
return match e {
|
return match e {
|
||||||
'n' | 'r' | 't' | '\\' | '\'' | '"' | '0' => true,
|
'n' | 'r' | 't' | '\\' | '\'' | '"' | '0' => true,
|
||||||
'x' => self.scan_byte_escape(delim, !ascii_only),
|
'x' => self.scan_byte_escape(delim, !ascii_only),
|
||||||
'u' if self.curr_is('{') => {
|
'u' => {
|
||||||
let valid = self.scan_unicode_escape(delim);
|
let valid = if self.curr_is('{') {
|
||||||
if valid && ascii_only {
|
self.scan_unicode_escape(delim) && !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 {
|
} else {
|
||||||
valid
|
|
||||||
}
|
|
||||||
}
|
|
||||||
'u' if !ascii_only => {
|
|
||||||
self.err_span_(start, self.last_pos,
|
self.err_span_(start, self.last_pos,
|
||||||
"incomplete unicode escape sequence");
|
"incorrect unicode escape sequence");
|
||||||
self.help_span_(start, self.last_pos,
|
self.help_span_(start, self.last_pos,
|
||||||
"format of unicode escape sequences is `\\u{…}`");
|
"format of unicode escape sequences is `\\u{…}`");
|
||||||
false
|
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"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
valid
|
||||||
|
|
||||||
}
|
}
|
||||||
'\n' if delim == '"' => {
|
'\n' if delim == '"' => {
|
||||||
self.consume_whitespace();
|
self.consume_whitespace();
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ fn main() {
|
|||||||
//~^ ERROR unicode escape sequences cannot be used as a byte or in a byte string
|
//~^ ERROR unicode escape sequences cannot be used as a byte or in a byte string
|
||||||
|
|
||||||
let _ = b'\u';
|
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';
|
let _ = b'\x5';
|
||||||
//~^ ERROR numeric character escape is too short
|
//~^ ERROR numeric character escape is too short
|
||||||
@@ -35,11 +36,12 @@ fn main() {
|
|||||||
let _ = b"\u{a4a4} \xf \u";
|
let _ = b"\u{a4a4} \xf \u";
|
||||||
//~^ ERROR unicode escape sequences cannot be used as a byte or in a byte string
|
//~^ ERROR unicode escape sequences cannot be used as a byte or in a byte string
|
||||||
//~^^ ERROR illegal character in numeric character escape:
|
//~^^ 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";
|
let _ = "\u{ffffff} \xf \u";
|
||||||
//~^ ERROR illegal unicode character escape
|
//~^ ERROR illegal unicode character escape
|
||||||
//~^^ ERROR illegal character in numeric 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 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
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user