Skip to content

Commit d370493

Browse files
committed
Auto merge of #57251 - petrochenkov:reregr, r=varkor
syntax: Fix regression in diagnostics for patterns in trait method parameters Fixes #55036
2 parents 9653034 + 3df500d commit d370493

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
@@ -1878,7 +1878,8 @@ impl<'a> Parser<'a> {
18781878
let parser_snapshot_before_ty = self.clone();
18791879
self.eat_incorrect_doc_comment("a method argument's type");
18801880
let mut ty = self.parse_ty();
1881-
if ty.is_ok() && self.token == token::Colon {
1881+
if ty.is_ok() && self.token != token::Comma &&
1882+
self.token != token::CloseDelim(token::Paren) {
18821883
// This wasn't actually a type, but a pattern looking like a type,
18831884
// so we are going to rollback and re-parse for recovery.
18841885
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)