about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_parse/src/parser/pat.rs3
-rw-r--r--src/test/ui/parser/inline_const/const_match_pat_parses.rs20
-rw-r--r--src/test/ui/parser/issue-66357-unexpected-unreachable.rs2
-rw-r--r--src/test/ui/parser/issue-66357-unexpected-unreachable.stderr2
4 files changed, 25 insertions, 2 deletions
diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs
index 5aced9dc37c..15db2066a30 100644
--- a/compiler/rustc_parse/src/parser/pat.rs
+++ b/compiler/rustc_parse/src/parser/pat.rs
@@ -313,6 +313,9 @@ impl<'a> Parser<'a> {
             let pat = self.parse_pat_with_range_pat(false, None)?;
             self.sess.gated_spans.gate(sym::box_patterns, lo.to(self.prev_token.span));
             PatKind::Box(pat)
+        } else if self.check_inline_const() {
+            // Parse `const pat`
+            PatKind::Lit(self.parse_const_expr(lo.to(self.token.span))?)
         } else if self.can_be_ident_pat() {
             // Parse `ident @ pat`
             // This can give false positives and parse nullary enums,
diff --git a/src/test/ui/parser/inline_const/const_match_pat_parses.rs b/src/test/ui/parser/inline_const/const_match_pat_parses.rs
new file mode 100644
index 00000000000..97b05b0a1f2
--- /dev/null
+++ b/src/test/ui/parser/inline_const/const_match_pat_parses.rs
@@ -0,0 +1,20 @@
+// check-pass
+// compile-flags: -Z parse-only
+
+#![feature(inline_const)]
+const MMIO_BIT1: u8 = 4;
+const MMIO_BIT2: u8 = 5;
+
+fn main() {
+    match read_mmio() {
+        0 => {}
+        const { 1 << MMIO_BIT1 } => println!("FOO"),
+        const { 1 << MMIO_BIT2 } => println!("BAR"),
+
+        _ => unreachable!(),
+    }
+}
+
+fn read_mmio() -> u8 {
+    1 << 5
+}
diff --git a/src/test/ui/parser/issue-66357-unexpected-unreachable.rs b/src/test/ui/parser/issue-66357-unexpected-unreachable.rs
index 5ec143fae23..7b95bc775ba 100644
--- a/src/test/ui/parser/issue-66357-unexpected-unreachable.rs
+++ b/src/test/ui/parser/issue-66357-unexpected-unreachable.rs
@@ -13,4 +13,4 @@
 
 fn f() { |[](* }
 //~^ ERROR expected one of `,` or `:`, found `(`
-//~| ERROR expected one of `&`, `(`, `)`, `-`, `...`, `..=`, `..`, `[`, `_`, `box`, `mut`, `ref`, `|`, identifier, or path, found `*`
+//~| ERROR expected one of `&`, `(`, `)`, `-`, `...`, `..=`, `..`, `[`, `_`, `box`, `const`, `mut`, `ref`, `|`, identifier, or path, found `*`
diff --git a/src/test/ui/parser/issue-66357-unexpected-unreachable.stderr b/src/test/ui/parser/issue-66357-unexpected-unreachable.stderr
index c3810999d23..5549f73920d 100644
--- a/src/test/ui/parser/issue-66357-unexpected-unreachable.stderr
+++ b/src/test/ui/parser/issue-66357-unexpected-unreachable.stderr
@@ -4,7 +4,7 @@ error: expected one of `,` or `:`, found `(`
 LL | fn f() { |[](* }
    |             ^ expected one of `,` or `:`
 
-error: expected one of `&`, `(`, `)`, `-`, `...`, `..=`, `..`, `[`, `_`, `box`, `mut`, `ref`, `|`, identifier, or path, found `*`
+error: expected one of `&`, `(`, `)`, `-`, `...`, `..=`, `..`, `[`, `_`, `box`, `const`, `mut`, `ref`, `|`, identifier, or path, found `*`
   --> $DIR/issue-66357-unexpected-unreachable.rs:14:14
    |
 LL | fn f() { |[](* }