diff options
4 files changed, 90 insertions, 7 deletions
diff --git a/crates/ra_parser/src/grammar/expressions.rs b/crates/ra_parser/src/grammar/expressions.rs index 795dccea1..298030cb9 100644 --- a/crates/ra_parser/src/grammar/expressions.rs +++ b/crates/ra_parser/src/grammar/expressions.rs | |||
@@ -181,6 +181,17 @@ pub(crate) fn expr_block_contents(p: &mut Parser) { | |||
181 | // fn foo(){ | 181 | // fn foo(){ |
182 | // ;;;some_expr();;;;{;;;};;;;Ok(()) | 182 | // ;;;some_expr();;;;{;;;};;;;Ok(()) |
183 | // } | 183 | // } |
184 | |||
185 | // test nocontentexpr_after_item | ||
186 | // fn simple_function() { | ||
187 | // enum LocalEnum { | ||
188 | // One, | ||
189 | // Two, | ||
190 | // }; | ||
191 | // fn f() {}; | ||
192 | // struct S {}; | ||
193 | // } | ||
194 | |||
184 | if p.current() == T![;] { | 195 | if p.current() == T![;] { |
185 | p.bump(); | 196 | p.bump(); |
186 | continue; | 197 | continue; |
diff --git a/crates/ra_parser/src/grammar/items.rs b/crates/ra_parser/src/grammar/items.rs index 424d0476d..543af7c4b 100644 --- a/crates/ra_parser/src/grammar/items.rs +++ b/crates/ra_parser/src/grammar/items.rs | |||
@@ -38,7 +38,15 @@ pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool, flavor: ItemF | |||
38 | let m = p.start(); | 38 | let m = p.start(); |
39 | attributes::outer_attributes(p); | 39 | attributes::outer_attributes(p); |
40 | let m = match maybe_item(p, m, flavor) { | 40 | let m = match maybe_item(p, m, flavor) { |
41 | Ok(()) => return, | 41 | Ok(()) => { |
42 | if p.at(T![;]) { | ||
43 | p.err_and_bump( | ||
44 | "expected item, found `;`\n\ | ||
45 | consider removing this semicolon", | ||
46 | ); | ||
47 | } | ||
48 | return; | ||
49 | } | ||
42 | Err(m) => m, | 50 | Err(m) => m, |
43 | }; | 51 | }; |
44 | if paths::is_path_start(p) { | 52 | if paths::is_path_start(p) { |
@@ -263,12 +271,6 @@ fn items_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> { | |||
263 | } | 271 | } |
264 | _ => return Err(m), | 272 | _ => return Err(m), |
265 | }; | 273 | }; |
266 | if p.at(T![;]) { | ||
267 | p.err_and_bump( | ||
268 | "expected item, found `;`\n\ | ||
269 | consider removing this semicolon", | ||
270 | ); | ||
271 | } | ||
272 | Ok(()) | 274 | Ok(()) |
273 | } | 275 | } |
274 | 276 | ||
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0134_nocontentexpr_after_item.rs b/crates/ra_syntax/tests/data/parser/inline/ok/0134_nocontentexpr_after_item.rs new file mode 100644 index 000000000..eadc7fffb --- /dev/null +++ b/crates/ra_syntax/tests/data/parser/inline/ok/0134_nocontentexpr_after_item.rs | |||
@@ -0,0 +1,8 @@ | |||
1 | fn simple_function() { | ||
2 | enum LocalEnum { | ||
3 | One, | ||
4 | Two, | ||
5 | }; | ||
6 | fn f() {}; | ||
7 | struct S {}; | ||
8 | } | ||
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0134_nocontentexpr_after_item.txt b/crates/ra_syntax/tests/data/parser/inline/ok/0134_nocontentexpr_after_item.txt new file mode 100644 index 000000000..50d3b5def --- /dev/null +++ b/crates/ra_syntax/tests/data/parser/inline/ok/0134_nocontentexpr_after_item.txt | |||
@@ -0,0 +1,62 @@ | |||
1 | SOURCE_FILE@[0; 111) | ||
2 | FN_DEF@[0; 110) | ||
3 | FN_KW@[0; 2) "fn" | ||
4 | WHITESPACE@[2; 3) " " | ||
5 | NAME@[3; 18) | ||
6 | IDENT@[3; 18) "simple_function" | ||
7 | PARAM_LIST@[18; 20) | ||
8 | L_PAREN@[18; 19) "(" | ||
9 | R_PAREN@[19; 20) ")" | ||
10 | WHITESPACE@[20; 21) " " | ||
11 | BLOCK@[21; 110) | ||
12 | L_CURLY@[21; 22) "{" | ||
13 | WHITESPACE@[22; 27) "\n " | ||
14 | ENUM_DEF@[27; 75) | ||
15 | ENUM_KW@[27; 31) "enum" | ||
16 | WHITESPACE@[31; 32) " " | ||
17 | NAME@[32; 41) | ||
18 | IDENT@[32; 41) "LocalEnum" | ||
19 | WHITESPACE@[41; 42) " " | ||
20 | ENUM_VARIANT_LIST@[42; 75) | ||
21 | L_CURLY@[42; 43) "{" | ||
22 | WHITESPACE@[43; 52) "\n " | ||
23 | ENUM_VARIANT@[52; 55) | ||
24 | NAME@[52; 55) | ||
25 | IDENT@[52; 55) "One" | ||
26 | COMMA@[55; 56) "," | ||
27 | WHITESPACE@[56; 65) "\n " | ||
28 | ENUM_VARIANT@[65; 68) | ||
29 | NAME@[65; 68) | ||
30 | IDENT@[65; 68) "Two" | ||
31 | COMMA@[68; 69) "," | ||
32 | WHITESPACE@[69; 74) "\n " | ||
33 | R_CURLY@[74; 75) "}" | ||
34 | SEMI@[75; 76) ";" | ||
35 | WHITESPACE@[76; 81) "\n " | ||
36 | FN_DEF@[81; 90) | ||
37 | FN_KW@[81; 83) "fn" | ||
38 | WHITESPACE@[83; 84) " " | ||
39 | NAME@[84; 85) | ||
40 | IDENT@[84; 85) "f" | ||
41 | PARAM_LIST@[85; 87) | ||
42 | L_PAREN@[85; 86) "(" | ||
43 | R_PAREN@[86; 87) ")" | ||
44 | WHITESPACE@[87; 88) " " | ||
45 | BLOCK@[88; 90) | ||
46 | L_CURLY@[88; 89) "{" | ||
47 | R_CURLY@[89; 90) "}" | ||
48 | SEMI@[90; 91) ";" | ||
49 | WHITESPACE@[91; 96) "\n " | ||
50 | STRUCT_DEF@[96; 107) | ||
51 | STRUCT_KW@[96; 102) "struct" | ||
52 | WHITESPACE@[102; 103) " " | ||
53 | NAME@[103; 104) | ||
54 | IDENT@[103; 104) "S" | ||
55 | WHITESPACE@[104; 105) " " | ||
56 | NAMED_FIELD_DEF_LIST@[105; 107) | ||
57 | L_CURLY@[105; 106) "{" | ||
58 | R_CURLY@[106; 107) "}" | ||
59 | SEMI@[107; 108) ";" | ||
60 | WHITESPACE@[108; 109) "\n" | ||
61 | R_CURLY@[109; 110) "}" | ||
62 | WHITESPACE@[110; 111) "\n" | ||