diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-05-02 10:57:45 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-05-02 10:57:45 +0100 |
commit | 75bc0249463b72971200e482d69dad88d4e76ae3 (patch) | |
tree | cf12a19a548f77af306bd8eeb4ba6a74175e1790 /crates/ra_syntax/src/ast/expr_extensions.rs | |
parent | 235728319fb545670e49db996e9c2cd94b8b34eb (diff) | |
parent | b73dbbfbf2cad646eb3f8e3342a1c390a874dc53 (diff) |
Merge #4257
4257: ast::EffectExpr r=matklad a=matklad
closes #4230
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src/ast/expr_extensions.rs')
-rw-r--r-- | crates/ra_syntax/src/ast/expr_extensions.rs | 40 |
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)] | ||
363 | pub 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 | |||
371 | impl 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 | |||
362 | impl ast::BlockExpr { | 389 | impl 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 | } |