aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
authorAndrey Tkachenko <[email protected]>2019-06-06 12:36:16 +0100
committerAndrey Tkachenko <[email protected]>2019-06-06 12:43:26 +0100
commit281c9eeaff8eac4e666089f80f67cf684e1d001b (patch)
treed5d315543cfc7aa47db24aafec3b98df3754ddb3 /crates/ra_hir/src
parentb79e6294a68fd41f0a3dbd9eb907dfe99646d77e (diff)
[#1083] Try block syntax
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/expr.rs10
-rw-r--r--crates/ra_hir/src/ty/infer.rs6
2 files changed, 15 insertions, 1 deletions
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs
index 51913d37b..9d9769859 100644
--- a/crates/ra_hir/src/expr.rs
+++ b/crates/ra_hir/src/expr.rs
@@ -6,7 +6,7 @@ use rustc_hash::FxHashMap;
6use ra_arena::{Arena, RawId, impl_arena_id, map::ArenaMap}; 6use ra_arena::{Arena, RawId, impl_arena_id, map::ArenaMap};
7use ra_syntax::{ 7use ra_syntax::{
8 SyntaxNodePtr, AstPtr, AstNode, 8 SyntaxNodePtr, AstPtr, AstNode,
9 ast::{self, LoopBodyOwner, ArgListOwner, NameOwner, LiteralKind,ArrayExprKind, TypeAscriptionOwner}, 9 ast::{self, TryBlockBodyOwner, LoopBodyOwner, ArgListOwner, NameOwner, LiteralKind,ArrayExprKind, TypeAscriptionOwner},
10}; 10};
11 11
12use crate::{ 12use crate::{
@@ -216,6 +216,9 @@ pub enum Expr {
216 Try { 216 Try {
217 expr: ExprId, 217 expr: ExprId,
218 }, 218 },
219 TryBlock {
220 body: ExprId,
221 },
219 Cast { 222 Cast {
220 expr: ExprId, 223 expr: ExprId,
221 type_ref: TypeRef, 224 type_ref: TypeRef,
@@ -299,6 +302,7 @@ impl Expr {
299 f(*expr); 302 f(*expr);
300 } 303 }
301 } 304 }
305 Expr::TryBlock { body } => f(*body),
302 Expr::Loop { body } => f(*body), 306 Expr::Loop { body } => f(*body),
303 Expr::While { condition, body } => { 307 Expr::While { condition, body } => {
304 f(*condition); 308 f(*condition);
@@ -578,6 +582,10 @@ where
578 self.alloc_expr(Expr::If { condition, then_branch, else_branch }, syntax_ptr) 582 self.alloc_expr(Expr::If { condition, then_branch, else_branch }, syntax_ptr)
579 } 583 }
580 } 584 }
585 ast::ExprKind::TryBlockExpr(e) => {
586 let body = self.collect_block_opt(e.try_body());
587 self.alloc_expr(Expr::TryBlock { body }, syntax_ptr)
588 }
581 ast::ExprKind::BlockExpr(e) => self.collect_block_opt(e.block()), 589 ast::ExprKind::BlockExpr(e) => self.collect_block_opt(e.block()),
582 ast::ExprKind::LoopExpr(e) => { 590 ast::ExprKind::LoopExpr(e) => {
583 let body = self.collect_block_opt(e.loop_body()); 591 let body = self.collect_block_opt(e.loop_body());
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs
index 905fe9f0e..579307d8a 100644
--- a/crates/ra_hir/src/ty/infer.rs
+++ b/crates/ra_hir/src/ty/infer.rs
@@ -946,6 +946,12 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
946 then_ty 946 then_ty
947 } 947 }
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 } => {
950 let _inner = self.infer_expr(*body, expected);
951
952 // FIXME should be std::result::Result<{inner}, _>
953 Ty::Unknown
954 }
949 Expr::Loop { body } => { 955 Expr::Loop { body } => {
950 self.infer_expr(*body, &Expectation::has_type(Ty::unit())); 956 self.infer_expr(*body, &Expectation::has_type(Ty::unit()));
951 // FIXME handle break with value 957 // FIXME handle break with value