Skip to content

Grammar check: update rustc for forced keywords - #2369

Merged
traviscross merged 1 commit into
rust-lang:masterfrom
DanielEScherzer:grammar-check-forced-keywords
Sep 29, 2026
Merged

traviscross merged 1 commit into
rust-lang:masterfrom
DanielEScherzer:grammar-check-forced-keywords

Conversation

@DanielEScherzer

@DanielEScherzer DanielEScherzer commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

@rustbot rustbot added the S-waiting-on-review Status: The marked PR is awaiting review from a maintainer label Sep 29, 2026
@DanielEScherzer

Copy link
Copy Markdown
Contributor Author

To be clear, this fixes the compilation, the changed grammar means that the actual grammar check fails

------------------------------------------------------------
error: reference failed, rustc_parse passed
test: rust/tests/ui/parser/forced-keywords/non-keyword-neg.rs
reference error: invalid token RESERVED_TOKEN at `k#not_a_keyword()
    //~^ ERROR expected expression, found `k#not_a_keyword`
}
fn k#trying_to_pass_…`
8:     k#not_a_keyword()
       ━
------------------------------------------------------------
error: reference failed, rustc_parse passed
test: rust/tests/ui/parser/forced-keywords/non-keyword-pos.rs
reference error: invalid token RESERVED_TOKEN at `k#not_a_keyword); // OK
#[cfg(false)]
invoke!(k#arbitrary_string_of_chars);
fn main() {}
`
9: discard!(k#not_a_keyword); // OK
            ━
------------------------------------------------------------
error: reference failed, rustc_parse passed
test: rust/tests/ui/parser/forced-keywords/decl-macro-matching.rs
reference error: invalid token RESERVED_TOKEN at `k#type) => {};
    (Normal type) => {};
}
accept!(ForcedKeyword type); //~ ERROR no rules expected …`
8:     (ForcedKeyword k#type) => {};
                      ━
------------------------------------------------------------
error: reference failed, rustc_parse passed
test: rust/tests/ui/parser/forced-keywords/basic.rs
reference error: invalid token RESERVED_TOKEN at `k#mod module {
    k#pub(k#in k#super) k#static _DATA: i32 = 0i8 k#as k#_;
}
k#use ::std::process::…`
5: k#mod module {
   ━
------------------------------------------------------------
error: reference failed, rustc_parse passed
test: rust/tests/ui/parser/forced-keywords/feature-gate-forced-keywords.rs
reference error: invalid token RESERVED_TOKEN at `k#fn main() {} //~ ERROR forced keywords are experimental
#[cfg(false)]
k#fn start() {} //~ ERROR f…`
3: k#fn main() {} //~ ERROR forced keywords are experimental
   ━
------------------------------------------------------------
error: reference failed, rustc_parse passed
test: rust/tests/ui/parser/forced-keywords/pre-2021-edition-fail.rs
reference error: invalid token RESERVED_TOKEN at `k#fn main() {} //~ ERROR expected one of `!` or `::`, found `#`
`
3: k#fn main() {} //~ ERROR expected one of `!` or `::`, found `#`
   ━
------------------------------------------------------------
error: reference failed, rustc_parse passed
test: rust/tests/ui/parser/forced-keywords/pre-2021-edition-pass.rs
reference error: invalid token RESERVED_TOKEN at `k#fn }
//~^ WARNING parsed as a forced keyword in Rust 2021 and onward
//~| WARNING this changes mea…`
10: ensure! { k#fn }
              ━
------------------------------------------------------------
passed: 78079
failed: 7
finished in 3 minutes 25 seconds

Fixing the actual check will require more extensive changes to the actual reference grammar that should be done later

@fmease

fmease commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

Fixing the actual check will require more extensive changes to the actual reference grammar that should be done later [emphasis: mine]

Note that this feature is perma-unstable and should not be observable on stable. The Reference should not mention this token kind.

From the perspective of the Reference k#ident continues to be treated as a reserved prefixed ident in Rust >=2021 just like e.g., prefix#ident.

It just "happens to be case" that rustc emits a different diagnostic for k#ident compared to other reserved prefixes, namely something like "forced keywords are unstable".

What happens if the source code also contains #![feature(forced_keywords)] is out of scope for the Reference / not under its purview.

@DanielEScherzer
DanielEScherzer force-pushed the grammar-check-forced-keywords branch from a44c939 to 9c3509d Compare September 29, 2026 18:43
@DanielEScherzer
DanielEScherzer force-pushed the grammar-check-forced-keywords branch from 9c3509d to 048dfca Compare September 29, 2026 18:45
@traviscross

Copy link
Copy Markdown
Contributor

Thanks @DanielEScherzer.

@traviscross
traviscross added this pull request to the merge queue Sep 29, 2026
Merged via the queue into rust-lang:master with commit fc518e9 Sep 29, 2026
8 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: The marked PR is awaiting review from a maintainer label Sep 29, 2026
@DanielEScherzer
DanielEScherzer deleted the grammar-check-forced-keywords branch September 29, 2026 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Daily Grammar Check Failed - 2026-09-29

4 participants