about summary refs log tree commit diff
path: root/src/test/ui/parser
diff options
context:
space:
mode:
authorRussell Cohen <russell.r.cohen@gmail.com>2020-03-28 01:46:20 -0400
committerRussell Cohen <russell.r.cohen@gmail.com>2020-03-29 00:43:43 -0400
commit629e97a5a02edb3d8dc63c5157962c093217d441 (patch)
treeec748780e2098a0581b06d0501bc297447ca59ba /src/test/ui/parser
parent840a5769b0879f39e21d973a60ac0b0db172f050 (diff)
downloadrust-629e97a5a02edb3d8dc63c5157962c093217d441.tar.gz
rust-629e97a5a02edb3d8dc63c5157962c093217d441.zip
Improve error messages for raw strings (#60762)
This diff improves error messages around raw strings in a few ways:
- Catch extra trailing `#` in the parser. This can't be handled in the lexer because we could be in a macro that actually expects another # (see test)
- Refactor & unify error handling in the lexer between ByteStrings and RawByteStrings
- Detect potentially intended terminators (longest sequence of "#*" is suggested)
Diffstat (limited to 'src/test/ui/parser')
-rw-r--r--src/test/ui/parser/raw/raw-byte-string-eof.stderr4
-rw-r--r--src/test/ui/parser/raw/raw-str-in-macro-call.rs14
-rw-r--r--src/test/ui/parser/raw/raw-str-unbalanced.rs2
-rw-r--r--src/test/ui/parser/raw/raw-str-unbalanced.stderr6
-rw-r--r--src/test/ui/parser/raw/raw_string.stderr4
5 files changed, 25 insertions, 5 deletions
diff --git a/src/test/ui/parser/raw/raw-byte-string-eof.stderr b/src/test/ui/parser/raw/raw-byte-string-eof.stderr
index d5f22e2a1a8..81344841c27 100644
--- a/src/test/ui/parser/raw/raw-byte-string-eof.stderr
+++ b/src/test/ui/parser/raw/raw-byte-string-eof.stderr
@@ -2,7 +2,9 @@ error[E0748]: unterminated raw string
   --> $DIR/raw-byte-string-eof.rs:2:5
    |
 LL |     br##"a"#;
-   |     ^ unterminated raw string
+   |     ^      - help: you might have intended to terminate the string here: `##`
+   |     |
+   |     unterminated raw string
    |
    = note: this raw string should be terminated with `"##`
 
diff --git a/src/test/ui/parser/raw/raw-str-in-macro-call.rs b/src/test/ui/parser/raw/raw-str-in-macro-call.rs
new file mode 100644
index 00000000000..462c2279f5c
--- /dev/null
+++ b/src/test/ui/parser/raw/raw-str-in-macro-call.rs
@@ -0,0 +1,14 @@
+// check-pass
+
+macro_rules! m1 {
+    ($tt:tt #) => ()
+}
+
+macro_rules! m2 {
+    ($tt:tt) => ()
+}
+
+fn main() {
+    m1!(r#"abc"##);
+    m2!(r#"abc"#);
+}
diff --git a/src/test/ui/parser/raw/raw-str-unbalanced.rs b/src/test/ui/parser/raw/raw-str-unbalanced.rs
index 5a1d1be11b6..35f118f5ce6 100644
--- a/src/test/ui/parser/raw/raw-str-unbalanced.rs
+++ b/src/test/ui/parser/raw/raw-str-unbalanced.rs
@@ -1,4 +1,4 @@
 static s: &'static str =
     r#"
-      "## //~ ERROR expected one of `.`, `;`, `?`, or an operator, found `#`
+      "## //~ too many `#` when terminating raw string
 ;
diff --git a/src/test/ui/parser/raw/raw-str-unbalanced.stderr b/src/test/ui/parser/raw/raw-str-unbalanced.stderr
index ddb75722bef..891f1d6337c 100644
--- a/src/test/ui/parser/raw/raw-str-unbalanced.stderr
+++ b/src/test/ui/parser/raw/raw-str-unbalanced.stderr
@@ -1,8 +1,10 @@
-error: expected one of `.`, `;`, `?`, or an operator, found `#`
+error: too many `#` when terminating raw string
   --> $DIR/raw-str-unbalanced.rs:3:9
    |
 LL |       "##
-   |         ^ expected one of `.`, `;`, `?`, or an operator
+   |         ^ help: Remove the extra `#`
+   |
+   = note: The raw string started with 1 `#`s
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/parser/raw/raw_string.stderr b/src/test/ui/parser/raw/raw_string.stderr
index 0f1d7e4651d..e91a16bedc4 100644
--- a/src/test/ui/parser/raw/raw_string.stderr
+++ b/src/test/ui/parser/raw/raw_string.stderr
@@ -2,7 +2,9 @@ error[E0748]: unterminated raw string
   --> $DIR/raw_string.rs:2:13
    |
 LL |     let x = r##"lol"#;
-   |             ^ unterminated raw string
+   |             ^       - help: you might have intended to terminate the string here: `##`
+   |             |
+   |             unterminated raw string
    |
    = note: this raw string should be terminated with `"##`