-
-
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
|
Reminder, once the PR becomes ready for a review, use |
73dfb1d to
45c1507
Compare
This comment has been minimized.
This comment has been minimized.
45c1507 to
52ba844
Compare
dd10d88 to
d488992
Compare
… 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.
d488992 to
5328fa7
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.
Looks good to me; thanks! One last request: could you fix the PR and commit descriptions? Specifically,
Any
ExprKind::ConstBlockinside a pattern now lowers toPatKind::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::ConstBlockPatfrom 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.
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.