about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorDylan DPC <dylan.dpc@gmail.com>2021-02-09 02:40:01 +0100
committerGitHub <noreply@github.com>2021-02-09 02:40:01 +0100
commit9ab05b4fe38e8aef69c981de0b9fb09d621cb96e (patch)
tree11cfb5d513cfa08a6beb74d4cb2e0f92c46ad8f7 /src
parenta63085dc5e718ad75a4571e9522d8a62a7c18ef1 (diff)
parent6eb1bd4c3e3ad9a28d0a3b0f1579a4769d9a88d2 (diff)
Rollup merge of #81876 - osa1:issue81806, r=matthewjasper
parser: Fix panic in 'const impl' recovery

The panic happens when in recovery parsing a full `impl`
(`parse_item_impl`) fails and we drop the `DiagnosticBuilder` for the
recovery suggestion and return the `parse_item_impl` error.

We now raise the original error "expected identifier found `impl`" when
parsing the `impl` fails.

Note that the regression test is slightly simplified version of the
original repro in #81806, to make the error output smaller and more
resilient to unrelated changes in parser error messages.

Fixes #81806
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/parser/issue-81806.rs5
-rw-r--r--src/test/ui/parser/issue-81806.stderr17
2 files changed, 22 insertions, 0 deletions
diff --git a/src/test/ui/parser/issue-81806.rs b/src/test/ui/parser/issue-81806.rs
new file mode 100644
index 00000000000..ca86788dff7
--- /dev/null
+++ b/src/test/ui/parser/issue-81806.rs
@@ -0,0 +1,5 @@
+trait T { const
+impl //~ ERROR: expected identifier, found keyword `impl`
+}
+
+fn main() {}
diff --git a/src/test/ui/parser/issue-81806.stderr b/src/test/ui/parser/issue-81806.stderr
new file mode 100644
index 00000000000..b8ada11d922
--- /dev/null
+++ b/src/test/ui/parser/issue-81806.stderr
@@ -0,0 +1,17 @@
+error: expected identifier, found keyword `impl`
+  --> $DIR/issue-81806.rs:2:1
+   |
+LL | trait T { const
+   |         - while parsing this item list starting here
+LL | impl
+   | ^^^^ expected identifier, found keyword
+LL | }
+   | - the item list ends here
+   |
+help: you can escape reserved keywords to use them as identifiers
+   |
+LL | r#impl
+   | ^^^^^^
+
+error: aborting due to previous error
+