about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2019-03-01 16:28:04 -0800
committerEsteban Küber <esteban@kuber.com.ar>2019-03-06 18:45:59 -0800
commit2ec7d0b2281e57a456d6122dadd5646804a9d36e (patch)
tree2e47895a2478a88036d8366525a5466bc1ad09e2
parentf22dca0a1bef4141e75326caacc3cd59f3d5be8e (diff)
downloadrust-2ec7d0b2281e57a456d6122dadd5646804a9d36e.tar.gz
rust-2ec7d0b2281e57a456d6122dadd5646804a9d36e.zip
Do not panic on missing close paren
Fix #58856.
-rw-r--r--src/libsyntax/parse/parser.rs4
-rw-r--r--src/test/ui/issues/issue-58856-1.rs9
-rw-r--r--src/test/ui/issues/issue-58856-1.stderr30
-rw-r--r--src/test/ui/issues/issue-58856-2.rs13
-rw-r--r--src/test/ui/issues/issue-58856-2.stderr55
5 files changed, 110 insertions, 1 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index fd5038a8614..dd4c2393fa5 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -6332,8 +6332,10 @@ impl<'a> Parser<'a> {
                     &token::CloseDelim(token::Paren), sep, parse_arg_fn)?;
                 fn_inputs.append(&mut input);
                 (fn_inputs, recovered)
+            } else if let Err(err) = self.expect_one_of(&[], &[]) {
+                return Err(err);
             } else {
-                return self.unexpected();
+                (vec![self_arg], true)
             }
         } else {
             self.parse_seq_to_before_end(&token::CloseDelim(token::Paren), sep, parse_arg_fn)?
diff --git a/src/test/ui/issues/issue-58856-1.rs b/src/test/ui/issues/issue-58856-1.rs
new file mode 100644
index 00000000000..9311bb0802f
--- /dev/null
+++ b/src/test/ui/issues/issue-58856-1.rs
@@ -0,0 +1,9 @@
+impl A {
+//~^ ERROR cannot find type `A` in this scope
+    fn b(self>
+    //~^ ERROR expected one of `)`, `,`, or `:`, found `>`
+    //~| ERROR expected one of `->`, `where`, or `{`, found `>`
+    //~| ERROR expected one of `->`, `async`, `const`, `crate`, `default`, `existential`,
+}
+
+fn main() {}
diff --git a/src/test/ui/issues/issue-58856-1.stderr b/src/test/ui/issues/issue-58856-1.stderr
new file mode 100644
index 00000000000..3cbfd375e78
--- /dev/null
+++ b/src/test/ui/issues/issue-58856-1.stderr
@@ -0,0 +1,30 @@
+error: expected one of `)`, `,`, or `:`, found `>`
+  --> $DIR/issue-58856-1.rs:3:14
+   |
+LL |     fn b(self>
+   |         -    ^
+   |         |    |
+   |         |    help: `)` may belong here
+   |         unclosed delimiter
+
+error: expected one of `->`, `where`, or `{`, found `>`
+  --> $DIR/issue-58856-1.rs:3:14
+   |
+LL |     fn b(self>
+   |              ^ expected one of `->`, `where`, or `{` here
+
+error: expected one of `->`, `async`, `const`, `crate`, `default`, `existential`, `extern`, `fn`, `pub`, `type`, `unsafe`, `where`, or `}`, found `>`
+  --> $DIR/issue-58856-1.rs:3:14
+   |
+LL |     fn b(self>
+   |              ^ expected one of 13 possible tokens here
+
+error[E0412]: cannot find type `A` in this scope
+  --> $DIR/issue-58856-1.rs:1:6
+   |
+LL | impl A {
+   |      ^ not found in this scope
+
+error: aborting due to 4 previous errors
+
+For more information about this error, try `rustc --explain E0412`.
diff --git a/src/test/ui/issues/issue-58856-2.rs b/src/test/ui/issues/issue-58856-2.rs
new file mode 100644
index 00000000000..4c764761e8e
--- /dev/null
+++ b/src/test/ui/issues/issue-58856-2.rs
@@ -0,0 +1,13 @@
+trait Howness {}
+impl Howness for () {
+    fn how_are_you(&self -> Empty {
+    //~^ ERROR expected one of `)` or `,`, found `->`
+    //~| ERROR method `how_are_you` is not a member of trait `Howness`
+    //~| ERROR cannot find type `Empty` in this scope
+        Empty
+        //~^ ERROR cannot find value `Empty` in this scope
+    }
+}
+//~^ ERROR expected one of `async`, `const`, `crate`, `default`, `existential`, `extern`, `fn`,
+
+fn main() {}
diff --git a/src/test/ui/issues/issue-58856-2.stderr b/src/test/ui/issues/issue-58856-2.stderr
new file mode 100644
index 00000000000..30027278e23
--- /dev/null
+++ b/src/test/ui/issues/issue-58856-2.stderr
@@ -0,0 +1,55 @@
+error: expected one of `)` or `,`, found `->`
+  --> $DIR/issue-58856-2.rs:3:26
+   |
+LL |     fn how_are_you(&self -> Empty {
+   |                   -     -^^
+   |                   |     |
+   |                   |     help: `)` may belong here
+   |                   unclosed delimiter
+
+error: expected one of `async`, `const`, `crate`, `default`, `existential`, `extern`, `fn`, `pub`, `type`, `unsafe`, or `}`, found `)`
+  --> $DIR/issue-58856-2.rs:10:1
+   |
+LL |     }
+   |      - expected one of 11 possible tokens here
+LL | }
+   | ^ unexpected token
+
+error[E0407]: method `how_are_you` is not a member of trait `Howness`
+  --> $DIR/issue-58856-2.rs:3:5
+   |
+LL | /     fn how_are_you(&self -> Empty {
+LL | |     //~^ ERROR expected one of `)` or `,`, found `->`
+LL | |     //~| ERROR method `how_are_you` is not a member of trait `Howness`
+LL | |     //~| ERROR cannot find type `Empty` in this scope
+LL | |         Empty
+LL | |         //~^ ERROR cannot find value `Empty` in this scope
+LL | |     }
+   | |_____^ not a member of trait `Howness`
+
+error[E0412]: cannot find type `Empty` in this scope
+  --> $DIR/issue-58856-2.rs:3:29
+   |
+LL |     fn how_are_you(&self -> Empty {
+   |                             ^^^^^ not found in this scope
+help: possible candidates are found in other modules, you can import them into scope
+   |
+LL | use std::io::Empty;
+   |
+LL | use std::iter::Empty;
+   |
+
+error[E0425]: cannot find value `Empty` in this scope
+  --> $DIR/issue-58856-2.rs:7:9
+   |
+LL |         Empty
+   |         ^^^^^ not found in this scope
+help: possible candidate is found in another module, you can import it into scope
+   |
+LL | use std::sync::mpsc::TryRecvError::Empty;
+   |
+
+error: aborting due to 5 previous errors
+
+Some errors occurred: E0407, E0412, E0425.
+For more information about an error, try `rustc --explain E0407`.