Skip to content

fix: Don't support const blocks in patterns - #23307

Merged
ChayimFriedman2 merged 1 commit into
rust-lang:masterfrom
Wilfred:fix/const-block-double-infer
Sep 9, 2026
Merged

fix: Don't support const blocks in patterns#23307
ChayimFriedman2 merged 1 commit into
rust-lang:masterfrom
Wilfred:fix/const-block-double-infer

Conversation

@Wilfred

@Wilfred Wilfred commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Support for const blocks in pattern positions was removed from rustc
in rust-lang/rust@a9442b4

Remove Pat::ConstBlock from hir-def so rust-analyzer is consistent with rustc lowering.

This also fixes a panic on closure calls in const blocks. This occurred because we ended up running type inference twice on ConstBlock in some code paths.

AI disclosure: Code partly written by GPT-5.6, commit message and review by me.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 7, 2026
@ChayimFriedman2

Copy link
Copy Markdown
Contributor

If rustc removed const patterns (and as far ago as more than a year), we should also remove them.

Support for const blocks in pattern positions was removed from rustc
in
rust-lang/rust@a9442b4

Remove Pat::ConstBlock from hir-def so rust-analyzer is consistent
with rustc lowering.

This also fixes a panic on closure calls in const blocks. This
occurred because we ended up running type inference twice on
ConstBlock in some code paths.

AI disclosure: Code partly written by GPT-5.6, commit message and
review by me.
@Wilfred
Wilfred force-pushed the fix/const-block-double-infer branch from 9b82ba3 to 9d3d1f9 Compare September 9, 2026 11:34
@rustbot

rustbot commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@Wilfred Wilfred changed the title fix: Panic on calling closures in const blocks fix: Do not lower const blocks in patterns Sep 9, 2026
@Wilfred Wilfred changed the title fix: Do not lower const blocks in patterns fix: Don't support const blocks in patterns Sep 9, 2026
@Wilfred

Wilfred commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

OK, I've removed the support for const blocks in lowering, matching rustc. I just dropped the relevant tests, it seemed pointless having tests for removed code paths.

I did notice that we don't currently emit any diagnostics the way rustc does for this situation:

https://github.com/rust-lang/rust/blob/a9442b4a2ab42d9456eef32990791297942fa780/compiler/rustc_ast_lowering/src/pat.rs#L420-L429

This is already an improvement, fixing the panic I was originally looking at. Long term, do we want r-a to emit all the same diagnostics that rustc does?

@ChayimFriedman2 ChayimFriedman2 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Long term, we'll just remove const block patterns from the parser as well. In fact we can already do, but not doing that is also fine.

Thanks!

View changes since this review

@ChayimFriedman2
ChayimFriedman2 added this pull request to the merge queue Sep 9, 2026
Merged via the queue into rust-lang:master with commit b376fbe Sep 9, 2026
19 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 9, 2026
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.

3 participants