Don't suggest using \r in raw strings
This commit is contained in:
parent
63dc7da703
commit
630d5f355f
6 changed files with 11 additions and 5 deletions
|
@ -12,6 +12,7 @@ pub(crate) enum EscapeError {
|
|||
LoneSlash,
|
||||
InvalidEscape,
|
||||
BareCarriageReturn,
|
||||
BareCarriageReturnInRawString,
|
||||
EscapeOnlyChar,
|
||||
|
||||
TooShortHexEscape,
|
||||
|
@ -299,7 +300,7 @@ where
|
|||
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";
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// 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
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
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
";
|
||||
|
|
Loading…
Add table
Reference in a new issue