提交 630d5f35 编写于 作者: I Igor Matuszewski

Don't suggest using \r in raw strings

上级 63dc7da7
......@@ -12,6 +12,7 @@ pub(crate) enum EscapeError {
LoneSlash,
InvalidEscape,
BareCarriageReturn,
BareCarriageReturnInRawString,
EscapeOnlyChar,
TooShortHexEscape,
......@@ -299,7 +300,7 @@ fn unescape_raw_str_or_byte_str<F>(literal_text: &str, mode: Mode, callback: &mu
chars.next();
Ok('\n')
},
('\r', _) => Err(EscapeError::BareCarriageReturn),
('\r', _) => Err(EscapeError::BareCarriageReturnInRawString),
(c, _) if mode.is_bytes() && !c.is_ascii() =>
Err(EscapeError::NonAsciiCharInByteString),
(c, _) => Ok(c),
......
......@@ -80,6 +80,11 @@ pub(crate) fn emit_unescape_error(
};
handler.span_err(span, msg);
}
EscapeError::BareCarriageReturnInRawString => {
assert!(mode.in_double_quotes());
let msg = "bare CR not allowed in raw string";
handler.span_err(span, msg);
}
EscapeError::InvalidEscape => {
let (c, span) = last_char();
......
......@@ -21,7 +21,7 @@ fn main() {
let _s = "foo bar"; //~ ERROR: bare CR not allowed in string
// the following string literal has a bare CR in it
let _s = r"bar foo"; //~ ERROR: bare CR not allowed in string
let _s = r"bar foo"; //~ ERROR: bare CR not allowed in raw string
// the following string literal has a bare CR in it
let _s = "foo\ bar"; //~ ERROR: unknown character escape: \r
......
......@@ -28,7 +28,7 @@ error: bare CR not allowed in string, use \r instead
LL | let _s = "foo bar";
| ^
error: bare CR not allowed in string, use \r instead
error: bare CR not allowed in raw string
--> $DIR/lex-bare-cr-string-literal-doc-comment.rs:24:19
|
LL | let _s = r"bar foo";
......
// ignore-tidy-cr
// compile-flags: -Z continue-parse-after-error
pub fn main() {
br"a "; //~ ERROR bare CR not allowed in string
br"a "; //~ ERROR bare CR not allowed in raw string
br"é"; //~ ERROR raw byte string must be ASCII
br##~"a"~##; //~ ERROR only `#` is allowed in raw string delimitation
}
......
error: bare CR not allowed in string, use \r instead
error: bare CR not allowed in raw string
--> $DIR/raw-byte-string-literals.rs:4:9
|
LL | br"a ";
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册