Skip to content

Patterns make parsing of optional parameter names kinda wonky #14445

Closed
@ben0x539

Description

@ben0x539

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. ;)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions