about summary refs log tree commit diff
diff options
context:
space:
mode:
authorIgor Matuszewski <Xanewok@gmail.com>2019-06-10 17:32:15 +0200
committerIgor Matuszewski <Xanewok@gmail.com>2019-06-10 17:32:15 +0200
commit630d5f355fc85fc2c3bab28a278c517d945d328d (patch)
tree0a03551c5117f67c34eabd1023d875c468ab067e
parent63dc7da703759dd53536dd18a42ff65f39a2f9b4 (diff)
downloadrust-630d5f355fc85fc2c3bab28a278c517d945d328d.tar.gz
rust-630d5f355fc85fc2c3bab28a278c517d945d328d.zip
Don't suggest using \r in raw strings
-rw-r--r--src/libsyntax/parse/unescape.rs3
-rw-r--r--src/libsyntax/parse/unescape_error_reporting.rs5
-rw-r--r--src/test/ui/parser/lex-bare-cr-string-literal-doc-comment.rs2
-rw-r--r--src/test/ui/parser/lex-bare-cr-string-literal-doc-comment.stderr2
-rw-r--r--src/test/ui/parser/raw-byte-string-literals.rs2
-rw-r--r--src/test/ui/parser/raw-byte-string-literals.stderr2
6 files changed, 11 insertions, 5 deletions
diff --git a/src/libsyntax/parse/unescape.rs b/src/libsyntax/parse/unescape.rs
index e816aa0271c..22cce67b5ee 100644
--- a/src/libsyntax/parse/unescape.rs
+++ b/src/libsyntax/parse/unescape.rs
@@ -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),
diff --git a/src/libsyntax/parse/unescape_error_reporting.rs b/src/libsyntax/parse/unescape_error_reporting.rs
index 8f152974a6d..71b41161ad8 100644
--- a/src/libsyntax/parse/unescape_error_reporting.rs
+++ b/src/libsyntax/parse/unescape_error_reporting.rs
@@ -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();
 
diff --git a/src/test/ui/parser/lex-bare-cr-string-literal-doc-comment.rs b/src/test/ui/parser/lex-bare-cr-string-literal-doc-comment.rs
index ed5df42f9dd..b588b007ae9 100644
--- a/src/test/ui/parser/lex-bare-cr-string-literal-doc-comment.rs
+++ b/src/test/ui/parser/lex-bare-cr-string-literal-doc-comment.rs
@@ -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
diff --git a/src/test/ui/parser/lex-bare-cr-string-literal-doc-comment.stderr b/src/test/ui/parser/lex-bare-cr-string-literal-doc-comment.stderr
index 153237a7f71..b0fe4b6acd4 100644
--- a/src/test/ui/parser/lex-bare-cr-string-literal-doc-comment.stderr
+++ b/src/test/ui/parser/lex-bare-cr-string-literal-doc-comment.stderr
@@ -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";
diff --git a/src/test/ui/parser/raw-byte-string-literals.rs b/src/test/ui/parser/raw-byte-string-literals.rs
index 87ecfb5c544..534afabdf77 100644
--- a/src/test/ui/parser/raw-byte-string-literals.rs
+++ b/src/test/ui/parser/raw-byte-string-literals.rs
@@ -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
 }
diff --git a/src/test/ui/parser/raw-byte-string-literals.stderr b/src/test/ui/parser/raw-byte-string-literals.stderr
index 03fe79722b8..4880d1fdbe8 100644
--- a/src/test/ui/parser/raw-byte-string-literals.stderr
+++ b/src/test/ui/parser/raw-byte-string-literals.stderr
@@ -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
";