aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-06-06 13:58:28 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-06-06 13:58:28 +0100
commitba3148159974b4fa7a2e37ade3a79ba5eeb4e760 (patch)
treeb5b9eb1151c6fdbfcbeeaaf4dfd2b2db015a6266 /crates/ra_hir
parentb79e6294a68fd41f0a3dbd9eb907dfe99646d77e (diff)
parent505b8d873ffe422358bb4ff47dc82d6c76d0772e (diff)
Merge #1380
1380: [#1083] Try block syntax r=matklad a=andreytkachenko The `try` block syntax Co-authored-by: Andrey Tkachenko <[email protected]>
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/expr.rs10
-rw-r--r--crates/ra_hir/src/ty/infer.rs5
2 files changed, 14 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..6cc5dbc6f 100644
--- a/crates/ra_hir/src/ty/infer.rs
+++ b/crates/ra_hir/src/ty/infer.rs
@@ -946,6 +946,11 @@ 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 // FIXME should be std::result::Result<{inner}, _>
952 Ty::Unknown
953 }
949 Expr::Loop { body } => { 954 Expr::Loop { body } => {
950 self.infer_expr(*body, &Expectation::has_type(Ty::unit())); 955 self.infer_expr(*body, &Expectation::has_type(Ty::unit()));
951 // FIXME handle break with value 956 // FIXME handle break with value