rust-lang / rust-lang/rust

Self parameters & C-variadics should be syntactically legal in parenthesized generic argument lists

Open
#160,797 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-grammar A-parser C-bug F-named_fn_trait_parameters T-compiler T-lang
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Self parameters shouldn't be syntactically forbidden in this position (only semantically) since that diverges from every other place that can contain "function parameters" IINM.

We intentionally allow self parameters in e.g., function pointer types (CC https://github.com/rust-lang/rust/pull/68764, https://github.com/rust-lang/reference/pull/2240#issuecomment-4320921175) and free function items. As it stands, it means we reject X(self), X(&self), X(&mut self) but accept X(&&self), X(&&mut self) for example (the latter are rightfully legal as they're interpreted as X(_: &&self) & X(_: &&mut self) essentially[^1]).

Similarly, for C-variadics. They should be syntactically allowed, too, IMO.

Unifying this would once again simplify the grammar; we shouldn't fight the fact that self parameters & C-variadics are (meant to be) syntactically valid fn params always.

[^1]: They're however always semantically ill-formed as self is a module not a type.

Originally posted by @fmease in https://github.com/rust-lang/rust/issues/158517#issuecomment-5230955069

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No file or test is named in the issue. Start by locating the parser rules and existing tests for parenthesized generic argument lists, self parameters, and C-variadics; done means the listed forms are syntactically accepted while their existing semantic validity is preserved.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.