aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast/expr_extensions.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-05-02 00:18:19 +0100
committerAleksey Kladov <[email protected]>2020-05-02 10:21:39 +0100
commit4f2134cc33f07c09fe166cec42971828843bc0ef (patch)
tree0e2440d51717dd0dfcefbf77e5ef546f1ee5c60d /crates/ra_syntax/src/ast/expr_extensions.rs
parent3c96de5380a09fe06752ce146edeb017ae8c701c (diff)
Introduce EffectExpr
Diffstat (limited to 'crates/ra_syntax/src/ast/expr_extensions.rs')
-rw-r--r--crates/ra_syntax/src/ast/expr_extensions.rs40
1 files changed, 32 insertions, 8 deletions
diff --git a/crates/ra_syntax/src/ast/expr_extensions.rs b/crates/ra_syntax/src/ast/expr_extensions.rs
index ecf74fd36..7ee36e60c 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::EffectExpr(_) => true,
20 _ => false, 20 _ => false,
21 } 21 }
22 } 22 }
@@ -359,6 +359,33 @@ impl ast::Literal {
359 } 359 }
360} 360}
361 361
362#[derive(Debug, Clone, PartialEq, Eq)]
363pub enum Effect {
364 Async(SyntaxToken),
365 Unsafe(SyntaxToken),
366 Try(SyntaxToken),
367 // Very much not an effect, but we stuff it into this node anyway
368 Label(ast::Label),
369}
370
371impl ast::EffectExpr {
372 pub fn effect(&self) -> Effect {
373 if let Some(token) = self.async_token() {
374 return Effect::Async(token);
375 }
376 if let Some(token) = self.unsafe_token() {
377 return Effect::Unsafe(token);
378 }
379 if let Some(token) = self.try_token() {
380 return Effect::Try(token);
381 }
382 if let Some(label) = self.label() {
383 return Effect::Label(label);
384 }
385 unreachable!("ast::EffectExpr without Effect")
386 }
387}
388
362impl ast::BlockExpr { 389impl ast::BlockExpr {
363 /// false if the block is an intrinsic part of the syntax and can't be 390 /// false if the block is an intrinsic part of the syntax and can't be
364 /// replaced with arbitrary expression. 391 /// replaced with arbitrary expression.
@@ -368,15 +395,12 @@ impl ast::BlockExpr {
368 /// const FOO: () = { stand_alone }; 395 /// const FOO: () = { stand_alone };
369 /// ``` 396 /// ```
370 pub fn is_standalone(&self) -> bool { 397 pub fn is_standalone(&self) -> bool {
371 if self.unsafe_token().is_some() || self.async_token().is_some() { 398 let parent = match self.syntax().parent() {
372 return false; 399 Some(it) => it,
373 }
374 let kind = match self.syntax().parent() {
375 None => return true, 400 None => return true,
376 Some(it) => it.kind(),
377 }; 401 };
378 match kind { 402 match parent.kind() {
379 FN_DEF | IF_EXPR | WHILE_EXPR | LOOP_EXPR | TRY_BLOCK_EXPR => false, 403 FN_DEF | IF_EXPR | WHILE_EXPR | LOOP_EXPR | EFFECT_EXPR => false,
380 _ => true, 404 _ => true,
381 } 405 }
382 } 406 }