Skip to content

Conversation

@Shinonn23
Copy link

@Shinonn23 Shinonn23 commented Dec 5, 2025

This PR fixes the ICE reported in #148138.

The root cause is that const blocks aren’t allowed in pattern position, but the AST lowering logic still attempted to create PatExprKind::ConstBlock, allowing invalid HIR to reach type checking and trigger a span_bug!.

Following the discussion in the issue, this patch removes the ConstBlock lowering path from lower_expr_within_pat. Any ExprKind::ConstBlock inside a pattern is now handled consistently with other invalid pattern expressions.

A new UI test is included to ensure the compiler reports a proper error and to prevent regressions.

Closes #148138.

@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 Dec 5, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 5, 2025

r? @SparrowLii

rustbot has assigned @SparrowLii.
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

@Shinonn23 Shinonn23 force-pushed the fix-ice-constblock-148138 branch from dd08ea6 to b713916 Compare December 5, 2025 05:38
@dianne
Copy link
Contributor

dianne commented Dec 5, 2025

r? dianne

@rustbot rustbot assigned dianne and unassigned SparrowLii Dec 5, 2025
@Shinonn23 Shinonn23 force-pushed the fix-ice-constblock-148138 branch from b713916 to 8a0d87b Compare December 5, 2025 07:22
@rustbot
Copy link
Collaborator

rustbot commented Dec 5, 2025

rust-analyzer is developed in its own repository. If possible, consider making this change to rust-lang/rust-analyzer instead.

cc @rust-lang/rust-analyzer

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

Some changes occurred in match checking

cc @Nadrieril

@rustbot rustbot added T-clippy Relevant to the Clippy team. T-rust-analyzer Relevant to the rust-analyzer team, which will review and decide on the PR/issue. labels Dec 5, 2025
@rustbot

This comment has been minimized.

@Shinonn23 Shinonn23 force-pushed the fix-ice-constblock-148138 branch from 8a0d87b to e412043 Compare December 5, 2025 07:25
@rustbot

This comment has been minimized.

@Shinonn23 Shinonn23 force-pushed the fix-ice-constblock-148138 branch from e412043 to 3d5438d Compare December 5, 2025 07:26
Copy link
Member

@Veykril Veykril left a comment

Choose a reason for hiding this comment

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

This should not need to touch rust-analyzer source

View changes since this review

@Shinonn23 Shinonn23 force-pushed the fix-ice-constblock-148138 branch 2 times, most recently from 5260fe6 to d217779 Compare December 5, 2025 07:54
@rust-log-analyzer

This comment has been minimized.

@jieyouxu jieyouxu closed this Dec 5, 2025
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 5, 2025
@jieyouxu jieyouxu reopened this Dec 5, 2025
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 5, 2025
@Shinonn23 Shinonn23 force-pushed the fix-ice-constblock-148138 branch 2 times, most recently from 85231c0 to 37c37ed Compare December 5, 2025 11:12
@rust-log-analyzer

This comment has been minimized.

@Shinonn23 Shinonn23 force-pushed the fix-ice-constblock-148138 branch from 37c37ed to 73dfb1d Compare December 7, 2025 08:39
Copy link
Contributor

@dianne dianne left a comment

Choose a reason for hiding this comment

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

This is looking good now, thanks! Just a few more notes.
@rustbot author

View changes since this 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 Dec 7, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 7, 2025

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

@rust-log-analyzer

This comment has been minimized.

@Shinonn23 Shinonn23 force-pushed the fix-ice-constblock-148138 branch from 45c1507 to 52ba844 Compare December 8, 2025 08:53
@Shinonn23 Shinonn23 force-pushed the fix-ice-constblock-148138 branch 2 times, most recently from dd10d88 to d488992 Compare December 8, 2025 12:52
… HIR

This fixes the reported ICE by explicitly rejecting `const` blocks
in patterns during AST lowering.

Additionally, performs complete cleanup:
- Removed `PatExprKind::ConstBlock` from HIR.
- Removed `Pat::ConstBlockPat` from Rust Analyzer.
- Cleaned up Clippy and other tools.
@Shinonn23 Shinonn23 force-pushed the fix-ice-constblock-148138 branch from d488992 to 5328fa7 Compare December 8, 2025 12:55
Copy link
Contributor

@dianne dianne left a comment

Choose a reason for hiding this comment

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

Looks good to me; thanks! One last request: could you fix the PR and commit descriptions? Specifically,

Any ExprKind::ConstBlock inside a pattern now lowers to PatKind::Err, consistent with how other invalid pattern expressions are handled.

This isn't the case. Invalid expression patterns lower to PatKind::Expr of PatExprKind::Lit representing a LitKind::Err. This doesn't need to be in the PR description, but I'd like to make sure whatever details are there are accurate. ^^

I think it'd be fine without that sentence, but it also wouldn't hurt to keep the detail about being consistent with how other invalid pattern expressions are handled. I'll leave the particulars up to you.

  • Removed Pat::ConstBlockPat from Rust Analyzer.

This is no longer part of the PR.

  • Cleaned up Clippy and other tools.

No other tools needed cleanup. And this is just a nit, but I think the clippy change could count as part of removing PatExprKind::ConstBlock from the HIR; there shouldn't be any other cleanup to clippy.

View changes since this review

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

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rust-analyzer Relevant to the rust-analyzer team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ICE adjust mode unimplemented for ConstBlock

8 participants