diff options
author | bravomikekilo <[email protected]> | 2019-08-14 04:55:21 +0100 |
---|---|---|
committer | bravomikekilo <[email protected]> | 2019-08-14 04:55:21 +0100 |
commit | 2bebdf0b372b23c3766fc08b345012870ae768c9 (patch) | |
tree | 7d242e820b9757e8c9b49f81a0d8ae2d2ae0d5f1 | |
parent | 978e3e384b045ea72ba952e7f94a2a4c82297e66 (diff) |
fix error of RangeFrom in for-loop
3 files changed, 130 insertions, 1 deletions
diff --git a/crates/ra_parser/src/grammar/expressions/atom.rs b/crates/ra_parser/src/grammar/expressions/atom.rs index d98953a7e..6e25e3cb4 100644 --- a/crates/ra_parser/src/grammar/expressions/atom.rs +++ b/crates/ra_parser/src/grammar/expressions/atom.rs | |||
@@ -110,7 +110,13 @@ 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 | if r.forbid_structs { | ||
115 | return None; | ||
116 | } else { | ||
117 | block_expr(p, None) | ||
118 | } | ||
119 | } | ||
114 | T![return] => return_expr(p), | 120 | T![return] => return_expr(p), |
115 | T![continue] => continue_expr(p), | 121 | T![continue] => continue_expr(p), |
116 | T![break] => break_expr(p, r), | 122 | T![break] => break_expr(p, r), |
@@ -307,6 +313,16 @@ fn while_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker { | |||
307 | // fn foo() { | 313 | // fn foo() { |
308 | // for x in [] {}; | 314 | // for x in [] {}; |
309 | // } | 315 | // } |
316 | |||
317 | // test for_range_block | ||
318 | // fn foo() { | ||
319 | // for x in 0 .. { | ||
320 | // break; | ||
321 | // } | ||
322 | // for _x in 0 .. (0 .. {1 + 2}).sum::<u32>() { | ||
323 | // break; | ||
324 | // } | ||
325 | // } | ||
310 | fn for_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker { | 326 | fn for_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker { |
311 | assert!(p.at(T![for])); | 327 | assert!(p.at(T![for])); |
312 | let m = m.unwrap_or_else(|| p.start()); | 328 | let m = m.unwrap_or_else(|| p.start()); |
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0142_for_range_block.rs b/crates/ra_syntax/test_data/parser/inline/ok/0142_for_range_block.rs new file mode 100644 index 000000000..33af70026 --- /dev/null +++ b/crates/ra_syntax/test_data/parser/inline/ok/0142_for_range_block.rs | |||
@@ -0,0 +1,8 @@ | |||
1 | fn foo() { | ||
2 | for x in 0 .. { | ||
3 | break; | ||
4 | }; | ||
5 | for _x in 0 .. (0 .. {1 + 2}).sum::<u32>() { | ||
6 | break; | ||
7 | }; | ||
8 | } | ||
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0142_for_range_block.txt b/crates/ra_syntax/test_data/parser/inline/ok/0142_for_range_block.txt new file mode 100644 index 000000000..7da4dbb8b --- /dev/null +++ b/crates/ra_syntax/test_data/parser/inline/ok/0142_for_range_block.txt | |||
@@ -0,0 +1,105 @@ | |||
1 | SOURCE_FILE@[0; 118) | ||
2 | FN_DEF@[0; 117) | ||
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; 117) | ||
12 | L_CURLY@[9; 10) "{" | ||
13 | WHITESPACE@[10; 14) "\n " | ||
14 | EXPR_STMT@[14; 48) | ||
15 | FOR_EXPR@[14; 48) | ||
16 | FOR_KW@[14; 17) "for" | ||
17 | WHITESPACE@[17; 18) " " | ||
18 | BIND_PAT@[18; 19) | ||
19 | NAME@[18; 19) | ||
20 | IDENT@[18; 19) "x" | ||
21 | WHITESPACE@[19; 20) " " | ||
22 | IN_KW@[20; 22) "in" | ||
23 | WHITESPACE@[22; 23) " " | ||
24 | RANGE_EXPR@[23; 27) | ||
25 | LITERAL@[23; 24) | ||
26 | INT_NUMBER@[23; 24) "0" | ||
27 | WHITESPACE@[24; 25) " " | ||
28 | DOTDOT@[25; 27) ".." | ||
29 | WHITESPACE@[27; 28) " " | ||
30 | BLOCK@[28; 48) | ||
31 | L_CURLY@[28; 29) "{" | ||
32 | WHITESPACE@[29; 37) "\n " | ||
33 | EXPR_STMT@[37; 43) | ||
34 | BREAK_EXPR@[37; 42) | ||
35 | BREAK_KW@[37; 42) "break" | ||
36 | SEMI@[42; 43) ";" | ||
37 | WHITESPACE@[43; 47) "\n " | ||
38 | R_CURLY@[47; 48) "}" | ||
39 | WHITESPACE@[48; 52) "\n " | ||
40 | FOR_EXPR@[52; 115) | ||
41 | FOR_KW@[52; 55) "for" | ||
42 | WHITESPACE@[55; 56) " " | ||
43 | BIND_PAT@[56; 58) | ||
44 | NAME@[56; 58) | ||
45 | IDENT@[56; 58) "_x" | ||
46 | WHITESPACE@[58; 59) " " | ||
47 | IN_KW@[59; 61) "in" | ||
48 | WHITESPACE@[61; 62) " " | ||
49 | RANGE_EXPR@[62; 94) | ||
50 | LITERAL@[62; 63) | ||
51 | INT_NUMBER@[62; 63) "0" | ||
52 | WHITESPACE@[63; 64) " " | ||
53 | DOTDOT@[64; 66) ".." | ||
54 | WHITESPACE@[66; 67) " " | ||
55 | METHOD_CALL_EXPR@[67; 94) | ||
56 | PAREN_EXPR@[67; 81) | ||
57 | L_PAREN@[67; 68) "(" | ||
58 | RANGE_EXPR@[68; 80) | ||
59 | LITERAL@[68; 69) | ||
60 | INT_NUMBER@[68; 69) "0" | ||
61 | WHITESPACE@[69; 70) " " | ||
62 | DOTDOT@[70; 72) ".." | ||
63 | WHITESPACE@[72; 73) " " | ||
64 | BLOCK_EXPR@[73; 80) | ||
65 | BLOCK@[73; 80) | ||
66 | L_CURLY@[73; 74) "{" | ||
67 | BIN_EXPR@[74; 79) | ||
68 | LITERAL@[74; 75) | ||
69 | INT_NUMBER@[74; 75) "1" | ||
70 | WHITESPACE@[75; 76) " " | ||
71 | PLUS@[76; 77) "+" | ||
72 | WHITESPACE@[77; 78) " " | ||
73 | LITERAL@[78; 79) | ||
74 | INT_NUMBER@[78; 79) "2" | ||
75 | R_CURLY@[79; 80) "}" | ||
76 | R_PAREN@[80; 81) ")" | ||
77 | DOT@[81; 82) "." | ||
78 | NAME_REF@[82; 85) | ||
79 | IDENT@[82; 85) "sum" | ||
80 | TYPE_ARG_LIST@[85; 92) | ||
81 | COLONCOLON@[85; 87) "::" | ||
82 | L_ANGLE@[87; 88) "<" | ||
83 | TYPE_ARG@[88; 91) | ||
84 | PATH_TYPE@[88; 91) | ||
85 | PATH@[88; 91) | ||
86 | PATH_SEGMENT@[88; 91) | ||
87 | NAME_REF@[88; 91) | ||
88 | IDENT@[88; 91) "u32" | ||
89 | R_ANGLE@[91; 92) ">" | ||
90 | ARG_LIST@[92; 94) | ||
91 | L_PAREN@[92; 93) "(" | ||
92 | R_PAREN@[93; 94) ")" | ||
93 | WHITESPACE@[94; 95) " " | ||
94 | BLOCK@[95; 115) | ||
95 | L_CURLY@[95; 96) "{" | ||
96 | WHITESPACE@[96; 104) "\n " | ||
97 | EXPR_STMT@[104; 110) | ||
98 | BREAK_EXPR@[104; 109) | ||
99 | BREAK_KW@[104; 109) "break" | ||
100 | SEMI@[109; 110) ";" | ||
101 | WHITESPACE@[110; 114) "\n " | ||
102 | R_CURLY@[114; 115) "}" | ||
103 | WHITESPACE@[115; 116) "\n" | ||
104 | R_CURLY@[116; 117) "}" | ||
105 | WHITESPACE@[117; 118) "\n" | ||