Skip to content

Commit 59d07c3

Browse files
committed
Parse inline const patterns
1 parent c3e8d79 commit 59d07c3

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

compiler/rustc_parse/src/parser/pat.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,9 @@ impl<'a> Parser<'a> {
313313
let pat = self.parse_pat_with_range_pat(false, None)?;
314314
self.sess.gated_spans.gate(sym::box_patterns, lo.to(self.prev_token.span));
315315
PatKind::Box(pat)
316+
} else if self.check_inline_const() {
317+
// Parse `const pat`
318+
PatKind::Lit(self.parse_const_expr(lo.to(self.token.span))?)
316319
} else if self.can_be_ident_pat() {
317320
// Parse `ident @ pat`
318321
// This can give false positives and parse nullary enums,
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// check-pass
2+
// compile-flags: -Z parse-only
3+
4+
#![feature(inline_const)]
5+
const MMIO_BIT1: u8 = 4;
6+
const MMIO_BIT2: u8 = 5;
7+
8+
fn main() {
9+
match read_mmio() {
10+
0 => {}
11+
const { 1 << MMIO_BIT1 } => println!("FOO"),
12+
const { 1 << MMIO_BIT2 } => println!("BAR"),
13+
14+
_ => unreachable!(),
15+
}
16+
}
17+
18+
fn read_mmio() -> u8 {
19+
1 << 5
20+
}

src/test/ui/parser/issue-66357-unexpected-unreachable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313

1414
fn f() { |[](* }
1515
//~^ ERROR expected one of `,` or `:`, found `(`
16-
//~| ERROR expected one of `&`, `(`, `)`, `-`, `...`, `..=`, `..`, `[`, `_`, `box`, `mut`, `ref`, `|`, identifier, or path, found `*`
16+
//~| ERROR expected one of `&`, `(`, `)`, `-`, `...`, `..=`, `..`, `[`, `_`, `box`, `const`, `mut`, `ref`, `|`, identifier, or path, found `*`

src/test/ui/parser/issue-66357-unexpected-unreachable.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: expected one of `,` or `:`, found `(`
44
LL | fn f() { |[](* }
55
| ^ expected one of `,` or `:`
66

7-
error: expected one of `&`, `(`, `)`, `-`, `...`, `..=`, `..`, `[`, `_`, `box`, `mut`, `ref`, `|`, identifier, or path, found `*`
7+
error: expected one of `&`, `(`, `)`, `-`, `...`, `..=`, `..`, `[`, `_`, `box`, `const`, `mut`, `ref`, `|`, identifier, or path, found `*`
88
--> $DIR/issue-66357-unexpected-unreachable.rs:14:14
99
|
1010
LL | fn f() { |[](* }

0 commit comments

Comments
 (0)