diff options
author | Andrey Tkachenko <[email protected]> | 2019-06-06 13:26:54 +0100 |
---|---|---|
committer | Andrey Tkachenko <[email protected]> | 2019-06-06 13:26:54 +0100 |
commit | 505b8d873ffe422358bb4ff47dc82d6c76d0772e (patch) | |
tree | b5b9eb1151c6fdbfcbeeaaf4dfd2b2db015a6266 | |
parent | 281c9eeaff8eac4e666089f80f67cf684e1d001b (diff) |
[#1083] Try block syntax: fix tests
6 files changed, 41 insertions, 45 deletions
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index 579307d8a..6cc5dbc6f 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs | |||
@@ -948,7 +948,6 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
948 | Expr::Block { statements, tail } => self.infer_block(statements, *tail, expected), | 948 | Expr::Block { statements, tail } => self.infer_block(statements, *tail, expected), |
949 | Expr::TryBlock { body } => { | 949 | Expr::TryBlock { body } => { |
950 | let _inner = self.infer_expr(*body, expected); | 950 | let _inner = self.infer_expr(*body, expected); |
951 | |||
952 | // FIXME should be std::result::Result<{inner}, _> | 951 | // FIXME should be std::result::Result<{inner}, _> |
953 | Ty::Unknown | 952 | Ty::Unknown |
954 | } | 953 | } |
diff --git a/crates/ra_parser/src/grammar/expressions/atom.rs b/crates/ra_parser/src/grammar/expressions/atom.rs index 0df47d33d..725fb99f6 100644 --- a/crates/ra_parser/src/grammar/expressions/atom.rs +++ b/crates/ra_parser/src/grammar/expressions/atom.rs | |||
@@ -76,7 +76,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar | |||
76 | T![loop] => loop_expr(p, None), | 76 | T![loop] => loop_expr(p, None), |
77 | T![for] => for_expr(p, None), | 77 | T![for] => for_expr(p, None), |
78 | T![while] => while_expr(p, None), | 78 | T![while] => while_expr(p, None), |
79 | T![try] => try_expr(p, None), | 79 | T![try] => try_block_expr(p, None), |
80 | LIFETIME if la == T![:] => { | 80 | LIFETIME if la == T![:] => { |
81 | let m = p.start(); | 81 | let m = p.start(); |
82 | label(p); | 82 | label(p); |
@@ -118,7 +118,9 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar | |||
118 | } | 118 | } |
119 | }; | 119 | }; |
120 | let blocklike = match done.kind() { | 120 | let blocklike = match done.kind() { |
121 | IF_EXPR | WHILE_EXPR | FOR_EXPR | LOOP_EXPR | MATCH_EXPR | BLOCK_EXPR | TRY_BLOCK_EXPR => BlockLike::Block, | 121 | IF_EXPR | WHILE_EXPR | FOR_EXPR | LOOP_EXPR | MATCH_EXPR | BLOCK_EXPR | TRY_BLOCK_EXPR => { |
122 | BlockLike::Block | ||
123 | } | ||
122 | _ => BlockLike::NotBlock, | 124 | _ => BlockLike::NotBlock, |
123 | }; | 125 | }; |
124 | Some((done, blocklike)) | 126 | Some((done, blocklike)) |
@@ -494,13 +496,11 @@ fn break_expr(p: &mut Parser, r: Restrictions) -> CompletedMarker { | |||
494 | m.complete(p, BREAK_EXPR) | 496 | m.complete(p, BREAK_EXPR) |
495 | } | 497 | } |
496 | 498 | ||
497 | // test try_expr | 499 | // test try_block_expr |
498 | // fn foo() { | 500 | // fn foo() { |
499 | // try { | 501 | // let _ = try {}; |
500 | // | ||
501 | // } | ||
502 | // } | 502 | // } |
503 | fn try_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker { | 503 | fn try_block_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker { |
504 | assert!(p.at(T![try])); | 504 | assert!(p.at(T![try])); |
505 | let m = m.unwrap_or_else(|| p.start()); | 505 | let m = m.unwrap_or_else(|| p.start()); |
506 | p.bump(); | 506 | p.bump(); |
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0130_try_block_expr.rs b/crates/ra_syntax/tests/data/parser/inline/ok/0130_try_block_expr.rs new file mode 100644 index 000000000..0f1b41eb6 --- /dev/null +++ b/crates/ra_syntax/tests/data/parser/inline/ok/0130_try_block_expr.rs | |||
@@ -0,0 +1,3 @@ | |||
1 | fn foo() { | ||
2 | let _ = try {}; | ||
3 | } | ||
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0130_try_block_expr.txt b/crates/ra_syntax/tests/data/parser/inline/ok/0130_try_block_expr.txt new file mode 100644 index 000000000..53f49b9b5 --- /dev/null +++ b/crates/ra_syntax/tests/data/parser/inline/ok/0130_try_block_expr.txt | |||
@@ -0,0 +1,31 @@ | |||
1 | SOURCE_FILE@[0; 33) | ||
2 | FN_DEF@[0; 32) | ||
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; 32) | ||
12 | L_CURLY@[9; 10) "{" | ||
13 | WHITESPACE@[10; 15) "\n " | ||
14 | LET_STMT@[15; 30) | ||
15 | LET_KW@[15; 18) "let" | ||
16 | WHITESPACE@[18; 19) " " | ||
17 | PLACEHOLDER_PAT@[19; 20) | ||
18 | UNDERSCORE@[19; 20) "_" | ||
19 | WHITESPACE@[20; 21) " " | ||
20 | EQ@[21; 22) "=" | ||
21 | WHITESPACE@[22; 23) " " | ||
22 | TRY_EXPR@[23; 29) | ||
23 | TRY_KW@[23; 26) "try" | ||
24 | WHITESPACE@[26; 27) " " | ||
25 | BLOCK@[27; 29) | ||
26 | L_CURLY@[27; 28) "{" | ||
27 | R_CURLY@[28; 29) "}" | ||
28 | SEMI@[29; 30) ";" | ||
29 | WHITESPACE@[30; 31) "\n" | ||
30 | R_CURLY@[31; 32) "}" | ||
31 | WHITESPACE@[32; 33) "\n" | ||
diff --git a/crates/ra_syntax/tests/data/parser/ok/0051_try_block.rs b/crates/ra_syntax/tests/data/parser/ok/0051_try_block.rs deleted file mode 100644 index 8cc11ddcc..000000000 --- a/crates/ra_syntax/tests/data/parser/ok/0051_try_block.rs +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | fn main() { | ||
2 | let res = try { | ||
3 | |||
4 | }; | ||
5 | } | ||
diff --git a/crates/ra_syntax/tests/data/parser/ok/0051_try_block.txt b/crates/ra_syntax/tests/data/parser/ok/0051_try_block.txt deleted file mode 100644 index f94eb3bcd..000000000 --- a/crates/ra_syntax/tests/data/parser/ok/0051_try_block.txt +++ /dev/null | |||
@@ -1,32 +0,0 @@ | |||
1 | SOURCE_FILE@[0; 41) | ||
2 | FN_DEF@[0; 41) | ||
3 | FN_KW@[0; 2) "fn" | ||
4 | WHITESPACE@[2; 3) " " | ||
5 | NAME@[3; 7) | ||
6 | IDENT@[3; 7) "main" | ||
7 | PARAM_LIST@[7; 9) | ||
8 | L_PAREN@[7; 8) "(" | ||
9 | R_PAREN@[8; 9) ")" | ||
10 | WHITESPACE@[9; 10) " " | ||
11 | BLOCK@[10; 41) | ||
12 | L_CURLY@[10; 11) "{" | ||
13 | WHITESPACE@[11; 16) "\n " | ||
14 | LET_STMT@[16; 39) | ||
15 | LET_KW@[16; 19) "let" | ||
16 | WHITESPACE@[19; 20) " " | ||
17 | BIND_PAT@[20; 23) | ||
18 | NAME@[20; 23) | ||
19 | IDENT@[20; 23) "res" | ||
20 | WHITESPACE@[23; 24) " " | ||
21 | EQ@[24; 25) "=" | ||
22 | WHITESPACE@[25; 26) " " | ||
23 | TRY_EXPR@[26; 38) | ||
24 | TRY_KW@[26; 29) "try" | ||
25 | WHITESPACE@[29; 30) " " | ||
26 | BLOCK@[30; 38) | ||
27 | L_CURLY@[30; 31) "{" | ||
28 | WHITESPACE@[31; 37) "\n\n " | ||
29 | R_CURLY@[37; 38) "}" | ||
30 | SEMI@[38; 39) ";" | ||
31 | WHITESPACE@[39; 40) "\n" | ||
32 | R_CURLY@[40; 41) "}" \ No newline at end of file | ||