aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast/expr_extensions.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/ast/expr_extensions.rs')
-rw-r--r--crates/ra_syntax/src/ast/expr_extensions.rs27
1 files changed, 6 insertions, 21 deletions
diff --git a/crates/ra_syntax/src/ast/expr_extensions.rs b/crates/ra_syntax/src/ast/expr_extensions.rs
index 352c0d2c5..ecf74fd36 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::TryExpr(_) => true, 19 | ast::Expr::TryBlockExpr(_) => true,
20 _ => false, 20 _ => false,
21 } 21 }
22 } 22 }
@@ -359,22 +359,7 @@ impl ast::Literal {
359 } 359 }
360} 360}
361 361
362pub enum BlockModifier {
363 Async(SyntaxToken),
364 Unsafe(SyntaxToken),
365}
366
367impl ast::BlockExpr { 362impl 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
378 /// false if the block is an intrinsic part of the syntax and can't be 363 /// false if the block is an intrinsic part of the syntax and can't be
379 /// replaced with arbitrary expression. 364 /// replaced with arbitrary expression.
380 /// 365 ///
@@ -383,15 +368,15 @@ impl ast::BlockExpr {
383 /// const FOO: () = { stand_alone }; 368 /// const FOO: () = { stand_alone };
384 /// ``` 369 /// ```
385 pub fn is_standalone(&self) -> bool { 370 pub fn is_standalone(&self) -> bool {
386 if self.modifier().is_some() { 371 if self.unsafe_token().is_some() || self.async_token().is_some() {
387 return false; 372 return false;
388 } 373 }
389 let parent = match self.syntax().parent() { 374 let kind = match self.syntax().parent() {
390 Some(it) => it,
391 None => return true, 375 None => return true,
376 Some(it) => it.kind(),
392 }; 377 };
393 match parent.kind() { 378 match kind {
394 FN_DEF | IF_EXPR | WHILE_EXPR | LOOP_EXPR => false, 379 FN_DEF | IF_EXPR | WHILE_EXPR | LOOP_EXPR | TRY_BLOCK_EXPR => false,
395 _ => true, 380 _ => true,
396 } 381 }
397 } 382 }