aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-04-30 21:43:06 +0100
committerAleksey Kladov <[email protected]>2020-04-30 21:58:26 +0100
commit1865dedadf02c0ecc71a039645ad832d33881d30 (patch)
treeabdb487e6f8a7968f49738833219384804064ef2 /crates/ra_syntax/src
parent292ba6a1f81fee4170c3081f74499fe8c3ddedd4 (diff)
Introduce BlockModifier
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r--crates/ra_syntax/src/ast.rs4
-rw-r--r--crates/ra_syntax/src/ast/expr_extensions.rs17
2 files changed, 19 insertions, 2 deletions
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 6aed7b4bb..352c0d2c5 100644
--- a/crates/ra_syntax/src/ast/expr_extensions.rs
+++ b/crates/ra_syntax/src/ast/expr_extensions.rs
@@ -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,7 +383,7 @@ 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 parent = match self.syntax().parent() { 389 let parent = match self.syntax().parent() {