Skip to content

Patterns make parsing of optional parameter names kinda wonky #14445

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

Closed
ben0x539 opened this issue May 26, 2014 · 1 comment
Closed

Patterns make parsing of optional parameter names kinda wonky #14445

ben0x539 opened this issue May 26, 2014 · 1 comment

Comments

@ben0x539
Copy link
Contributor

I'd expect these method declarations to work:

struct Welp<T>(pub T);

trait Bleh {
    fn foo(Welp(i): Welp<int>) {}
    //         ^ expected `` but found `(`
    fn bar(&&&x: &&&int) {}
    //           ^~ expected `,` but found `&&`
    fn baz((): ()) {}
    //       ^ expected `,` but found `:`
}

The manual says "As with let bindings, function arguments are irrefutable patterns, so any pattern that is valid in a let binding is also valid as an argument." Yet these aren't, and it seems like it would require a ton of lookahead given that newtype struct constructors can be named with arbitrarily long paths and you can have lots of &s prefixed, or deeply nested tuples, ...

Edit: Rereading the parser code, it looks like currently the only valid patterns in trait method parameter position are a single identifier optionally prefixed with &, && or mut, and rereading the manual, the bit I quoted is in the description of functions, not trait methods, so I guess I don't have a real case here. ;)

@steveklabnik
Copy link
Member

Given that this would be a language change, I'm going to give it a close. Feel free to start an RFC if you want to see this land in Rust!

bors added a commit to rust-lang-ci/rust that referenced this issue Jun 5, 2023
flip1995 added a commit to flip1995/rust that referenced this issue Mar 20, 2025
r? @ghost

changelog: none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants