Skip to content

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

@fmease

Description

@fmease

Before the experimental fn delegation (#118212, F-fn_delegation `#![feature(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 `;`
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-parserArea: The lexing & parsing of Rust source code to an ASTC-bugCategory: This is a bug.F-fn_delegation`#![feature(fn_delegation)]`P-lowLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions