diff options
author | bors <bors@rust-lang.org> | 2019-01-02 09:24:10 +0000 |
---|---|---|
committer | bors <bors@rust-lang.org> | 2019-01-02 09:24:10 +0000 |
commit | d3704932bd3bf72fefe62fe4c4a1a0d9b37cec6b (patch) | |
tree | ef3d5ca62781a7f778d7fb97755bcd7c0e6a1897 | |
parent | 96530344ef951c79e07cad69cf65eddb876b0e2d (diff) | |
parent | 3df500db29b6f50c5c74e7735a9e007ae90206d7 (diff) | |
download | rust-d3704932bd3bf72fefe62fe4c4a1a0d9b37cec6b.tar.gz |
Auto merge of #57251 - petrochenkov:reregr, r=varkor
syntax: Fix regression in diagnostics for patterns in trait method parameters
Fixes https://github.com/rust-lang/rust/issues/55036
-rw-r--r-- | src/libsyntax/parse/parser.rs | 3 | ||||
-rw-r--r-- | src/test/ui/E0642.rs | 2 | ||||
-rw-r--r-- | src/test/ui/E0642.stderr | 12 |
3 files changed, 15 insertions, 2 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 7c471fdebb3..1e4a26b3537 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1878,7 +1878,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(); diff --git a/src/test/ui/E0642.rs b/src/test/ui/E0642.rs index 8b74e5abe19..cfbd362c1da 100644 --- a/src/test/ui/E0642.rs +++ b/src/test/ui/E0642.rs @@ -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 diff --git a/src/test/ui/E0642.stderr b/src/test/ui/E0642.stderr index c3a230d5acf..4c82a6cbd21 100644 --- a/src/test/ui/E0642.stderr +++ b/src/test/ui/E0642.stderr @@ -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`. |