You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Before the experimental fn delegation (#118212,
F-fn_delegation`#![feature(fn_delegation)]`
) was introduced, the following code used to compile:
fnmain(){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:
fnmain(){let reuse = 0;
reuse << reuse;//~ ERROR expected one of `!`, `(`, `+`, `::`, `<`, `>`, or `as`, found `;`}
changed the title [-]Introduction of fn delegation introduced a theoretical syntax regression (regarding weak keyword `reuse`)[/-][+]Fn delegation introduced a theoretical syntax regression (regarding weak keyword `reuse`)[/+]on Oct 29, 2025
I would say it's as useful as a block-scoped use: Only necessary in rare cases of ambiguity, otherwise merely a somewhat ~stylistic choice by the author (potentially improving local reasoning) and I think frowned upon in most larger codebases (except for enum glob imports above a match maybe).
Is there much of a use case to allow reuse directly within function bodies as opposed to at the root of a module or impl?
The item grammar should generally be the same regardless of context, in macros we don't always know where we are, that's why all items are usually parsed in all contexts.
Activity
[-]Introduction of fn delegation introduced a theoretical syntax regression (regarding weak keyword `reuse`)[/-][+]Fn delegation introduced a theoretical syntax regression (regarding weak keyword `reuse`)[/+]bjorn3 commentedon Oct 29, 2025
Is there much of a use case to allow
reusedirectly within function bodies as opposed to at the root of a module or impl?fmease commentedon Nov 28, 2025
I would say it's as useful as a block-scoped
use: Only necessary in rare cases of ambiguity, otherwise merely a somewhat ~stylistic choice by the author (potentially improving local reasoning) and I think frowned upon in most larger codebases (except for enum glob imports above a match maybe).petrochenkov commentedon Nov 28, 2025
The item grammar should generally be the same regardless of context, in macros we don't always know where we are, that's why all items are usually parsed in all contexts.
Rollup merge of rust-lang#153624 - fmease:ping-me-on-parser-changes, …
Rollup merge of rust-lang#153624 - fmease:ping-me-on-parser-changes, …
Rollup merge of rust-lang#153624 - fmease:ping-me-on-parser-changes, …
Unrolled build for #153624