-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 #53046. r? @petrochenkov
- Loading branch information
Showing
5 changed files
with
122 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |