about summary refs log tree commit diff
path: root/compiler/rustc_parse/src
diff options
context:
space:
mode:
authorSantiago Pastorino <spastorino@gmail.com>2020-10-19 16:18:47 -0300
committerSantiago Pastorino <spastorino@gmail.com>2020-10-22 13:21:18 -0300
commitf8842b9bacaf277430fa5c6cdf430b046dc7f323 (patch)
tree1be9f02ccf5901d4732c7088ef3259209b32bbfc /compiler/rustc_parse/src
parent954b5a81b46f60df640f36cfc83f04cd2a965051 (diff)
downloadrust-f8842b9bacaf277430fa5c6cdf430b046dc7f323.tar.gz
rust-f8842b9bacaf277430fa5c6cdf430b046dc7f323.zip
Make inline const work in range patterns
Diffstat (limited to 'compiler/rustc_parse/src')
-rw-r--r--compiler/rustc_parse/src/parser/pat.rs21
1 files changed, 15 insertions, 6 deletions
diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs
index 356743f2071..8da0a2f57d8 100644
--- a/compiler/rustc_parse/src/parser/pat.rs
+++ b/compiler/rustc_parse/src/parser/pat.rs
@@ -315,7 +315,13 @@ impl<'a> Parser<'a> {
             PatKind::Box(pat)
         } else if self.check_inline_const() {
             // Parse `const pat`
-            PatKind::Lit(self.parse_const_block(lo.to(self.token.span))?)
+            let const_expr = self.parse_const_block(lo.to(self.token.span))?;
+
+            if let Some(re) = self.parse_range_end() {
+                self.parse_pat_range_begin_with(const_expr, re)?
+            } else {
+                PatKind::Lit(const_expr)
+            }
         } else if self.can_be_ident_pat() {
             // Parse `ident @ pat`
             // This can give false positives and parse nullary enums,
@@ -716,17 +722,20 @@ impl<'a> Parser<'a> {
     }
 
     /// Is the token `dist` away from the current suitable as the start of a range patterns end?
-    fn is_pat_range_end_start(&self, dist: usize) -> bool {
-        self.look_ahead(dist, |t| {
-            t.is_path_start() // e.g. `MY_CONST`;
+    fn is_pat_range_end_start(&mut self, dist: usize) -> bool {
+        self.check_inline_const()
+            || self.look_ahead(dist, |t| {
+                t.is_path_start() // e.g. `MY_CONST`;
                 || t.kind == token::Dot // e.g. `.5` for recovery;
                 || t.can_begin_literal_maybe_minus() // e.g. `42`.
                 || t.is_whole_expr()
-        })
+            })
     }
 
     fn parse_pat_range_end(&mut self) -> PResult<'a, P<Expr>> {
-        if self.check_path() {
+        if self.check_inline_const() {
+            self.parse_const_block(self.token.span)
+        } else if self.check_path() {
             let lo = self.token.span;
             let (qself, path) = if self.eat_lt() {
                 // Parse a qualified path