Auto merge of #53051 - varkor:trait-method-pattern-arguments-error, r=petrochenkov

Emit error for pattern arguments in trait methods

The error and check for this already existed, but the parser didn't try to parse trait method arguments as patterns, so the error was never emitted. This surfaces the error, so we get better errors than simple parse errors.

This improves the error message described in https://github.com/rust-lang/rust/issues/53046.

r? @petrochenkov
This commit is contained in:
bors 2018-08-13 02:28:13 +00:00
commit ab93561b5f
5 changed files with 122 additions and 16 deletions

24
src/test/ui/E0642.rs Normal file
View file

@ -0,0 +1,24 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#[derive(Clone, Copy)]
struct S;
trait T {
fn foo((x, y): (i32, i32)); //~ ERROR patterns aren't allowed in methods without bodies
fn bar((x, y): (i32, i32)) {} //~ 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
}
fn main() {}

23
src/test/ui/E0642.stderr Normal file
View file

@ -0,0 +1,23 @@
error[E0642]: patterns aren't allowed in methods without bodies
--> $DIR/E0642.rs:15:12
|
LL | fn foo((x, y): (i32, i32)); //~ ERROR patterns aren't allowed in methods without bodies
| ^^^^^^
help: give this argument a name or use an underscore to ignore it
|
LL | fn foo(_: (i32, i32)); //~ ERROR patterns aren't allowed in methods without bodies
| ^
error[E0642]: patterns aren't allowed in methods without bodies
--> $DIR/E0642.rs:17:12
|
LL | fn bar((x, y): (i32, i32)) {} //~ ERROR patterns aren't allowed in methods without bodies
| ^^^^^^
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
For more information about this error, try `rustc --explain E0642`.