diff options
Diffstat (limited to 'crates')
5 files changed, 142 insertions, 1 deletions
diff --git a/crates/ra_parser/src/grammar/expressions/atom.rs b/crates/ra_parser/src/grammar/expressions/atom.rs index 401c738a3..bc942ae01 100644 --- a/crates/ra_parser/src/grammar/expressions/atom.rs +++ b/crates/ra_parser/src/grammar/expressions/atom.rs | |||
@@ -110,7 +110,19 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar | |||
110 | p.bump(); | 110 | p.bump(); |
111 | block_expr(p, Some(m)) | 111 | block_expr(p, Some(m)) |
112 | } | 112 | } |
113 | T!['{'] => block_expr(p, None), | 113 | T!['{'] => { |
114 | // test for_range_from | ||
115 | // fn foo() { | ||
116 | // for x in 0 .. { | ||
117 | // break; | ||
118 | // } | ||
119 | // } | ||
120 | if r.forbid_structs { | ||
121 | return None; | ||
122 | } else { | ||
123 | block_expr(p, None) | ||
124 | } | ||
125 | } | ||
114 | T![return] => return_expr(p), | 126 | T![return] => return_expr(p), |
115 | T![continue] => continue_expr(p), | 127 | T![continue] => continue_expr(p), |
116 | T![break] => break_expr(p, r), | 128 | T![break] => break_expr(p, r), |
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0142_for_range_from.rs b/crates/ra_syntax/test_data/parser/inline/ok/0142_for_range_from.rs new file mode 100644 index 000000000..af0d40a7a --- /dev/null +++ b/crates/ra_syntax/test_data/parser/inline/ok/0142_for_range_from.rs | |||
@@ -0,0 +1,5 @@ | |||
1 | fn foo() { | ||
2 | for x in 0 .. { | ||
3 | break; | ||
4 | } | ||
5 | } | ||
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0142_for_range_from.txt b/crates/ra_syntax/test_data/parser/inline/ok/0142_for_range_from.txt new file mode 100644 index 000000000..9e5836233 --- /dev/null +++ b/crates/ra_syntax/test_data/parser/inline/ok/0142_for_range_from.txt | |||
@@ -0,0 +1,40 @@ | |||
1 | SOURCE_FILE@[0; 51) | ||
2 | FN_DEF@[0; 50) | ||
3 | FN_KW@[0; 2) "fn" | ||
4 | WHITESPACE@[2; 3) " " | ||
5 | NAME@[3; 6) | ||
6 | IDENT@[3; 6) "foo" | ||
7 | PARAM_LIST@[6; 8) | ||
8 | L_PAREN@[6; 7) "(" | ||
9 | R_PAREN@[7; 8) ")" | ||
10 | WHITESPACE@[8; 9) " " | ||
11 | BLOCK@[9; 50) | ||
12 | L_CURLY@[9; 10) "{" | ||
13 | WHITESPACE@[10; 14) "\n " | ||
14 | FOR_EXPR@[14; 48) | ||
15 | FOR_KW@[14; 17) "for" | ||
16 | WHITESPACE@[17; 18) " " | ||
17 | BIND_PAT@[18; 19) | ||
18 | NAME@[18; 19) | ||
19 | IDENT@[18; 19) "x" | ||
20 | WHITESPACE@[19; 20) " " | ||
21 | IN_KW@[20; 22) "in" | ||
22 | WHITESPACE@[22; 23) " " | ||
23 | RANGE_EXPR@[23; 27) | ||
24 | LITERAL@[23; 24) | ||
25 | INT_NUMBER@[23; 24) "0" | ||
26 | WHITESPACE@[24; 25) " " | ||
27 | DOTDOT@[25; 27) ".." | ||
28 | WHITESPACE@[27; 28) " " | ||
29 | BLOCK@[28; 48) | ||
30 | L_CURLY@[28; 29) "{" | ||
31 | WHITESPACE@[29; 37) "\n " | ||
32 | EXPR_STMT@[37; 43) | ||
33 | BREAK_EXPR@[37; 42) | ||
34 | BREAK_KW@[37; 42) "break" | ||
35 | SEMI@[42; 43) ";" | ||
36 | WHITESPACE@[43; 47) "\n " | ||
37 | R_CURLY@[47; 48) "}" | ||
38 | WHITESPACE@[48; 49) "\n" | ||
39 | R_CURLY@[49; 50) "}" | ||
40 | WHITESPACE@[50; 51) "\n" | ||
diff --git a/crates/ra_syntax/test_data/parser/ok/0052_for_range_block.rs b/crates/ra_syntax/test_data/parser/ok/0052_for_range_block.rs new file mode 100644 index 000000000..b51b19630 --- /dev/null +++ b/crates/ra_syntax/test_data/parser/ok/0052_for_range_block.rs | |||
@@ -0,0 +1,5 @@ | |||
1 | fn foo() { | ||
2 | for _x in 0 .. (0 .. {1 + 2}).sum::<u32>() { | ||
3 | break; | ||
4 | } | ||
5 | } | ||
diff --git a/crates/ra_syntax/test_data/parser/ok/0052_for_range_block.txt b/crates/ra_syntax/test_data/parser/ok/0052_for_range_block.txt new file mode 100644 index 000000000..858f042c6 --- /dev/null +++ b/crates/ra_syntax/test_data/parser/ok/0052_for_range_block.txt | |||
@@ -0,0 +1,79 @@ | |||
1 | SOURCE_FILE@[0; 80) | ||
2 | FN_DEF@[0; 79) | ||
3 | FN_KW@[0; 2) "fn" | ||
4 | WHITESPACE@[2; 3) " " | ||
5 | NAME@[3; 6) | ||
6 | IDENT@[3; 6) "foo" | ||
7 | PARAM_LIST@[6; 8) | ||
8 | L_PAREN@[6; 7) "(" | ||
9 | R_PAREN@[7; 8) ")" | ||
10 | WHITESPACE@[8; 9) " " | ||
11 | BLOCK@[9; 79) | ||
12 | L_CURLY@[9; 10) "{" | ||
13 | WHITESPACE@[10; 14) "\n " | ||
14 | FOR_EXPR@[14; 77) | ||
15 | FOR_KW@[14; 17) "for" | ||
16 | WHITESPACE@[17; 18) " " | ||
17 | BIND_PAT@[18; 20) | ||
18 | NAME@[18; 20) | ||
19 | IDENT@[18; 20) "_x" | ||
20 | WHITESPACE@[20; 21) " " | ||
21 | IN_KW@[21; 23) "in" | ||
22 | WHITESPACE@[23; 24) " " | ||
23 | RANGE_EXPR@[24; 56) | ||
24 | LITERAL@[24; 25) | ||
25 | INT_NUMBER@[24; 25) "0" | ||
26 | WHITESPACE@[25; 26) " " | ||
27 | DOTDOT@[26; 28) ".." | ||
28 | WHITESPACE@[28; 29) " " | ||
29 | METHOD_CALL_EXPR@[29; 56) | ||
30 | PAREN_EXPR@[29; 43) | ||
31 | L_PAREN@[29; 30) "(" | ||
32 | RANGE_EXPR@[30; 42) | ||
33 | LITERAL@[30; 31) | ||
34 | INT_NUMBER@[30; 31) "0" | ||
35 | WHITESPACE@[31; 32) " " | ||
36 | DOTDOT@[32; 34) ".." | ||
37 | WHITESPACE@[34; 35) " " | ||
38 | BLOCK_EXPR@[35; 42) | ||
39 | BLOCK@[35; 42) | ||
40 | L_CURLY@[35; 36) "{" | ||
41 | BIN_EXPR@[36; 41) | ||
42 | LITERAL@[36; 37) | ||
43 | INT_NUMBER@[36; 37) "1" | ||
44 | WHITESPACE@[37; 38) " " | ||
45 | PLUS@[38; 39) "+" | ||
46 | WHITESPACE@[39; 40) " " | ||
47 | LITERAL@[40; 41) | ||
48 | INT_NUMBER@[40; 41) "2" | ||
49 | R_CURLY@[41; 42) "}" | ||
50 | R_PAREN@[42; 43) ")" | ||
51 | DOT@[43; 44) "." | ||
52 | NAME_REF@[44; 47) | ||
53 | IDENT@[44; 47) "sum" | ||
54 | TYPE_ARG_LIST@[47; 54) | ||
55 | COLONCOLON@[47; 49) "::" | ||
56 | L_ANGLE@[49; 50) "<" | ||
57 | TYPE_ARG@[50; 53) | ||
58 | PATH_TYPE@[50; 53) | ||
59 | PATH@[50; 53) | ||
60 | PATH_SEGMENT@[50; 53) | ||
61 | NAME_REF@[50; 53) | ||
62 | IDENT@[50; 53) "u32" | ||
63 | R_ANGLE@[53; 54) ">" | ||
64 | ARG_LIST@[54; 56) | ||
65 | L_PAREN@[54; 55) "(" | ||
66 | R_PAREN@[55; 56) ")" | ||
67 | WHITESPACE@[56; 57) " " | ||
68 | BLOCK@[57; 77) | ||
69 | L_CURLY@[57; 58) "{" | ||
70 | WHITESPACE@[58; 66) "\n " | ||
71 | EXPR_STMT@[66; 72) | ||
72 | BREAK_EXPR@[66; 71) | ||
73 | BREAK_KW@[66; 71) "break" | ||
74 | SEMI@[71; 72) ";" | ||
75 | WHITESPACE@[72; 76) "\n " | ||
76 | R_CURLY@[76; 77) "}" | ||
77 | WHITESPACE@[77; 78) "\n" | ||
78 | R_CURLY@[78; 79) "}" | ||
79 | WHITESPACE@[79; 80) "\n" | ||