about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDezhi Wu <wu543065657@163.com>2022-12-16 10:44:25 +0800
committerDezhi Wu <wu543065657@163.com>2022-12-16 10:44:25 +0800
commit258e532434c5086a29c46535ff0388ecf80fd02a (patch)
tree575b81e3b5bd095f674dcd6b0b54f2efa20a664a
parent6a295fcd3b81498a7c2a83c8bb2d6d3e3c33c722 (diff)
downloadrust-258e532434c5086a29c46535ff0388ecf80fd02a.tar.gz
rust-258e532434c5086a29c46535ff0388ecf80fd02a.zip
docs: update the comment and add a test to `half_open_range_pat`
-rw-r--r--crates/parser/src/grammar/patterns.rs7
-rw-r--r--crates/parser/test_data/parser/inline/ok/0166_half_open_range_pat.rast43
-rw-r--r--crates/parser/test_data/parser/inline/ok/0166_half_open_range_pat.rs5
3 files changed, 55 insertions, 0 deletions
diff --git a/crates/parser/src/grammar/patterns.rs b/crates/parser/src/grammar/patterns.rs
index 8de42c99eec..abcefffa23f 100644
--- a/crates/parser/src/grammar/patterns.rs
+++ b/crates/parser/src/grammar/patterns.rs
@@ -126,6 +126,8 @@ fn pattern_single_r(p: &mut Parser<'_>, recovery_set: TokenSet) {
                 //             ^
                 // `[0..]`
                 //      ^
+                // `0 .. if`
+                //       ^
                 if matches!(
                     p.current(),
                     T![=] | T![,] | T![:] | T![')'] | T!['}'] | T![']'] | T![if]
@@ -134,6 +136,11 @@ fn pattern_single_r(p: &mut Parser<'_>, recovery_set: TokenSet) {
                     // fn f() {
                     //     let 0 .. = 1u32;
                     //     let 0..: _ = 1u32;
+                    //
+                    //     match 42 {
+                    //         0 .. if true => (),
+                    //         _ => (),
+                    //     }
                     // }
                 } else {
                     atom_pat(p, recovery_set);
diff --git a/crates/parser/test_data/parser/inline/ok/0166_half_open_range_pat.rast b/crates/parser/test_data/parser/inline/ok/0166_half_open_range_pat.rast
index 4b401b60df0..c85a6859911 100644
--- a/crates/parser/test_data/parser/inline/ok/0166_half_open_range_pat.rast
+++ b/crates/parser/test_data/parser/inline/ok/0166_half_open_range_pat.rast
@@ -46,6 +46,49 @@ SOURCE_FILE
           LITERAL
             INT_NUMBER "1u32"
           SEMICOLON ";"
+        WHITESPACE "\n\n    "
+        MATCH_EXPR
+          MATCH_KW "match"
+          WHITESPACE " "
+          LITERAL
+            INT_NUMBER "42"
+          WHITESPACE " "
+          MATCH_ARM_LIST
+            L_CURLY "{"
+            WHITESPACE "\n        "
+            MATCH_ARM
+              RANGE_PAT
+                LITERAL_PAT
+                  LITERAL
+                    INT_NUMBER "0"
+                WHITESPACE " "
+                DOT2 ".."
+              WHITESPACE " "
+              MATCH_GUARD
+                IF_KW "if"
+                WHITESPACE " "
+                LITERAL
+                  TRUE_KW "true"
+              WHITESPACE " "
+              FAT_ARROW "=>"
+              WHITESPACE " "
+              TUPLE_EXPR
+                L_PAREN "("
+                R_PAREN ")"
+              COMMA ","
+            WHITESPACE "\n        "
+            MATCH_ARM
+              WILDCARD_PAT
+                UNDERSCORE "_"
+              WHITESPACE " "
+              FAT_ARROW "=>"
+              WHITESPACE " "
+              TUPLE_EXPR
+                L_PAREN "("
+                R_PAREN ")"
+              COMMA ","
+            WHITESPACE "\n    "
+            R_CURLY "}"
         WHITESPACE "\n"
         R_CURLY "}"
   WHITESPACE "\n"
diff --git a/crates/parser/test_data/parser/inline/ok/0166_half_open_range_pat.rs b/crates/parser/test_data/parser/inline/ok/0166_half_open_range_pat.rs
index c9386a221a9..f7e2d07922e 100644
--- a/crates/parser/test_data/parser/inline/ok/0166_half_open_range_pat.rs
+++ b/crates/parser/test_data/parser/inline/ok/0166_half_open_range_pat.rs
@@ -1,4 +1,9 @@
 fn f() {
     let 0 .. = 1u32;
     let 0..: _ = 1u32;
+
+    match 42 {
+        0 .. if true => (),
+        _ => (),
+    }
 }