Fix ICE by rejecting const blocks in patterns during AST lowering (closes #148138)#149667
Merged
bors merged 1 commit intorust-lang:mainfrom Dec 29, 2025
Merged
Conversation
Collaborator
|
r? @SparrowLii rustbot has assigned @SparrowLii. Use |
tests/ui/pattern/deref-patterns/ice-adjust-mode-unimplemented-for-constblock.rs
Outdated
Show resolved
Hide resolved
dd08ea6 to
b713916
Compare
dianne
reviewed
Dec 5, 2025
Contributor
|
r? dianne |
b713916 to
8a0d87b
Compare
Collaborator
|
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 |
This comment has been minimized.
This comment has been minimized.
8a0d87b to
e412043
Compare
This comment has been minimized.
This comment has been minimized.
e412043 to
3d5438d
Compare
dianne
reviewed
Dec 5, 2025
Veykril
reviewed
Dec 5, 2025
5260fe6 to
d217779
Compare
This comment has been minimized.
This comment has been minimized.
85231c0 to
37c37ed
Compare
This comment has been minimized.
This comment has been minimized.
1d08e9f to
f910a1d
Compare
This fixes the ICE reported by rejecting `const` blocks in pattern position during AST lowering. Previously, `ExprKind::ConstBlock` could reach HIR as `PatExprKind::ConstBlock`, allowing invalid patterns to be type-checked and triggering an ICE. This patch removes the lowering path for const blocks in patterns and emits a proper diagnostic instead. A new UI test is added to ensure the compiler reports a regular error and to prevent regressions.
f910a1d to
a9442b4
Compare
Contributor
|
@bors r+ |
Collaborator
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Dec 28, 2025
…8, r=dianne Fix ICE by rejecting const blocks in patterns during AST lowering (closes rust-lang#148138) This PR fixes the ICE reported in rust-lang#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 rust-lang#148138.
This was referenced Dec 28, 2025
bors
added a commit
that referenced
this pull request
Dec 28, 2025
…uwer Rollup of 8 pull requests Successful merges: - #148321 (parser/lexer: bump to Unicode 17, use faster unicode-ident) - #149540 (std: sys: fs: uefi: Implement readdir) - #149582 (Implement `Duration::div_duration_{floor,ceil}`) - #149663 (Optimized implementation for uN::{gather,scatter}_bits) - #149667 (Fix ICE by rejecting const blocks in patterns during AST lowering (closes #148138)) - #149947 (add several older crashtests) - #150011 (Add more `unbounded_sh[lr]` examples) - #150411 (refactor `destructure_const`) r? `@ghost` `@rustbot` modify labels: rollup
rust-timer
added a commit
that referenced
this pull request
Dec 29, 2025
Rollup merge of #149667 - Shinonn23:fix-ice-constblock-148138, r=dianne Fix ICE by rejecting const blocks in patterns during AST lowering (closes #148138) 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.
flip1995
pushed a commit
to flip1995/rust
that referenced
this pull request
Jan 8, 2026
…8, r=dianne Fix ICE by rejecting const blocks in patterns during AST lowering (closes rust-lang#148138) This PR fixes the ICE reported in rust-lang#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 rust-lang#148138.
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Jan 14, 2026
… r=lcnr cleanup: remove borrowck handling for inline const patterns rust-lang#120390 added borrow-checking for inline const patterns; a type annotation was added to inline const patterns in the THIR to remember the `DefId` and args of the constants so they could be checked and constraints could be propagated to their parents. As of rust-lang#138499 though, inline const patterns can't be borrow-checked due to a query cycle, and as of rust-lang#149667, the type/`DefId`/args annotations on inline const patterns have been removed, so the borrowck code for them seems unused; this PR removes it. In a hypothetical future where borrowck doesn't depend on exhaustiveness checking so `inline_const_pat` can be reinstated, I imagine we also won't be evaluating inline const patterns before borrowck. As such, we might be able to reuse the existing code for normal unevaluated inline const operands in [`TypeChecker::visit_operand`](https://github.com/rust-lang/rust/blob/32fe406b5e71afbb0d8b95280e50e67d1549224c/compiler/rustc_borrowck/src/type_check/mod.rs#L1720-L1749) (or at least we shouldn't need to encode inline const patterns' `DefId` and args in user type annotations if they appear directly in the MIR). r? lcnr
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Jan 14, 2026
… r=lcnr cleanup: remove borrowck handling for inline const patterns rust-lang#120390 added borrow-checking for inline const patterns; a type annotation was added to inline const patterns in the THIR to remember the `DefId` and args of the constants so they could be checked and constraints could be propagated to their parents. As of rust-lang#138499 though, inline const patterns can't be borrow-checked due to a query cycle, and as of rust-lang#149667, the type/`DefId`/args annotations on inline const patterns have been removed, so the borrowck code for them seems unused; this PR removes it. In a hypothetical future where borrowck doesn't depend on exhaustiveness checking so `inline_const_pat` can be reinstated, I imagine we also won't be evaluating inline const patterns before borrowck. As such, we might be able to reuse the existing code for normal unevaluated inline const operands in [`TypeChecker::visit_operand`](https://github.com/rust-lang/rust/blob/32fe406b5e71afbb0d8b95280e50e67d1549224c/compiler/rustc_borrowck/src/type_check/mod.rs#L1720-L1749) (or at least we shouldn't need to encode inline const patterns' `DefId` and args in user type annotations if they appear directly in the MIR). r? lcnr
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Jan 14, 2026
… r=lcnr cleanup: remove borrowck handling for inline const patterns rust-lang#120390 added borrow-checking for inline const patterns; a type annotation was added to inline const patterns in the THIR to remember the `DefId` and args of the constants so they could be checked and constraints could be propagated to their parents. As of rust-lang#138499 though, inline const patterns can't be borrow-checked due to a query cycle, and as of rust-lang#149667, the type/`DefId`/args annotations on inline const patterns have been removed, so the borrowck code for them seems unused; this PR removes it. In a hypothetical future where borrowck doesn't depend on exhaustiveness checking so `inline_const_pat` can be reinstated, I imagine we also won't be evaluating inline const patterns before borrowck. As such, we might be able to reuse the existing code for normal unevaluated inline const operands in [`TypeChecker::visit_operand`](https://github.com/rust-lang/rust/blob/32fe406b5e71afbb0d8b95280e50e67d1549224c/compiler/rustc_borrowck/src/type_check/mod.rs#L1720-L1749) (or at least we shouldn't need to encode inline const patterns' `DefId` and args in user type annotations if they appear directly in the MIR). r? lcnr
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Jan 14, 2026
… r=lcnr cleanup: remove borrowck handling for inline const patterns rust-lang#120390 added borrow-checking for inline const patterns; a type annotation was added to inline const patterns in the THIR to remember the `DefId` and args of the constants so they could be checked and constraints could be propagated to their parents. As of rust-lang#138499 though, inline const patterns can't be borrow-checked due to a query cycle, and as of rust-lang#149667, the type/`DefId`/args annotations on inline const patterns have been removed, so the borrowck code for them seems unused; this PR removes it. In a hypothetical future where borrowck doesn't depend on exhaustiveness checking so `inline_const_pat` can be reinstated, I imagine we also won't be evaluating inline const patterns before borrowck. As such, we might be able to reuse the existing code for normal unevaluated inline const operands in [`TypeChecker::visit_operand`](https://github.com/rust-lang/rust/blob/32fe406b5e71afbb0d8b95280e50e67d1549224c/compiler/rustc_borrowck/src/type_check/mod.rs#L1720-L1749) (or at least we shouldn't need to encode inline const patterns' `DefId` and args in user type annotations if they appear directly in the MIR). r? lcnr
rust-timer
added a commit
that referenced
this pull request
Jan 15, 2026
Rollup merge of #150817 - cleanup-inline-const-pat-borrowck, r=lcnr cleanup: remove borrowck handling for inline const patterns #120390 added borrow-checking for inline const patterns; a type annotation was added to inline const patterns in the THIR to remember the `DefId` and args of the constants so they could be checked and constraints could be propagated to their parents. As of #138499 though, inline const patterns can't be borrow-checked due to a query cycle, and as of #149667, the type/`DefId`/args annotations on inline const patterns have been removed, so the borrowck code for them seems unused; this PR removes it. In a hypothetical future where borrowck doesn't depend on exhaustiveness checking so `inline_const_pat` can be reinstated, I imagine we also won't be evaluating inline const patterns before borrowck. As such, we might be able to reuse the existing code for normal unevaluated inline const operands in [`TypeChecker::visit_operand`](https://github.com/rust-lang/rust/blob/32fe406b5e71afbb0d8b95280e50e67d1549224c/compiler/rustc_borrowck/src/type_check/mod.rs#L1720-L1749) (or at least we shouldn't need to encode inline const patterns' `DefId` and args in user type annotations if they appear directly in the MIR). r? lcnr
github-actions bot
pushed a commit
to rust-lang/miri
that referenced
this pull request
Jan 15, 2026
cleanup: remove borrowck handling for inline const patterns rust-lang/rust#120390 added borrow-checking for inline const patterns; a type annotation was added to inline const patterns in the THIR to remember the `DefId` and args of the constants so they could be checked and constraints could be propagated to their parents. As of rust-lang/rust#138499 though, inline const patterns can't be borrow-checked due to a query cycle, and as of rust-lang/rust#149667, the type/`DefId`/args annotations on inline const patterns have been removed, so the borrowck code for them seems unused; this PR removes it. In a hypothetical future where borrowck doesn't depend on exhaustiveness checking so `inline_const_pat` can be reinstated, I imagine we also won't be evaluating inline const patterns before borrowck. As such, we might be able to reuse the existing code for normal unevaluated inline const operands in [`TypeChecker::visit_operand`](https://github.com/rust-lang/rust/blob/32fe406b5e71afbb0d8b95280e50e67d1549224c/compiler/rustc_borrowck/src/type_check/mod.rs#L1720-L1749) (or at least we shouldn't need to encode inline const patterns' `DefId` and args in user type annotations if they appear directly in the MIR). r? lcnr
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Feb 12, 2026
…expansion, r=fmease reject inline const patterns pre-expansion Reverts the parser changes from rust-lang#149667 Fixes rust-lang#152499 Awkwardly, some cases of inline const pats can only be caught pre-expansion and some can only be caught post-expansion. rust-lang#149667 switched from only rejecting the former to only rejecting the latter.
Zalathar
added a commit
to Zalathar/rust
that referenced
this pull request
Feb 13, 2026
…expansion, r=fmease reject inline const patterns pre-expansion Reverts the parser changes from rust-lang#149667 Fixes rust-lang#152499 Awkwardly, some cases of inline const pats can only be caught pre-expansion and some can only be caught post-expansion. rust-lang#149667 switched from only rejecting the former to only rejecting the latter.
Zalathar
added a commit
to Zalathar/rust
that referenced
this pull request
Feb 13, 2026
…expansion, r=fmease reject inline const patterns pre-expansion Reverts the parser changes from rust-lang#149667 Fixes rust-lang#152499 Awkwardly, some cases of inline const pats can only be caught pre-expansion and some can only be caught post-expansion. rust-lang#149667 switched from only rejecting the former to only rejecting the latter.
rust-timer
added a commit
that referenced
this pull request
Feb 13, 2026
Rollup merge of #152548 - dianne:reject-const-block-pat-pre-expansion, r=fmease reject inline const patterns pre-expansion Reverts the parser changes from #149667 Fixes #152499 Awkwardly, some cases of inline const pats can only be caught pre-expansion and some can only be caught post-expansion. #149667 switched from only rejecting the former to only rejecting the latter.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes the ICE reported in #148138.
The root cause is that
constblocks aren’t allowed in pattern position, but the AST lowering logic still attempted to createPatExprKind::ConstBlock, allowing invalid HIR to reach type checking and trigger aspan_bug!.Following the discussion in the issue, this patch removes the
ConstBlocklowering path fromlower_expr_within_pat. AnyExprKind::ConstBlockinside 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.