Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slice patterns cannot be used in trait methods #50571

Closed
cake4289 opened this issue May 9, 2018 · 3 comments · Fixed by #64928
Closed

Slice patterns cannot be used in trait methods #50571

cake4289 opened this issue May 9, 2018 · 3 comments · Fixed by #64928
Labels
A-parser Area: The parsing of Rust source code to an AST C-enhancement Category: An issue proposing an enhancement or a PR with one. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@cake4289
Copy link

cake4289 commented May 9, 2018

The following code works on beta:

fn foo([a, b]: [i32; 2]) {}

But when used in a trait like so:

trait Foo {
    fn foo([a, b]: [i32; 2]) {}
}

rustc reports the following error:

error: expected one of `!`, `(`, `+`, `::`, `;`, `<`, or `]`, found `,`
 --> src/main.rs:2:14
  |
2 |     fn foo([a, b]: [i32; 2]) {}
  |              ^ expected one of 7 possible tokens here

error: aborting due to previous error
@cake4289
Copy link
Author

cake4289 commented May 9, 2018

Possibly related to rustc expecting possibly a type in this scenario? As you can declare trait methods with no parameter name

@petrochenkov
Copy link
Contributor

@cake4289

Possibly related to rustc expecting possibly a type in this scenario?

Exactly.
When #41686 becomes an error, we'll be able to accept arbitrary patterns in parameters of trait methods, but for now only very limited subset is allowed.

@estebank estebank added the A-parser Area: The parsing of Rust source code to an AST label May 9, 2018
@XAMPPRocky XAMPPRocky added C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 2, 2018
@varkor varkor added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. labels Sep 28, 2019
@varkor
Copy link
Member

varkor commented Sep 28, 2019

The example in the issue now compiles. If we don't have existing tests for this, we ought to add one.

JohnTitor added a commit to JohnTitor/rust that referenced this issue Sep 30, 2019
Centril added a commit to Centril/rust that referenced this issue Oct 1, 2019
@bors bors closed this as completed in dc1c1fe Oct 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parser Area: The parsing of Rust source code to an AST C-enhancement Category: An issue proposing an enhancement or a PR with one. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants