summary refs log tree commit diff
path: root/src/test/ui/parser
diff options
context:
space:
mode:
authorDylan DPC <dylan.dpc@gmail.com>2020-10-28 01:21:24 +0100
committerGitHub <noreply@github.com>2020-10-28 01:21:24 +0100
commit892ebe9afe9d299a5ff22b9dec1a84a653b85f78 (patch)
tree9e0ee9377cbb36f710bfceb062aa74cf39249ab4 /src/test/ui/parser
parent1a64e570c6d3bf19a387f96bcb0bd09e51caee22 (diff)
parentff61949860813247b26d96eb374b41b46becba81 (diff)
downloadrust-892ebe9afe9d299a5ff22b9dec1a84a653b85f78.tar.gz
rust-892ebe9afe9d299a5ff22b9dec1a84a653b85f78.zip
Rollup merge of #78379 - estebank:fn-signature-parse, r=varkor
Tweak invalid `fn` header and body parsing

* Rely on regular "expected"/"found" parser error for `fn`, fix #77115
* Recover empty `fn` bodies when encountering `}`
* Recover trailing `>` in return types
* Recover from non-type in array type `[<BAD TOKEN>; LEN]`
Diffstat (limited to 'src/test/ui/parser')
-rw-r--r--src/test/ui/parser/fn-colon-return-type.rs5
-rw-r--r--src/test/ui/parser/fn-colon-return-type.stderr8
-rw-r--r--src/test/ui/parser/issue-24780.rs7
-rw-r--r--src/test/ui/parser/issue-24780.stderr4
-rw-r--r--src/test/ui/parser/issue-6610.rs2
-rw-r--r--src/test/ui/parser/issue-6610.stderr10
-rw-r--r--src/test/ui/parser/missing_right_paren.stderr4
-rw-r--r--src/test/ui/parser/not-a-pred.rs3
-rw-r--r--src/test/ui/parser/not-a-pred.stderr6
9 files changed, 30 insertions, 19 deletions
diff --git a/src/test/ui/parser/fn-colon-return-type.rs b/src/test/ui/parser/fn-colon-return-type.rs
new file mode 100644
index 00000000000..c791fb3ae67
--- /dev/null
+++ b/src/test/ui/parser/fn-colon-return-type.rs
@@ -0,0 +1,5 @@
+fn foo(x: i32): i32 { //~ ERROR expected one of `->`, `;`, `where`, or `{`, found `:`
+    x
+}
+
+fn main() {}
diff --git a/src/test/ui/parser/fn-colon-return-type.stderr b/src/test/ui/parser/fn-colon-return-type.stderr
new file mode 100644
index 00000000000..92df9bc60bd
--- /dev/null
+++ b/src/test/ui/parser/fn-colon-return-type.stderr
@@ -0,0 +1,8 @@
+error: expected one of `->`, `;`, `where`, or `{`, found `:`
+  --> $DIR/fn-colon-return-type.rs:1:15
+   |
+LL | fn foo(x: i32): i32 {
+   |               ^ expected one of `->`, `;`, `where`, or `{`
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/parser/issue-24780.rs b/src/test/ui/parser/issue-24780.rs
index 8b46aa2bf22..20665b549d2 100644
--- a/src/test/ui/parser/issue-24780.rs
+++ b/src/test/ui/parser/issue-24780.rs
@@ -1,8 +1,9 @@
 // Verify that '>' is not both expected and found at the same time, as it used
 // to happen in #24780. For example, following should be an error:
-// expected one of ..., `>`, ... found `>`
+// expected one of ..., `>`, ... found `>`. No longer exactly this, but keeping for posterity.
 
-fn foo() -> Vec<usize>> {
-    //~^ ERROR expected `;` or `{`, found `>`
+fn foo() -> Vec<usize>> { //~ ERROR unmatched angle bracket
     Vec::new()
 }
+
+fn main() {}
diff --git a/src/test/ui/parser/issue-24780.stderr b/src/test/ui/parser/issue-24780.stderr
index d65a5f44873..d12b13d35f8 100644
--- a/src/test/ui/parser/issue-24780.stderr
+++ b/src/test/ui/parser/issue-24780.stderr
@@ -1,8 +1,8 @@
-error: expected `;` or `{`, found `>`
+error: unmatched angle bracket
   --> $DIR/issue-24780.rs:5:23
    |
 LL | fn foo() -> Vec<usize>> {
-   |                       ^ expected `;` or `{`
+   |                       ^^ help: remove extra angle bracket
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/parser/issue-6610.rs b/src/test/ui/parser/issue-6610.rs
index 2dfa08fe82d..9ed5a61220b 100644
--- a/src/test/ui/parser/issue-6610.rs
+++ b/src/test/ui/parser/issue-6610.rs
@@ -1,3 +1,3 @@
-trait Foo { fn a() } //~ ERROR expected `;` or `{`, found `}`
+trait Foo { fn a() } //~ ERROR expected one of `->`, `;`, `where`, or `{`, found `}`
 
 fn main() {}
diff --git a/src/test/ui/parser/issue-6610.stderr b/src/test/ui/parser/issue-6610.stderr
index a9804208946..4a3bc752553 100644
--- a/src/test/ui/parser/issue-6610.stderr
+++ b/src/test/ui/parser/issue-6610.stderr
@@ -1,12 +1,10 @@
-error: expected `;` or `{`, found `}`
+error: expected one of `->`, `;`, `where`, or `{`, found `}`
   --> $DIR/issue-6610.rs:1:20
    |
 LL | trait Foo { fn a() }
-   |           -        ^
-   |           |        |
-   |           |        expected `;` or `{`
-   |           |        the item list ends here
-   |           while parsing this item list starting here
+   |                -   ^ expected one of `->`, `;`, `where`, or `{`
+   |                |
+   |                while parsing this `fn`
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/parser/missing_right_paren.stderr b/src/test/ui/parser/missing_right_paren.stderr
index c1ceb81a07c..22e1c2f97e7 100644
--- a/src/test/ui/parser/missing_right_paren.stderr
+++ b/src/test/ui/parser/missing_right_paren.stderr
@@ -22,11 +22,11 @@ error: expected one of `:` or `|`, found `)`
 LL | fn main((ؼ
    |           ^ expected one of `:` or `|`
 
-error: expected `;` or `{`, found `<eof>`
+error: expected one of `->`, `;`, `where`, or `{`, found `<eof>`
   --> $DIR/missing_right_paren.rs:3:11
    |
 LL | fn main((ؼ
-   |           ^ expected `;` or `{`
+   |           ^ expected one of `->`, `;`, `where`, or `{`
 
 error: aborting due to 4 previous errors
 
diff --git a/src/test/ui/parser/not-a-pred.rs b/src/test/ui/parser/not-a-pred.rs
index e6a02d5fc56..1b3d9bf66bb 100644
--- a/src/test/ui/parser/not-a-pred.rs
+++ b/src/test/ui/parser/not-a-pred.rs
@@ -1,6 +1,5 @@
-// error-pattern: lt
-
 fn f(a: isize, b: isize) : lt(a, b) { }
+//~^ ERROR expected one of `->`, `;`, `where`, or `{`, found `:`
 
 fn lt(a: isize, b: isize) { }
 
diff --git a/src/test/ui/parser/not-a-pred.stderr b/src/test/ui/parser/not-a-pred.stderr
index dce54655fa0..ec413c5594c 100644
--- a/src/test/ui/parser/not-a-pred.stderr
+++ b/src/test/ui/parser/not-a-pred.stderr
@@ -1,8 +1,8 @@
-error: expected `;` or `{`, found `:`
-  --> $DIR/not-a-pred.rs:3:26
+error: expected one of `->`, `;`, `where`, or `{`, found `:`
+  --> $DIR/not-a-pred.rs:1:26
    |
 LL | fn f(a: isize, b: isize) : lt(a, b) { }
-   |                          ^ expected `;` or `{`
+   |                          ^ expected one of `->`, `;`, `where`, or `{`
 
 error: aborting due to previous error