rust-lang / rust-lang/rust

Fn delegation introduced a theoretical syntax regression (regarding weak keyword `reuse`)

Open
#148,238 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-parser C-bug F-fn_delegation P-low regression-from-stable-to-stable T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Before the experimental fn delegation (https://github.com/rust-lang/rust/issues/118212, https://github.com/rust-lang/rust/labels/F-fn_delegation) was introduced, the following code used to compile:

fn main() {
    let reuse = 0;
    reuse < reuse;
}

Now however it leads to

error: expected one of `!`, `(`, `+`, `::`, `<`, `>`, or `as`, found `;`
 --> src/main.rs:3:18
  |
3 |     reuse < reuse;
  |                  ^ expected one of 7 possible tokens

despite reuse supposedly being a weak keyword only. Here, the parser likely treats the reuse < reuse as the start of a delegation item because the second reuse can begin a type in theory (it's looking to parse reuse <$type>::$pathtree; / reuse <$type as $traitref>::$pathtree).

Of course, this is very unlikely to be hit in practice. Moreover, I can't really see a good solution (unbounded look-ahead & backtracking is of course not on the table). In any case, the syntax is temporary.

Other example:

fn main() {
    let reuse = 0;
    reuse << reuse; //~ ERROR expected one of `!`, `(`, `+`, `::`, `<`, `>`, or `as`, found `;`
}

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

Reproduce the two Rust examples from the issue and investigate the parser path introduced by experimental fn delegation. Done means preserving these comparison expressions while retaining valid delegation parsing, but the issue does not identify a file, test, or agreed implementation approach.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.