aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_hir_def/src/body/lower.rs4
-rw-r--r--crates/ra_hir_def/src/expr.rs4
-rw-r--r--crates/ra_hir_ty/src/infer/expr.rs5
-rw-r--r--crates/ra_parser/src/grammar/expressions/atom.rs6
-rw-r--r--crates/ra_parser/src/syntax_kind/generated.rs1
-rw-r--r--crates/ra_syntax/src/ast.rs4
-rw-r--r--crates/ra_syntax/src/ast/expr_extensions.rs27
-rw-r--r--crates/ra_syntax/src/ast/generated/nodes.rs37
-rw-r--r--xtask/src/ast_src.rs5
9 files changed, 30 insertions, 63 deletions
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs
index 571603854..f467ed3fe 100644
--- a/crates/ra_hir_def/src/body/lower.rs
+++ b/crates/ra_hir_def/src/body/lower.rs
@@ -182,10 +182,6 @@ impl ExprCollector<'_> {
182 182
183 self.alloc_expr(Expr::If { condition, then_branch, else_branch }, syntax_ptr) 183 self.alloc_expr(Expr::If { condition, then_branch, else_branch }, syntax_ptr)
184 } 184 }
185 ast::Expr::TryBlockExpr(e) => {
186 let body = self.collect_block_opt(e.body());
187 self.alloc_expr(Expr::TryBlock { body }, syntax_ptr)
188 }
189 ast::Expr::BlockExpr(e) => self.collect_block(e), 185 ast::Expr::BlockExpr(e) => self.collect_block(e),
190 ast::Expr::LoopExpr(e) => { 186 ast::Expr::LoopExpr(e) => {
191 let body = self.collect_block_opt(e.loop_body()); 187 let body = self.collect_block_opt(e.loop_body());
diff --git a/crates/ra_hir_def/src/expr.rs b/crates/ra_hir_def/src/expr.rs
index a0cdad529..aad12e123 100644
--- a/crates/ra_hir_def/src/expr.rs
+++ b/crates/ra_hir_def/src/expr.rs
@@ -101,9 +101,6 @@ pub enum Expr {
101 Try { 101 Try {
102 expr: ExprId, 102 expr: ExprId,
103 }, 103 },
104 TryBlock {
105 body: ExprId,
106 },
107 Cast { 104 Cast {
108 expr: ExprId, 105 expr: ExprId,
109 type_ref: TypeRef, 106 type_ref: TypeRef,
@@ -239,7 +236,6 @@ impl Expr {
239 f(*expr); 236 f(*expr);
240 } 237 }
241 } 238 }
242 Expr::TryBlock { body } => f(*body),
243 Expr::Loop { body } => f(*body), 239 Expr::Loop { body } => f(*body),
244 Expr::While { condition, body } => { 240 Expr::While { condition, body } => {
245 f(*condition); 241 f(*condition);
diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs
index 83f946eee..efc60986b 100644
--- a/crates/ra_hir_ty/src/infer/expr.rs
+++ b/crates/ra_hir_ty/src/infer/expr.rs
@@ -73,11 +73,6 @@ impl<'a> InferenceContext<'a> {
73 self.coerce_merge_branch(&then_ty, &else_ty) 73 self.coerce_merge_branch(&then_ty, &else_ty)
74 } 74 }
75 Expr::Block { statements, tail } => self.infer_block(statements, *tail, expected), 75 Expr::Block { statements, tail } => self.infer_block(statements, *tail, expected),
76 Expr::TryBlock { body } => {
77 let _inner = self.infer_expr(*body, expected);
78 // FIXME should be std::result::Result<{inner}, _>
79 Ty::Unknown
80 }
81 Expr::Loop { body } => { 76 Expr::Loop { body } => {
82 self.infer_expr(*body, &Expectation::has_type(Ty::unit())); 77 self.infer_expr(*body, &Expectation::has_type(Ty::unit()));
83 // FIXME handle break with value 78 // FIXME handle break with value
diff --git a/crates/ra_parser/src/grammar/expressions/atom.rs b/crates/ra_parser/src/grammar/expressions/atom.rs
index 166dfc472..76aa601cb 100644
--- a/crates/ra_parser/src/grammar/expressions/atom.rs
+++ b/crates/ra_parser/src/grammar/expressions/atom.rs
@@ -84,7 +84,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar
84 T![box] => box_expr(p, None), 84 T![box] => box_expr(p, None),
85 T![for] => for_expr(p, None), 85 T![for] => for_expr(p, None),
86 T![while] => while_expr(p, None), 86 T![while] => while_expr(p, None),
87 T![try] => try_block_expr(p, None), 87 T![try] => try_expr(p, None),
88 LIFETIME if la == T![:] => { 88 LIFETIME if la == T![:] => {
89 let m = p.start(); 89 let m = p.start();
90 label(p); 90 label(p);
@@ -134,7 +134,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar
134 } 134 }
135 }; 135 };
136 let blocklike = match done.kind() { 136 let blocklike = match done.kind() {
137 IF_EXPR | WHILE_EXPR | FOR_EXPR | LOOP_EXPR | MATCH_EXPR | BLOCK_EXPR | TRY_BLOCK_EXPR => { 137 IF_EXPR | WHILE_EXPR | FOR_EXPR | LOOP_EXPR | MATCH_EXPR | BLOCK_EXPR | TRY_EXPR => {
138 BlockLike::Block 138 BlockLike::Block
139 } 139 }
140 _ => BlockLike::NotBlock, 140 _ => BlockLike::NotBlock,
@@ -532,7 +532,7 @@ fn break_expr(p: &mut Parser, r: Restrictions) -> CompletedMarker {
532// fn foo() { 532// fn foo() {
533// let _ = try {}; 533// let _ = try {};
534// } 534// }
535fn try_block_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker { 535fn try_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
536 assert!(p.at(T![try])); 536 assert!(p.at(T![try]));
537 let m = m.unwrap_or_else(|| p.start()); 537 let m = m.unwrap_or_else(|| p.start());
538 // Special-case `try!` as macro. 538 // Special-case `try!` as macro.
diff --git a/crates/ra_parser/src/syntax_kind/generated.rs b/crates/ra_parser/src/syntax_kind/generated.rs
index 524e7d784..ab727ed7e 100644
--- a/crates/ra_parser/src/syntax_kind/generated.rs
+++ b/crates/ra_parser/src/syntax_kind/generated.rs
@@ -191,7 +191,6 @@ pub enum SyntaxKind {
191 RECORD_LIT, 191 RECORD_LIT,
192 RECORD_FIELD_LIST, 192 RECORD_FIELD_LIST,
193 RECORD_FIELD, 193 RECORD_FIELD,
194 TRY_BLOCK_EXPR,
195 BOX_EXPR, 194 BOX_EXPR,
196 CALL_EXPR, 195 CALL_EXPR,
197 INDEX_EXPR, 196 INDEX_EXPR,
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs
index a716e525b..521ca8ab8 100644
--- a/crates/ra_syntax/src/ast.rs
+++ b/crates/ra_syntax/src/ast.rs
@@ -16,7 +16,9 @@ use crate::{
16}; 16};
17 17
18pub use self::{ 18pub use self::{
19 expr_extensions::{ArrayExprKind, BinOp, ElseBranch, LiteralKind, PrefixOp, RangeOp}, 19 expr_extensions::{
20 ArrayExprKind, BinOp, BlockModifier, ElseBranch, LiteralKind, PrefixOp, RangeOp,
21 },
20 extensions::{ 22 extensions::{
21 AttrKind, FieldKind, NameOrNameRef, PathSegmentKind, SelfParamKind, SlicePatComponents, 23 AttrKind, FieldKind, NameOrNameRef, PathSegmentKind, SelfParamKind, SlicePatComponents,
22 StructKind, TypeBoundKind, VisibilityKind, 24 StructKind, TypeBoundKind, VisibilityKind,
diff --git a/crates/ra_syntax/src/ast/expr_extensions.rs b/crates/ra_syntax/src/ast/expr_extensions.rs
index ecf74fd36..352c0d2c5 100644
--- a/crates/ra_syntax/src/ast/expr_extensions.rs
+++ b/crates/ra_syntax/src/ast/expr_extensions.rs
@@ -16,7 +16,7 @@ impl ast::Expr {
16 | ast::Expr::WhileExpr(_) 16 | ast::Expr::WhileExpr(_)
17 | ast::Expr::BlockExpr(_) 17 | ast::Expr::BlockExpr(_)
18 | ast::Expr::MatchExpr(_) 18 | ast::Expr::MatchExpr(_)
19 | ast::Expr::TryBlockExpr(_) => true, 19 | ast::Expr::TryExpr(_) => true,
20 _ => false, 20 _ => false,
21 } 21 }
22 } 22 }
@@ -359,7 +359,22 @@ impl ast::Literal {
359 } 359 }
360} 360}
361 361
362pub enum BlockModifier {
363 Async(SyntaxToken),
364 Unsafe(SyntaxToken),
365}
366
362impl ast::BlockExpr { 367impl ast::BlockExpr {
368 pub fn modifier(&self) -> Option<BlockModifier> {
369 if let Some(token) = self.async_token() {
370 return Some(BlockModifier::Async(token));
371 }
372 if let Some(token) = self.unsafe_token() {
373 return Some(BlockModifier::Unsafe(token));
374 }
375 None
376 }
377
363 /// false if the block is an intrinsic part of the syntax and can't be 378 /// false if the block is an intrinsic part of the syntax and can't be
364 /// replaced with arbitrary expression. 379 /// replaced with arbitrary expression.
365 /// 380 ///
@@ -368,15 +383,15 @@ impl ast::BlockExpr {
368 /// const FOO: () = { stand_alone }; 383 /// const FOO: () = { stand_alone };
369 /// ``` 384 /// ```
370 pub fn is_standalone(&self) -> bool { 385 pub fn is_standalone(&self) -> bool {
371 if self.unsafe_token().is_some() || self.async_token().is_some() { 386 if self.modifier().is_some() {
372 return false; 387 return false;
373 } 388 }
374 let kind = match self.syntax().parent() { 389 let parent = match self.syntax().parent() {
390 Some(it) => it,
375 None => return true, 391 None => return true,
376 Some(it) => it.kind(),
377 }; 392 };
378 match kind { 393 match parent.kind() {
379 FN_DEF | IF_EXPR | WHILE_EXPR | LOOP_EXPR | TRY_BLOCK_EXPR => false, 394 FN_DEF | IF_EXPR | WHILE_EXPR | LOOP_EXPR => false,
380 _ => true, 395 _ => true,
381 } 396 }
382 } 397 }
diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs
index d2253d4af..81260680f 100644
--- a/crates/ra_syntax/src/ast/generated/nodes.rs
+++ b/crates/ra_syntax/src/ast/generated/nodes.rs
@@ -476,16 +476,6 @@ impl LoopExpr {
476} 476}
477 477
478#[derive(Debug, Clone, PartialEq, Eq, Hash)] 478#[derive(Debug, Clone, PartialEq, Eq, Hash)]
479pub struct TryBlockExpr {
480 pub(crate) syntax: SyntaxNode,
481}
482impl ast::AttrsOwner for TryBlockExpr {}
483impl TryBlockExpr {
484 pub fn try_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![try]) }
485 pub fn body(&self) -> Option<BlockExpr> { support::child(&self.syntax) }
486}
487
488#[derive(Debug, Clone, PartialEq, Eq, Hash)]
489pub struct ForExpr { 479pub struct ForExpr {
490 pub(crate) syntax: SyntaxNode, 480 pub(crate) syntax: SyntaxNode,
491} 481}
@@ -1475,7 +1465,6 @@ pub enum Expr {
1475 FieldExpr(FieldExpr), 1465 FieldExpr(FieldExpr),
1476 AwaitExpr(AwaitExpr), 1466 AwaitExpr(AwaitExpr),
1477 TryExpr(TryExpr), 1467 TryExpr(TryExpr),
1478 TryBlockExpr(TryBlockExpr),
1479 CastExpr(CastExpr), 1468 CastExpr(CastExpr),
1480 RefExpr(RefExpr), 1469 RefExpr(RefExpr),
1481 PrefixExpr(PrefixExpr), 1470 PrefixExpr(PrefixExpr),
@@ -1958,17 +1947,6 @@ impl AstNode for LoopExpr {
1958 } 1947 }
1959 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1948 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1960} 1949}
1961impl AstNode for TryBlockExpr {
1962 fn can_cast(kind: SyntaxKind) -> bool { kind == TRY_BLOCK_EXPR }
1963 fn cast(syntax: SyntaxNode) -> Option<Self> {
1964 if Self::can_cast(syntax.kind()) {
1965 Some(Self { syntax })
1966 } else {
1967 None
1968 }
1969 }
1970 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1971}
1972impl AstNode for ForExpr { 1950impl AstNode for ForExpr {
1973 fn can_cast(kind: SyntaxKind) -> bool { kind == FOR_EXPR } 1951 fn can_cast(kind: SyntaxKind) -> bool { kind == FOR_EXPR }
1974 fn cast(syntax: SyntaxNode) -> Option<Self> { 1952 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -3310,9 +3288,6 @@ impl From<AwaitExpr> for Expr {
3310impl From<TryExpr> for Expr { 3288impl From<TryExpr> for Expr {
3311 fn from(node: TryExpr) -> Expr { Expr::TryExpr(node) } 3289 fn from(node: TryExpr) -> Expr { Expr::TryExpr(node) }
3312} 3290}
3313impl From<TryBlockExpr> for Expr {
3314 fn from(node: TryBlockExpr) -> Expr { Expr::TryBlockExpr(node) }
3315}
3316impl From<CastExpr> for Expr { 3291impl From<CastExpr> for Expr {
3317 fn from(node: CastExpr) -> Expr { Expr::CastExpr(node) } 3292 fn from(node: CastExpr) -> Expr { Expr::CastExpr(node) }
3318} 3293}
@@ -3343,9 +3318,8 @@ impl AstNode for Expr {
3343 TUPLE_EXPR | ARRAY_EXPR | PAREN_EXPR | PATH_EXPR | LAMBDA_EXPR | IF_EXPR 3318 TUPLE_EXPR | ARRAY_EXPR | PAREN_EXPR | PATH_EXPR | LAMBDA_EXPR | IF_EXPR
3344 | LOOP_EXPR | FOR_EXPR | WHILE_EXPR | CONTINUE_EXPR | BREAK_EXPR | LABEL 3319 | LOOP_EXPR | FOR_EXPR | WHILE_EXPR | CONTINUE_EXPR | BREAK_EXPR | LABEL
3345 | BLOCK_EXPR | RETURN_EXPR | MATCH_EXPR | RECORD_LIT | CALL_EXPR | INDEX_EXPR 3320 | BLOCK_EXPR | RETURN_EXPR | MATCH_EXPR | RECORD_LIT | CALL_EXPR | INDEX_EXPR
3346 | METHOD_CALL_EXPR | FIELD_EXPR | AWAIT_EXPR | TRY_EXPR | TRY_BLOCK_EXPR 3321 | METHOD_CALL_EXPR | FIELD_EXPR | AWAIT_EXPR | TRY_EXPR | CAST_EXPR | REF_EXPR
3347 | CAST_EXPR | REF_EXPR | PREFIX_EXPR | RANGE_EXPR | BIN_EXPR | LITERAL | MACRO_CALL 3322 | PREFIX_EXPR | RANGE_EXPR | BIN_EXPR | LITERAL | MACRO_CALL | BOX_EXPR => true,
3348 | BOX_EXPR => true,
3349 _ => false, 3323 _ => false,
3350 } 3324 }
3351 } 3325 }
@@ -3373,7 +3347,6 @@ impl AstNode for Expr {
3373 FIELD_EXPR => Expr::FieldExpr(FieldExpr { syntax }), 3347 FIELD_EXPR => Expr::FieldExpr(FieldExpr { syntax }),
3374 AWAIT_EXPR => Expr::AwaitExpr(AwaitExpr { syntax }), 3348 AWAIT_EXPR => Expr::AwaitExpr(AwaitExpr { syntax }),
3375 TRY_EXPR => Expr::TryExpr(TryExpr { syntax }), 3349 TRY_EXPR => Expr::TryExpr(TryExpr { syntax }),
3376 TRY_BLOCK_EXPR => Expr::TryBlockExpr(TryBlockExpr { syntax }),
3377 CAST_EXPR => Expr::CastExpr(CastExpr { syntax }), 3350 CAST_EXPR => Expr::CastExpr(CastExpr { syntax }),
3378 REF_EXPR => Expr::RefExpr(RefExpr { syntax }), 3351 REF_EXPR => Expr::RefExpr(RefExpr { syntax }),
3379 PREFIX_EXPR => Expr::PrefixExpr(PrefixExpr { syntax }), 3352 PREFIX_EXPR => Expr::PrefixExpr(PrefixExpr { syntax }),
@@ -3410,7 +3383,6 @@ impl AstNode for Expr {
3410 Expr::FieldExpr(it) => &it.syntax, 3383 Expr::FieldExpr(it) => &it.syntax,
3411 Expr::AwaitExpr(it) => &it.syntax, 3384 Expr::AwaitExpr(it) => &it.syntax,
3412 Expr::TryExpr(it) => &it.syntax, 3385 Expr::TryExpr(it) => &it.syntax,
3413 Expr::TryBlockExpr(it) => &it.syntax,
3414 Expr::CastExpr(it) => &it.syntax, 3386 Expr::CastExpr(it) => &it.syntax,
3415 Expr::RefExpr(it) => &it.syntax, 3387 Expr::RefExpr(it) => &it.syntax,
3416 Expr::PrefixExpr(it) => &it.syntax, 3388 Expr::PrefixExpr(it) => &it.syntax,
@@ -3891,11 +3863,6 @@ impl std::fmt::Display for LoopExpr {
3891 std::fmt::Display::fmt(self.syntax(), f) 3863 std::fmt::Display::fmt(self.syntax(), f)
3892 } 3864 }
3893} 3865}
3894impl std::fmt::Display for TryBlockExpr {
3895 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
3896 std::fmt::Display::fmt(self.syntax(), f)
3897 }
3898}
3899impl std::fmt::Display for ForExpr { 3866impl std::fmt::Display for ForExpr {
3900 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { 3867 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
3901 std::fmt::Display::fmt(self.syntax(), f) 3868 std::fmt::Display::fmt(self.syntax(), f)
diff --git a/xtask/src/ast_src.rs b/xtask/src/ast_src.rs
index c14804aad..bdd42cb76 100644
--- a/xtask/src/ast_src.rs
+++ b/xtask/src/ast_src.rs
@@ -162,7 +162,6 @@ pub(crate) const KINDS_SRC: KindsSrc = KindsSrc {
162 "RECORD_LIT", 162 "RECORD_LIT",
163 "RECORD_FIELD_LIST", 163 "RECORD_FIELD_LIST",
164 "RECORD_FIELD", 164 "RECORD_FIELD",
165 "TRY_BLOCK_EXPR",
166 "BOX_EXPR", 165 "BOX_EXPR",
167 // postfix 166 // postfix
168 "CALL_EXPR", 167 "CALL_EXPR",
@@ -440,7 +439,6 @@ pub(crate) const AST_SRC: AstSrc = AstSrc {
440 } 439 }
441 struct IfExpr: AttrsOwner { T![if], Condition } 440 struct IfExpr: AttrsOwner { T![if], Condition }
442 struct LoopExpr: AttrsOwner, LoopBodyOwner { T![loop] } 441 struct LoopExpr: AttrsOwner, LoopBodyOwner { T![loop] }
443 struct TryBlockExpr: AttrsOwner { T![try], body: BlockExpr }
444 struct ForExpr: AttrsOwner, LoopBodyOwner { 442 struct ForExpr: AttrsOwner, LoopBodyOwner {
445 T![for], 443 T![for],
446 Pat, 444 Pat,
@@ -451,7 +449,7 @@ pub(crate) const AST_SRC: AstSrc = AstSrc {
451 struct ContinueExpr: AttrsOwner { T![continue], T![lifetime] } 449 struct ContinueExpr: AttrsOwner { T![continue], T![lifetime] }
452 struct BreakExpr: AttrsOwner { T![break], T![lifetime], Expr } 450 struct BreakExpr: AttrsOwner { T![break], T![lifetime], Expr }
453 struct Label { T![lifetime] } 451 struct Label { T![lifetime] }
454 struct BlockExpr: AttrsOwner { Label, T![unsafe], T![async], Block } 452 struct BlockExpr: AttrsOwner { Label, T![unsafe], T![async], Block }
455 struct ReturnExpr: AttrsOwner { Expr } 453 struct ReturnExpr: AttrsOwner { Expr }
456 struct CallExpr: ArgListOwner { Expr } 454 struct CallExpr: ArgListOwner { Expr }
457 struct MethodCallExpr: AttrsOwner, ArgListOwner { 455 struct MethodCallExpr: AttrsOwner, ArgListOwner {
@@ -722,7 +720,6 @@ pub(crate) const AST_SRC: AstSrc = AstSrc {
722 FieldExpr, 720 FieldExpr,
723 AwaitExpr, 721 AwaitExpr,
724 TryExpr, 722 TryExpr,
725 TryBlockExpr,
726 CastExpr, 723 CastExpr,
727 RefExpr, 724 RefExpr,
728 PrefixExpr, 725 PrefixExpr,