diff options
Diffstat (limited to 'crates/ra_syntax')
6 files changed, 90 insertions, 2 deletions
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index c2e89de15..0376c91c8 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs | |||
@@ -513,7 +513,11 @@ impl ast::TypeParamsOwner for ConstDef {} | |||
513 | impl ast::AttrsOwner for ConstDef {} | 513 | impl ast::AttrsOwner for ConstDef {} |
514 | impl ast::DocCommentsOwner for ConstDef {} | 514 | impl ast::DocCommentsOwner for ConstDef {} |
515 | impl ast::TypeAscriptionOwner for ConstDef {} | 515 | impl ast::TypeAscriptionOwner for ConstDef {} |
516 | impl ConstDef {} | 516 | impl ConstDef { |
517 | pub fn body(&self) -> Option<&Expr> { | ||
518 | super::child_opt(self) | ||
519 | } | ||
520 | } | ||
517 | 521 | ||
518 | // ContinueExpr | 522 | // ContinueExpr |
519 | #[derive(Debug, PartialEq, Eq, Hash)] | 523 | #[derive(Debug, PartialEq, Eq, Hash)] |
@@ -3364,7 +3368,11 @@ impl ast::TypeParamsOwner for StaticDef {} | |||
3364 | impl ast::AttrsOwner for StaticDef {} | 3368 | impl ast::AttrsOwner for StaticDef {} |
3365 | impl ast::DocCommentsOwner for StaticDef {} | 3369 | impl ast::DocCommentsOwner for StaticDef {} |
3366 | impl ast::TypeAscriptionOwner for StaticDef {} | 3370 | impl ast::TypeAscriptionOwner for StaticDef {} |
3367 | impl StaticDef {} | 3371 | impl StaticDef { |
3372 | pub fn body(&self) -> Option<&Expr> { | ||
3373 | super::child_opt(self) | ||
3374 | } | ||
3375 | } | ||
3368 | 3376 | ||
3369 | // Stmt | 3377 | // Stmt |
3370 | #[derive(Debug, PartialEq, Eq, Hash)] | 3378 | #[derive(Debug, PartialEq, Eq, Hash)] |
diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron index dc0de5808..0a35e25d5 100644 --- a/crates/ra_syntax/src/grammar.ron +++ b/crates/ra_syntax/src/grammar.ron | |||
@@ -315,6 +315,7 @@ Grammar( | |||
315 | "DocCommentsOwner", | 315 | "DocCommentsOwner", |
316 | "TypeAscriptionOwner", | 316 | "TypeAscriptionOwner", |
317 | ], | 317 | ], |
318 | options: [ ["body","Expr"]], | ||
318 | ), | 319 | ), |
319 | "StaticDef": ( | 320 | "StaticDef": ( |
320 | traits: [ | 321 | traits: [ |
@@ -325,6 +326,7 @@ Grammar( | |||
325 | "DocCommentsOwner", | 326 | "DocCommentsOwner", |
326 | "TypeAscriptionOwner", | 327 | "TypeAscriptionOwner", |
327 | ], | 328 | ], |
329 | options: [ ["body","Expr"]], | ||
328 | ), | 330 | ), |
329 | "TypeAliasDef": ( | 331 | "TypeAliasDef": ( |
330 | traits: [ | 332 | traits: [ |
diff --git a/crates/ra_syntax/tests/data/parser/inline/err/0010_wrong_order_fns.rs b/crates/ra_syntax/tests/data/parser/inline/err/0010_wrong_order_fns.rs new file mode 100644 index 000000000..16edee95d --- /dev/null +++ b/crates/ra_syntax/tests/data/parser/inline/err/0010_wrong_order_fns.rs | |||
@@ -0,0 +1,2 @@ | |||
1 | async unsafe fn foo() {} | ||
2 | unsafe const fn bar() {} | ||
diff --git a/crates/ra_syntax/tests/data/parser/inline/err/0010_wrong_order_fns.txt b/crates/ra_syntax/tests/data/parser/inline/err/0010_wrong_order_fns.txt new file mode 100644 index 000000000..220191ffa --- /dev/null +++ b/crates/ra_syntax/tests/data/parser/inline/err/0010_wrong_order_fns.txt | |||
@@ -0,0 +1,39 @@ | |||
1 | SOURCE_FILE@[0; 50) | ||
2 | ERROR@[0; 5) | ||
3 | ASYNC_KW@[0; 5) "async" | ||
4 | err: `expected fn, trait or impl` | ||
5 | WHITESPACE@[5; 6) " " | ||
6 | FN_DEF@[6; 24) | ||
7 | UNSAFE_KW@[6; 12) "unsafe" | ||
8 | WHITESPACE@[12; 13) " " | ||
9 | FN_KW@[13; 15) "fn" | ||
10 | WHITESPACE@[15; 16) " " | ||
11 | NAME@[16; 19) | ||
12 | IDENT@[16; 19) "foo" | ||
13 | PARAM_LIST@[19; 21) | ||
14 | L_PAREN@[19; 20) "(" | ||
15 | R_PAREN@[20; 21) ")" | ||
16 | WHITESPACE@[21; 22) " " | ||
17 | BLOCK@[22; 24) | ||
18 | L_CURLY@[22; 23) "{" | ||
19 | R_CURLY@[23; 24) "}" | ||
20 | WHITESPACE@[24; 25) "\n" | ||
21 | ERROR@[25; 31) | ||
22 | UNSAFE_KW@[25; 31) "unsafe" | ||
23 | err: `expected fn, trait or impl` | ||
24 | WHITESPACE@[31; 32) " " | ||
25 | FN_DEF@[32; 49) | ||
26 | CONST_KW@[32; 37) "const" | ||
27 | WHITESPACE@[37; 38) " " | ||
28 | FN_KW@[38; 40) "fn" | ||
29 | WHITESPACE@[40; 41) " " | ||
30 | NAME@[41; 44) | ||
31 | IDENT@[41; 44) "bar" | ||
32 | PARAM_LIST@[44; 46) | ||
33 | L_PAREN@[44; 45) "(" | ||
34 | R_PAREN@[45; 46) ")" | ||
35 | WHITESPACE@[46; 47) " " | ||
36 | BLOCK@[47; 49) | ||
37 | L_CURLY@[47; 48) "{" | ||
38 | R_CURLY@[48; 49) "}" | ||
39 | WHITESPACE@[49; 50) "\n" | ||
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0128_combined_fns.rs b/crates/ra_syntax/tests/data/parser/inline/ok/0128_combined_fns.rs new file mode 100644 index 000000000..46af91b82 --- /dev/null +++ b/crates/ra_syntax/tests/data/parser/inline/ok/0128_combined_fns.rs | |||
@@ -0,0 +1,2 @@ | |||
1 | unsafe async fn foo() {} | ||
2 | const unsafe fn bar() {} | ||
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0128_combined_fns.txt b/crates/ra_syntax/tests/data/parser/inline/ok/0128_combined_fns.txt new file mode 100644 index 000000000..2a16aeb61 --- /dev/null +++ b/crates/ra_syntax/tests/data/parser/inline/ok/0128_combined_fns.txt | |||
@@ -0,0 +1,35 @@ | |||
1 | SOURCE_FILE@[0; 50) | ||
2 | FN_DEF@[0; 24) | ||
3 | UNSAFE_KW@[0; 6) "unsafe" | ||
4 | WHITESPACE@[6; 7) " " | ||
5 | ASYNC_KW@[7; 12) "async" | ||
6 | WHITESPACE@[12; 13) " " | ||
7 | FN_KW@[13; 15) "fn" | ||
8 | WHITESPACE@[15; 16) " " | ||
9 | NAME@[16; 19) | ||
10 | IDENT@[16; 19) "foo" | ||
11 | PARAM_LIST@[19; 21) | ||
12 | L_PAREN@[19; 20) "(" | ||
13 | R_PAREN@[20; 21) ")" | ||
14 | WHITESPACE@[21; 22) " " | ||
15 | BLOCK@[22; 24) | ||
16 | L_CURLY@[22; 23) "{" | ||
17 | R_CURLY@[23; 24) "}" | ||
18 | WHITESPACE@[24; 25) "\n" | ||
19 | FN_DEF@[25; 49) | ||
20 | CONST_KW@[25; 30) "const" | ||
21 | WHITESPACE@[30; 31) " " | ||
22 | UNSAFE_KW@[31; 37) "unsafe" | ||
23 | WHITESPACE@[37; 38) " " | ||
24 | FN_KW@[38; 40) "fn" | ||
25 | WHITESPACE@[40; 41) " " | ||
26 | NAME@[41; 44) | ||
27 | IDENT@[41; 44) "bar" | ||
28 | PARAM_LIST@[44; 46) | ||
29 | L_PAREN@[44; 45) "(" | ||
30 | R_PAREN@[45; 46) ")" | ||
31 | WHITESPACE@[46; 47) " " | ||
32 | BLOCK@[47; 49) | ||
33 | L_CURLY@[47; 48) "{" | ||
34 | R_CURLY@[48; 49) "}" | ||
35 | WHITESPACE@[49; 50) "\n" | ||