Skip to content

Fix ICE when a forced keyword follows a parameter pattern - #165700

Closed
lazerg wants to merge 2 commits into
rust-lang:mainfrom
lazerg:fix/issue-165690-forced-kw-param-without-type
Closed

lazerg wants to merge 2 commits into
rust-lang:mainfrom
lazerg:fix/issue-165690-forced-kw-param-without-type

Conversation

@lazerg

@lazerg lazerg commented Nov 9, 2026 •

Copy link
Copy Markdown

For fn bar(S k#self) {}, the C-style parameter recovery (fn foo(String s)) saw an identifier token after the pattern and unwrapped parse_ident_common(true), but that returns an error for forced keywords instead of recovering, so the parser ICEd. Forced keywords are never identifiers, so the recovery now skips them and we report the normal "expected one of :, @, or |" error. The missing fn/struct keyword recovery had the same unwrap (pub k#self() {} ICEd too), so it gets the same check.

Fixes #165690

@rustbot

rustbot commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

The parser was modified, potentially altering the grammar of (stable) Rust
which would be a breaking change.

cc @fmease

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 9, 2026
@rustbot

rustbot commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

r? @aerooneqq

rustbot has assigned @aerooneqq.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 79 candidates
  • Random selection from 22 candidates

@fmease fmease assigned fmease and unassigned aerooneqq Nov 9, 2026
@apiraino

apiraino commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

@lazerg given your recent streak of patches, can you please disclose your LLM usage (if any)? thanks

@lazerg

lazerg commented Nov 9, 2026

Copy link
Copy Markdown
Author

Yes, I prepare these patches with Claude Code (Claude Opus 5.5).

@workingjubilee

Copy link
Copy Markdown
Member

Submitting such patches without disclosure of LLM usage up-front is incorrect. Please read the LLM usage policy.

Comment on lines 2011 to 2016
if self.check_ident()
&& !matches!(self.token.ident(), Some((_, IdentKind::ForcedKeyword)))
&& self.look_ahead(1, |t| *t == token::Comma || *t == token::CloseParen)
{
// `fn foo(String s) {}`
let ident = self.parse_ident_common(true).unwrap();

@fmease fmease Nov 9, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if let Some(ident) = self.token.non_reserved_ident()
&& self.look_ahead(1, |t| *t == token::Comma || *t == token::CloseParen)
{
// `fn foo(String s) {}`
self.bump(); // ident

View changes since the review

Comment on lines 510 to 516
let ident = if self.token.is_ident()
&& !matches!(self.token.ident(), Some((_, IdentKind::ForcedKeyword)))
&& (!is_const || self.look_ahead(1, |t| *t == token::OpenParen))
&& self.look_ahead(1, |t| {
matches!(t.kind, token::Lt | token::OpenBrace | token::OpenParen)
}) {
self.parse_ident_common(true).unwrap()

@fmease fmease Nov 9, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, (pseudo)

if is_ident() && !matches!(ForcedKeyword) ... { parse_ident_common().unwrap()`

to (pseudo)

if let Some(ident) = self.token.non_reserved_ident() ... { self.bump(); // ident

View changes since the review

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 9, 2026
@rustbot

rustbot commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@oli-obk oli-obk closed this Nov 9, 2026
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Nov 9, 2026
@oli-obk

oli-obk commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Hi,

For the last few months we have been receiving an increased amount of slop by users running bots that generate contributions, and even misconfiguring their bot so it will even send generated apology emails on top. We have no way to distinguish your PR from your other generated ones and no way to determine whether you actually want to contribute.

We are a community of contributors, not just a code repository. Thus we focus on contributors who desire to stay around and put in the work to produce high quality contributions or learn to do so.

We are thus banning you as per our policies (1) and contribution standards (2). You can contact the moderation team to discuss and possibly reconsider your ban.

Thanks for understanding

Oli in the name of the mod team

jhpratt added a commit to jhpratt/rust that referenced this pull request Nov 20, 2026
…-kw-param-without-type, r=fmease

fix ICE when a forced keyword follows a parameter pattern

This is a resubmission of rust-lang#165700 by lazerg.

Fixes rust-lang#165690

r? fmease
jhpratt added a commit to jhpratt/rust that referenced this pull request Nov 20, 2026
…-kw-param-without-type, r=fmease

fix ICE when a forced keyword follows a parameter pattern

This is a resubmission of rust-lang#165700 by lazerg.

Fixes rust-lang#165690

r? fmease
rust-bors Bot pushed a commit that referenced this pull request Nov 20, 2026
Rollup merge of #165906 - programskillforverification:forced-kw-param-without-type, r=fmease

fix ICE when a forced keyword follows a parameter pattern

This is a resubmission of #165700 by lazerg.

Fixes #165690

r? fmease
folkertdev pushed a commit to folkertdev/stdarch that referenced this pull request Nov 22, 2026
…-without-type, r=fmease

fix ICE when a forced keyword follows a parameter pattern

This is a resubmission of rust-lang/rust#165700 by lazerg.

Fixes rust-lang/rust#165690

r? fmease
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ICE]: called Result::unwrap() on an Err value, in parser/diagnostics.rs's parameter_without_type

7 participants