Skip to content

Commit 3df500d

Browse files
committed
syntax: Fix regression in diagnostics for patterns in trait method parameters
1 parent cae1647 commit 3df500d

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

src/libsyntax/parse/parser.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1866,7 +1866,8 @@ impl<'a> Parser<'a> {
18661866
let parser_snapshot_before_ty = self.clone();
18671867
self.eat_incorrect_doc_comment("a method argument's type");
18681868
let mut ty = self.parse_ty();
1869-
if ty.is_ok() && self.token == token::Colon {
1869+
if ty.is_ok() && self.token != token::Comma &&
1870+
self.token != token::CloseDelim(token::Paren) {
18701871
// This wasn't actually a type, but a pattern looking like a type,
18711872
// so we are going to rollback and re-parse for recovery.
18721873
ty = self.unexpected();

src/test/ui/E0642.rs

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ trait T {
66

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

9+
fn method(S { .. }: S) {} //~ ERROR patterns aren't allowed in methods without bodies
10+
911
fn f(&ident: &S) {} // ok
1012
fn g(&&ident: &&S) {} // ok
1113
fn h(mut ident: S) {} // ok

src/test/ui/E0642.stderr

+11-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ help: give this argument a name or use an underscore to ignore it
1818
LL | fn bar(_: (i32, i32)) {} //~ ERROR patterns aren't allowed in methods without bodies
1919
| ^
2020

21-
error: aborting due to 2 previous errors
21+
error[E0642]: patterns aren't allowed in methods without bodies
22+
--> $DIR/E0642.rs:9:15
23+
|
24+
LL | fn method(S { .. }: S) {} //~ ERROR patterns aren't allowed in methods without bodies
25+
| ^^^^^^^^
26+
help: give this argument a name or use an underscore to ignore it
27+
|
28+
LL | fn method(_: S) {} //~ ERROR patterns aren't allowed in methods without bodies
29+
| ^
30+
31+
error: aborting due to 3 previous errors
2232

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

0 commit comments

Comments
 (0)