Skip to content

Commit de93023

Browse files
author
zjy
committed
fixed #1384
1 parent 0129790 commit de93023

File tree

4 files changed

+90
-7
lines changed

4 files changed

+90
-7
lines changed

crates/ra_parser/src/grammar/expressions.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,17 @@ pub(crate) fn expr_block_contents(p: &mut Parser) {
181181
// fn foo(){
182182
// ;;;some_expr();;;;{;;;};;;;Ok(())
183183
// }
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+
184195
if p.current() == T![;] {
185196
p.bump();
186197
continue;

crates/ra_parser/src/grammar/items.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,15 @@ pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool, flavor: ItemF
3838
let m = p.start();
3939
attributes::outer_attributes(p);
4040
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+
}
4250
Err(m) => m,
4351
};
4452
if paths::is_path_start(p) {
@@ -263,12 +271,6 @@ fn items_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> {
263271
}
264272
_ => return Err(m),
265273
};
266-
if p.at(T![;]) {
267-
p.err_and_bump(
268-
"expected item, found `;`\n\
269-
consider removing this semicolon",
270-
);
271-
}
272274
Ok(())
273275
}
274276

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fn simple_function() {
2+
enum LocalEnum {
3+
One,
4+
Two,
5+
};
6+
fn f() {};
7+
struct S {};
8+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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"

0 commit comments

Comments
 (0)