Skip to content

Remove incorrect parse error recovery code that mistakes as casts for the long removed type ascription - #162700

Open
fmease wants to merge 2 commits into
rust-lang:mainfrom
fmease:rm-dead-ascr-recov
Open

Remove incorrect parse error recovery code that mistakes as casts for the long removed type ascription#162700
fmease wants to merge 2 commits into
rust-lang:mainfrom
fmease:rm-dead-ascr-recov

Conversation

@fmease

@fmease fmease commented Sep 12, 2026

Copy link
Copy Markdown
Member

Back when we still had type ascription syntax $expr : $ty, parse_assoc_op_cast would parse both as casts & type ascription.

During that time (namely in commit 8c5dafd), parse error recovery from code like label: loop {} was added (label lacks leading apostrophe). However, it never checked if we did actually parse a : and not an as meaning to this day we emit a nonsensical diagnostic for expressions like label as loop {}! This PR does away with this code & further cleans up in the area (thanks to type ascription being gone).

In case you're wondering, we do still recover from expr stmts like label: loop {} as we have some code in the stmt parser for this.

Since the removal of the type ascription syntax we do indeed no longer provide that recovery for arbitrary exprs (e.g, (label: loop {})) which I find absolutely acceptable.

(No LLM was or will be used by me during the entire creation process of this PR)

@fmease fmease added the C-cleanup Category: PRs that clean code up or issues documenting cleanup. label Sep 12, 2026
@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 Sep 12, 2026
@rustbot

rustbot commented Sep 12, 2026

Copy link
Copy Markdown
Collaborator

r? @fee1-dead

rustbot has assigned @fee1-dead.
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, parser
  • compiler, parser expanded to 76 candidates
  • Random selection from 21 candidates

@chenyukang

Copy link
Copy Markdown
Member

link #101728

@chenyukang

Copy link
Copy Markdown
Member

maybe add a ui test for it since there is a observable change on diagnostics.

@fmease

fmease commented Sep 13, 2026

Copy link
Copy Markdown
Member Author

maybe add a ui test for it since there is a observable change on diagnostics.

I'm usually pro tests (of course) but in cases like here (or over there: #162704) I'm less in favor since the larger context is me being on a spree to dejank the parser trying to shave off as much crusty code as possible (cc #162269, #161796).

How likely would it be for label as loop {} to regress again? I believe it's 0% because we've de-RFC'ed $expr : $ty as you obviously know. So what would the odds be? It's just a lot more satisfying to have diffs where removed>>added ^^' Adding a regression test that in my eyes doesn't bear any value would make a dent in that.

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

Labels

C-cleanup Category: PRs that clean code up or issues documenting cleanup. 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants