]> git.lizzy.rs Git - rust.git/commitdiff
Don't drop DiagnosticBuilder if parsing fails
authorJonathan Goodman <goodmanjonathan@sbcglobal.net>
Sun, 14 Jul 2019 00:34:06 +0000 (19:34 -0500)
committerJonathan Goodman <goodmanjonathan@sbcglobal.net>
Sun, 14 Jul 2019 00:46:13 +0000 (19:46 -0500)
If the explicitly given type of a `self` parameter fails to parse correctly,
we need to propagate the error rather than dropping it and causing an ICE.

Fixes #62660.

src/libsyntax/parse/parser.rs
src/test/ui/parser/issue-62660.rs [new file with mode: 0644]
src/test/ui/parser/issue-62660.stderr [new file with mode: 0644]

index 83030e89af3105b060f9fc7f29d409cc98138f48..aca63705f3d000370c20f61c79f182fa20756152 100644 (file)
@@ -1498,7 +1498,7 @@ fn parse_arg_general<F>(
         F: Fn(&token::Token) -> bool
     {
         let attrs = self.parse_arg_attributes()?;
-        if let Ok(Some(mut arg)) = self.parse_self_arg() {
+        if let Some(mut arg) = self.parse_self_arg()? {
             arg.attrs = attrs.into();
             return self.recover_bad_self_arg(arg, is_trait_item);
         }
diff --git a/src/test/ui/parser/issue-62660.rs b/src/test/ui/parser/issue-62660.rs
new file mode 100644 (file)
index 0000000..33c8a9f
--- /dev/null
@@ -0,0 +1,11 @@
+// Regression test for issue #62660: if a receiver's type does not
+// successfully parse, emit the correct error instead of ICE-ing the compiler.
+
+struct Foo;
+
+impl Foo {
+    pub fn foo(_: i32, self: Box<Self) {}
+    //~^ ERROR expected one of `!`, `(`, `+`, `,`, `::`, `<`, or `>`, found `)`
+}
+
+fn main() {}
diff --git a/src/test/ui/parser/issue-62660.stderr b/src/test/ui/parser/issue-62660.stderr
new file mode 100644 (file)
index 0000000..3a8f679
--- /dev/null
@@ -0,0 +1,8 @@
+error: expected one of `!`, `(`, `+`, `,`, `::`, `<`, or `>`, found `)`
+  --> $DIR/issue-62660.rs:7:38
+   |
+LL |     pub fn foo(_: i32, self: Box<Self) {}
+   |                                      ^ expected one of 7 possible tokens here
+
+error: aborting due to previous error
+