-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -399,7 +399,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { | |
| ExprKind::Lit(lit) => { | ||
| hir::PatExprKind::Lit { lit: self.lower_lit(lit, span), negated: false } | ||
| } | ||
| ExprKind::ConstBlock(c) => hir::PatExprKind::ConstBlock(self.lower_const_block(c)), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since they're caught here now, maybe it would make sense to remove the special-casing of const blocks in patterns from the parser?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! I've removed
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd actually not recommend changing rust-analyzer here. Could you remove the rust-analyzer changes from this PR and open a separate cleanup PR to the rust-analyzer repository instead (rust-lang/rust-analyzer)? rust-analyzer uses its own representations of Rust code, so it shouldn't be necessary to change it here, I don't think.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've reverted the rust-analyzer changes in the latest push
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm also not seeing the change to the parser you said you did. Are you writing this using an LLM? I'd strongly recommend writing contributions by hand and reviewing your own code and github interactions. If I'm effectively writing this PR by proxy, I can't approve it; it'd at least need another reviewer to sign off on it. I'd like to help you contribute if it's your own contribution, but machine-generated PRs and replies place extra stress on reviewers; we rely on contributors to self-review and understand the changes they're making. See rust-lang/compiler-team#893 for more information. Apologies if I've jumped to conclusions.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for your patience as well, and sorry for any alarm I might have caused. ^^
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And of course, if anything is unclear, I'd be happy to clarify or explain.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you very much, it my first time to contribute :) So, I have done clean up the parser |
||
| ExprKind::IncludedBytes(byte_sym) => hir::PatExprKind::Lit { | ||
| lit: respan(span, LitKind::ByteStr(*byte_sym, StrStyle::Cooked)), | ||
| negated: false, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,8 @@ | ||
| error: const blocks cannot be used as patterns | ||
| --> $DIR/in-pat-recovery.rs:6:15 | ||
| error: arbitrary expressions aren't allowed in patterns | ||
| --> $DIR/in-pat-recovery.rs:6:9 | ||
| | | ||
| LL | const { 1 + 7 } => {} | ||
| | ^^^^^^^^^ | ||
| | | ||
| = help: use a named `const`-item or an `if`-guard (`x if x == const { ... }`) instead | ||
| | ^^^^^^^^^^^^^^^ | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| #![feature(deref_patterns)] | ||
| #![expect(incomplete_features)] | ||
|
|
||
| fn main() { | ||
| let vec![const { vec![] }]: Vec<usize> = vec![]; | ||
| //~^ ERROR expected a pattern, found a function call | ||
| //~| ERROR usage of qualified paths in this context is experimental | ||
| //~| ERROR expected tuple struct or tuple variant | ||
| //~| ERROR arbitrary expressions aren't allowed in patterns | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| error[E0532]: expected a pattern, found a function call | ||
| --> $DIR/ice-adjust-mode-unimplemented-for-constblock.rs:5:9 | ||
| | | ||
| LL | let vec![const { vec![] }]: Vec<usize> = vec![]; | ||
| | ^^^^^^^^^^^^^^^^^^^^^^ not a tuple struct or tuple variant | ||
| | | ||
| = note: function calls are not allowed in patterns: <https://doc.rust-lang.org/book/ch19-00-patterns.html> | ||
| = note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
|
||
| error[E0658]: usage of qualified paths in this context is experimental | ||
| --> $DIR/ice-adjust-mode-unimplemented-for-constblock.rs:5:9 | ||
| | | ||
| LL | let vec![const { vec![] }]: Vec<usize> = vec![]; | ||
| | ^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| = note: see issue #86935 <https://github.com/rust-lang/rust/issues/86935> for more information | ||
| = help: add `#![feature(more_qualified_paths)]` to the crate attributes to enable | ||
| = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
| = note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
|
||
| error: arbitrary expressions aren't allowed in patterns | ||
| --> $DIR/ice-adjust-mode-unimplemented-for-constblock.rs:5:14 | ||
| | | ||
| LL | let vec![const { vec![] }]: Vec<usize> = vec![]; | ||
| | ^^^^^^^^^^^^^^^^ | ||
|
|
||
| error[E0164]: expected tuple struct or tuple variant, found associated function `<[_]>::into_vec` | ||
| --> $DIR/ice-adjust-mode-unimplemented-for-constblock.rs:5:9 | ||
| | | ||
| LL | let vec![const { vec![] }]: Vec<usize> = vec![]; | ||
| | ^^^^^^^^^^^^^^^^^^^^^^ `fn` calls are not allowed in patterns | ||
| | | ||
| = help: for more information, visit https://doc.rust-lang.org/book/ch19-00-patterns.html | ||
| = note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
|
||
| error: aborting due to 4 previous errors | ||
|
|
||
| Some errors have detailed explanations: E0164, E0532, E0658. | ||
| For more information about an error, try `rustc --explain E0164`. |
Uh oh!
There was an error while loading. Please reload this page.