Skip to content

syntax: Fix regression in diagnostics for patterns in trait method parameters #57251

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

Merged
merged 1 commit into from
Jan 2, 2019
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
3 changes: 2 additions & 1 deletion src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1866,7 +1866,8 @@ impl<'a> Parser<'a> {
let parser_snapshot_before_ty = self.clone();
self.eat_incorrect_doc_comment("a method argument's type");
let mut ty = self.parse_ty();
if ty.is_ok() && self.token == token::Colon {
if ty.is_ok() && self.token != token::Comma &&
self.token != token::CloseDelim(token::Paren) {
// This wasn't actually a type, but a pattern looking like a type,
// so we are going to rollback and re-parse for recovery.
ty = self.unexpected();
Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/E0642.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ trait T {

fn bar((x, y): (i32, i32)) {} //~ ERROR patterns aren't allowed in methods without bodies

fn method(S { .. }: S) {} //~ ERROR patterns aren't allowed in methods without bodies

fn f(&ident: &S) {} // ok
fn g(&&ident: &&S) {} // ok
fn h(mut ident: S) {} // ok
Expand Down
12 changes: 11 additions & 1 deletion src/test/ui/E0642.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ help: give this argument a name or use an underscore to ignore it
LL | fn bar(_: (i32, i32)) {} //~ ERROR patterns aren't allowed in methods without bodies
| ^

error: aborting due to 2 previous errors
error[E0642]: patterns aren't allowed in methods without bodies
--> $DIR/E0642.rs:9:15
|
LL | fn method(S { .. }: S) {} //~ ERROR patterns aren't allowed in methods without bodies
| ^^^^^^^^
help: give this argument a name or use an underscore to ignore it
|
LL | fn method(_: S) {} //~ ERROR patterns aren't allowed in methods without bodies
| ^

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0642`.