diff options
Diffstat (limited to 'crates')
3 files changed, 96 insertions, 0 deletions
diff --git a/crates/parser/src/grammar/patterns.rs b/crates/parser/src/grammar/patterns.rs index 7e7f73dee..44400c9f8 100644 --- a/crates/parser/src/grammar/patterns.rs +++ b/crates/parser/src/grammar/patterns.rs | |||
@@ -1,5 +1,7 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use expressions::block_expr; | ||
4 | |||
3 | use super::*; | 5 | use super::*; |
4 | 6 | ||
5 | pub(super) const PATTERN_FIRST: TokenSet = | 7 | pub(super) const PATTERN_FIRST: TokenSet = |
@@ -89,6 +91,7 @@ fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option<CompletedMarker> { | |||
89 | let m = match p.nth(0) { | 91 | let m = match p.nth(0) { |
90 | T![box] => box_pat(p), | 92 | T![box] => box_pat(p), |
91 | T![ref] | T![mut] => ident_pat(p, true), | 93 | T![ref] | T![mut] => ident_pat(p, true), |
94 | T![const] => const_block_pat(p), | ||
92 | IDENT => match p.nth(1) { | 95 | IDENT => match p.nth(1) { |
93 | // Checks the token after an IDENT to see if a pattern is a path (Struct { .. }) or macro | 96 | // Checks the token after an IDENT to see if a pattern is a path (Struct { .. }) or macro |
94 | // (T![x]). | 97 | // (T![x]). |
@@ -386,3 +389,16 @@ fn box_pat(p: &mut Parser) -> CompletedMarker { | |||
386 | pattern_single(p); | 389 | pattern_single(p); |
387 | m.complete(p, BOX_PAT) | 390 | m.complete(p, BOX_PAT) |
388 | } | 391 | } |
392 | |||
393 | // test const_block_pat | ||
394 | // fn main() { | ||
395 | // let const { 15 } = (); | ||
396 | // let const { foo(); bar() } = (); | ||
397 | // } | ||
398 | fn const_block_pat(p: &mut Parser) -> CompletedMarker { | ||
399 | assert!(p.at(T![const])); | ||
400 | let m = p.start(); | ||
401 | p.bump(T![const]); | ||
402 | block_expr(p); | ||
403 | m.complete(p, CONST_BLOCK_PAT) | ||
404 | } | ||
diff --git a/crates/syntax/test_data/parser/inline/ok/0156_const_block_pat.rast b/crates/syntax/test_data/parser/inline/ok/0156_const_block_pat.rast new file mode 100644 index 000000000..8ff4822c4 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0156_const_block_pat.rast | |||
@@ -0,0 +1,76 @@ | |||
1 | [email protected] | ||
2 | [email protected] | ||
3 | [email protected] "fn" | ||
4 | [email protected] " " | ||
5 | [email protected] | ||
6 | [email protected] "main" | ||
7 | [email protected] | ||
8 | [email protected] "(" | ||
9 | [email protected] ")" | ||
10 | [email protected] " " | ||
11 | [email protected] | ||
12 | [email protected] "{" | ||
13 | [email protected] "\n " | ||
14 | [email protected] | ||
15 | [email protected] "let" | ||
16 | [email protected] " " | ||
17 | [email protected] | ||
18 | [email protected] "const" | ||
19 | [email protected] " " | ||
20 | [email protected] | ||
21 | [email protected] "{" | ||
22 | [email protected] " " | ||
23 | [email protected] | ||
24 | [email protected] "15" | ||
25 | [email protected] " " | ||
26 | [email protected] "}" | ||
27 | [email protected] " " | ||
28 | [email protected] "=" | ||
29 | [email protected] " " | ||
30 | [email protected] | ||
31 | [email protected] "(" | ||
32 | [email protected] ")" | ||
33 | [email protected] ";" | ||
34 | [email protected] "\n " | ||
35 | [email protected] | ||
36 | [email protected] "let" | ||
37 | [email protected] " " | ||
38 | [email protected] | ||
39 | [email protected] "const" | ||
40 | [email protected] " " | ||
41 | [email protected] | ||
42 | [email protected] "{" | ||
43 | [email protected] " " | ||
44 | [email protected] | ||
45 | [email protected] | ||
46 | [email protected] | ||
47 | [email protected] | ||
48 | [email protected] | ||
49 | [email protected] | ||
50 | [email protected] "foo" | ||
51 | [email protected] | ||
52 | [email protected] "(" | ||
53 | [email protected] ")" | ||
54 | [email protected] ";" | ||
55 | [email protected] " " | ||
56 | [email protected] | ||
57 | [email protected] | ||
58 | [email protected] | ||
59 | [email protected] | ||
60 | [email protected] | ||
61 | [email protected] "bar" | ||
62 | [email protected] | ||
63 | [email protected] "(" | ||
64 | [email protected] ")" | ||
65 | [email protected] " " | ||
66 | [email protected] "}" | ||
67 | [email protected] " " | ||
68 | [email protected] "=" | ||
69 | [email protected] " " | ||
70 | [email protected] | ||
71 | [email protected] "(" | ||
72 | [email protected] ")" | ||
73 | [email protected] ";" | ||
74 | [email protected] "\n" | ||
75 | [email protected] "}" | ||
76 | [email protected] "\n" | ||
diff --git a/crates/syntax/test_data/parser/inline/ok/0156_const_block_pat.rs b/crates/syntax/test_data/parser/inline/ok/0156_const_block_pat.rs new file mode 100644 index 000000000..dce9defac --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0156_const_block_pat.rs | |||
@@ -0,0 +1,4 @@ | |||
1 | fn main() { | ||
2 | let const { 15 } = (); | ||
3 | let const { foo(); bar() } = (); | ||
4 | } | ||