Skip to content

Commit 7111328

Browse files
Don't drop DiagnosticBuilder if parsing fails
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 rust-lang#62660.
1 parent 69656fa commit 7111328

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

src/libsyntax/parse/parser.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1498,7 +1498,7 @@ impl<'a> Parser<'a> {
14981498
F: Fn(&token::Token) -> bool
14991499
{
15001500
let attrs = self.parse_arg_attributes()?;
1501-
if let Ok(Some(mut arg)) = self.parse_self_arg() {
1501+
if let Some(mut arg) = self.parse_self_arg()? {
15021502
arg.attrs = attrs.into();
15031503
return self.recover_bad_self_arg(arg, is_trait_item);
15041504
}

src/test/ui/parser/issue-62660.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Regression test for issue #62660: if a receiver's type does not
2+
// successfully parse, emit the correct error instead of ICE-ing the compiler.
3+
4+
struct Foo;
5+
6+
impl Foo {
7+
pub fn foo(_: i32, self: Box<Self) {}
8+
//~^ ERROR expected one of `!`, `(`, `+`, `,`, `::`, `<`, or `>`, found `)`
9+
}
10+
11+
fn main() {}

src/test/ui/parser/issue-62660.stderr

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: expected one of `!`, `(`, `+`, `,`, `::`, `<`, or `>`, found `)`
2+
--> $DIR/issue-62660.rs:7:38
3+
|
4+
LL | pub fn foo(_: i32, self: Box<Self) {}
5+
| ^ expected one of 7 possible tokens here
6+
7+
error: aborting due to previous error
8+

0 commit comments

Comments
 (0)