Skip to content

Commit b713916

Browse files
committed
Remove handling of ConstBlock in pattern lowering to prevent ICE
1 parent 29e035e commit b713916

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

compiler/rustc_ast_lowering/src/pat.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
399399
ExprKind::Lit(lit) => {
400400
hir::PatExprKind::Lit { lit: self.lower_lit(lit, span), negated: false }
401401
}
402-
ExprKind::ConstBlock(c) => hir::PatExprKind::ConstBlock(self.lower_const_block(c)),
403402
ExprKind::IncludedBytes(byte_sym) => hir::PatExprKind::Lit {
404403
lit: respan(span, LitKind::ByteStr(*byte_sym, StrStyle::Cooked)),
405404
negated: false,
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Regression test for #148138
2+
// Ensure that const blocks in patterns are rejected with a proper error
3+
// instead of causing an ICE in the type checker.
4+
//
5+
// The vec! macro expansion bypasses parser validation for const blocks in patterns,
6+
// so this must be caught during AST lowering.
7+
8+
#![feature(deref_patterns)]
9+
#![expect(incomplete_features)]
10+
11+
fn main() {
12+
let vec![const { vec![] }]: Vec<usize> = vec![];
13+
//~^ ERROR expected a pattern, found a function call
14+
//~| ERROR usage of qualified paths in this context is experimental
15+
//~| ERROR expected tuple struct or tuple variant
16+
//~| ERROR arbitrary expressions aren't allowed in patterns
17+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
error[E0532]: expected a pattern, found a function call
2+
--> $DIR/ice-adjust-mode-unimplemented-for-constblock.rs:12:9
3+
|
4+
LL | let vec![const { vec![] }]: Vec<usize> = vec![];
5+
| ^^^^^^^^^^^^^^^^^^^^^^ not a tuple struct or tuple variant
6+
|
7+
= note: function calls are not allowed in patterns: <https://doc.rust-lang.org/book/ch19-00-patterns.html>
8+
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
9+
10+
error[E0658]: usage of qualified paths in this context is experimental
11+
--> $DIR/ice-adjust-mode-unimplemented-for-constblock.rs:12:9
12+
|
13+
LL | let vec![const { vec![] }]: Vec<usize> = vec![];
14+
| ^^^^^^^^^^^^^^^^^^^^^^
15+
|
16+
= note: see issue #86935 <https://github.com/rust-lang/rust/issues/86935> for more information
17+
= help: add `#![feature(more_qualified_paths)]` to the crate attributes to enable
18+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
19+
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
20+
21+
error: arbitrary expressions aren't allowed in patterns
22+
--> $DIR/ice-adjust-mode-unimplemented-for-constblock.rs:12:14
23+
|
24+
LL | let vec![const { vec![] }]: Vec<usize> = vec![];
25+
| ^^^^^^^^^^^^^^^^
26+
27+
error[E0164]: expected tuple struct or tuple variant, found associated function `<[_]>::into_vec`
28+
--> $DIR/ice-adjust-mode-unimplemented-for-constblock.rs:12:9
29+
|
30+
LL | let vec![const { vec![] }]: Vec<usize> = vec![];
31+
| ^^^^^^^^^^^^^^^^^^^^^^ `fn` calls are not allowed in patterns
32+
|
33+
= help: for more information, visit https://doc.rust-lang.org/book/ch19-00-patterns.html
34+
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
35+
36+
error: aborting due to 4 previous errors
37+
38+
Some errors have detailed explanations: E0164, E0532, E0658.
39+
For more information about an error, try `rustc --explain E0164`.

0 commit comments

Comments
 (0)