-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Allow destructuring parameters in trait function declarations #53046
Comments
I think this is a consequence of trait method declarations not requiring argument names. Patterns as arguments are only accepted if names are required. I imagine there's some parsing issue here. Perhaps something like: trait Trait {
fn foo(&Bar); // is `&Bar` a pattern or type here?
} However, in the presence of Edit: see rust-lang/rfcs#1351 (comment) and #41686. |
Interestingly, there's a better error message for this, E0642:
However, it's unlisted on the Error Index and isn't emitted because the parser fails before that point. Edit: Looks like it wasn't being type-checked properly before it was forbidden. |
…ts-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 rust-lang#53046.
…=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
Triage: there is a very small change now:
(now says function because it's not a method) |
The current syntax rules do not allow for trait functions to destructure parameters:
Playground
Compiling the above outputs this:
The destructuring of trait function parameters should be allowed for consistency and readability.
The text was updated successfully, but these errors were encountered: