Skip to content

Commit

Permalink
Don't suggest using \r in raw strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Xanewok committed Jun 10, 2019
1 parent 63dc7da commit 630d5f3
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/libsyntax/parse/unescape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub(crate) enum EscapeError {
LoneSlash,
InvalidEscape,
BareCarriageReturn,
BareCarriageReturnInRawString,
EscapeOnlyChar,

TooShortHexEscape,
Expand Down Expand Up @@ -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),
Expand Down
5 changes: 5 additions & 0 deletions src/libsyntax/parse/unescape_error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn main() {
let _s = "foobar"; //~ ERROR: bare CR not allowed in string

// the following string literal has a bare CR in it
let _s = r"barfoo"; //~ ERROR: bare CR not allowed in string
let _s = r"barfoo"; //~ 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ error: bare CR not allowed in string, use \r instead
LL | let _s = "foobar";
| ^

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"barfoo";
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/parser/raw-byte-string-literals.rs
Original file line number Diff line number Diff line change
@@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/parser/raw-byte-string-literals.stderr
Original file line number Diff line number Diff line change
@@ -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";
Expand Down

0 comments on commit 630d5f3

Please sign in to comment.