Skip to content

Commit 630d5f3

Browse files
committed
Don't suggest using \r in raw strings
1 parent 63dc7da commit 630d5f3

6 files changed

+11
-5
lines changed

src/libsyntax/parse/unescape.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub(crate) enum EscapeError {
1212
LoneSlash,
1313
InvalidEscape,
1414
BareCarriageReturn,
15+
BareCarriageReturnInRawString,
1516
EscapeOnlyChar,
1617

1718
TooShortHexEscape,
@@ -299,7 +300,7 @@ where
299300
chars.next();
300301
Ok('\n')
301302
},
302-
('\r', _) => Err(EscapeError::BareCarriageReturn),
303+
('\r', _) => Err(EscapeError::BareCarriageReturnInRawString),
303304
(c, _) if mode.is_bytes() && !c.is_ascii() =>
304305
Err(EscapeError::NonAsciiCharInByteString),
305306
(c, _) => Ok(c),

src/libsyntax/parse/unescape_error_reporting.rs

+5
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ pub(crate) fn emit_unescape_error(
8080
};
8181
handler.span_err(span, msg);
8282
}
83+
EscapeError::BareCarriageReturnInRawString => {
84+
assert!(mode.in_double_quotes());
85+
let msg = "bare CR not allowed in raw string";
86+
handler.span_err(span, msg);
87+
}
8388
EscapeError::InvalidEscape => {
8489
let (c, span) = last_char();
8590

src/test/ui/parser/lex-bare-cr-string-literal-doc-comment.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn main() {
2121
let _s = "foobar"; //~ ERROR: bare CR not allowed in string
2222

2323
// the following string literal has a bare CR in it
24-
let _s = r"barfoo"; //~ ERROR: bare CR not allowed in string
24+
let _s = r"barfoo"; //~ ERROR: bare CR not allowed in raw string
2525

2626
// the following string literal has a bare CR in it
2727
let _s = "foo\bar"; //~ ERROR: unknown character escape: \r

src/test/ui/parser/lex-bare-cr-string-literal-doc-comment.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ error: bare CR not allowed in string, use \r instead
2828
LL | let _s = "foobar";
2929
| ^
3030

31-
error: bare CR not allowed in string, use \r instead
31+
error: bare CR not allowed in raw string
3232
--> $DIR/lex-bare-cr-string-literal-doc-comment.rs:24:19
3333
|
3434
LL | let _s = r"barfoo";

src/test/ui/parser/raw-byte-string-literals.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ignore-tidy-cr
22
// compile-flags: -Z continue-parse-after-error
33
pub fn main() {
4-
br"a"; //~ ERROR bare CR not allowed in string
4+
br"a"; //~ ERROR bare CR not allowed in raw string
55
br"é"; //~ ERROR raw byte string must be ASCII
66
br##~"a"~##; //~ ERROR only `#` is allowed in raw string delimitation
77
}

src/test/ui/parser/raw-byte-string-literals.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: bare CR not allowed in string, use \r instead
1+
error: bare CR not allowed in raw string
22
--> $DIR/raw-byte-string-literals.rs:4:9
33
|
44
LL | br"a";

0 commit comments

Comments
 (0)