Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a parser ICE on invalid fn body #87646

Merged
merged 1 commit into from
Aug 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1715,13 +1715,11 @@ impl<'a> Parser<'a> {
// the AST for typechecking.
err.span_label(ident.span, "while parsing this `fn`");
err.emit();
(Vec::new(), None)
} else {
return Err(err);
}
} else {
unreachable!()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add a delay_span_bug to protect against this ever passing compilation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unreachable!() is equivalent to bug!(), isn't it? (Unless that's only the case for debug builds.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

esteban and I had a short chat. This is ok, even if not idea. There should be an issue mentioning the wrong first error suggestion (as seen in the newly added test) and that we should find a way to avoid that message and just show the second one.

r=me with that issue opened.

}
(Vec::new(), None)
};
attrs.extend(inner_attrs);
Ok(body)
Expand Down
9 changes: 9 additions & 0 deletions src/test/ui/parser/issue-87635.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
struct Foo {}

impl Foo {
pub fn bar()
//~^ ERROR: expected `;`, found `}`
//~| ERROR: associated function in `impl` without body
}

fn main() {}
19 changes: 19 additions & 0 deletions src/test/ui/parser/issue-87635.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error: expected `;`, found `}`
--> $DIR/issue-87635.rs:4:17
|
LL | pub fn bar()
| ^ help: add `;` here
...
LL | }
| - unexpected token

error: associated function in `impl` without body
--> $DIR/issue-87635.rs:4:5
|
LL | pub fn bar()
| ^^^^^^^^^^^-
| |
| help: provide a definition for the function: `{ <body> }`

error: aborting due to 2 previous errors