-
Notifications
You must be signed in to change notification settings - Fork 14.1k
Fix ICE by rejecting const blocks in patterns during AST lowering (closes #148138) #149667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
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
|
r? dianne |
b713916 to
8a0d87b
Compare
|
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
There was a problem hiding this 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
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.
37c37ed to
73dfb1d
Compare
There was a problem hiding this 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
| | ^^^^^^^^^ | ||
| | | ||
| = help: use a named `const`-item or an `if`-guard (`x if x == const { ... }`) instead |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be nice to keep this help message around. Could you add it to the ArbitraryExpressionInPattern error emitted during AST lowering? There's an optional pattern_from_macro_note note on it already, so you can use that as a reference (except making it a help rather than a note). We could also use the const blocks cannot be used as patterns message in that case too, but I could go either way on that; arbitrary expressions aren't allowed in patterns seems fine enough to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
|
Reminder, once the PR becomes ready for a review, use |
… 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.
73dfb1d to
45c1507
Compare
|
The job Click to see the possible cause of the failure (guessed by this bot) |
| let guar = self.dcx().emit_err(ArbitraryExpressionInPattern { | ||
| span, | ||
| pattern_from_macro_note: pattern_from_macro, | ||
| arbitrary_expression_in_pattern_help: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the help message is specific to const blocks, it should only show up if the AST expression being lowered is actually a const block. It might be helpful to name its corresponding field as such too.
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. That allowed invalid HIR to reach type checking, which then hit aspan_bug!.Following the discussion in the issue, this patch removes the
ConstBlocklowering path fromlower_expr_within_pat.Any
ExprKind::ConstBlockinside a pattern now lowers toPatKind::Err, consistent with how other invalid pattern expressions are handled.A new UI test is included to ensure the compiler emits a proper error for const blocks in patterns and to prevent regressions.
Closes #148138