From 1865dedadf02c0ecc71a039645ad832d33881d30 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Apr 2020 22:43:06 +0200 Subject: Introduce BlockModifier --- crates/ra_syntax/src/ast.rs | 4 +++- crates/ra_syntax/src/ast/expr_extensions.rs | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) (limited to 'crates') 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::{ }; pub use self::{ - expr_extensions::{ArrayExprKind, BinOp, ElseBranch, LiteralKind, PrefixOp, RangeOp}, + expr_extensions::{ + ArrayExprKind, BinOp, BlockModifier, ElseBranch, LiteralKind, PrefixOp, RangeOp, + }, extensions::{ AttrKind, FieldKind, NameOrNameRef, PathSegmentKind, SelfParamKind, SlicePatComponents, 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 { } } +pub enum BlockModifier { + Async(SyntaxToken), + Unsafe(SyntaxToken), +} + impl ast::BlockExpr { + pub fn modifier(&self) -> Option { + if let Some(token) = self.async_token() { + return Some(BlockModifier::Async(token)); + } + if let Some(token) = self.unsafe_token() { + return Some(BlockModifier::Unsafe(token)); + } + None + } + /// false if the block is an intrinsic part of the syntax and can't be /// replaced with arbitrary expression. /// @@ -368,7 +383,7 @@ impl ast::BlockExpr { /// const FOO: () = { stand_alone }; /// ``` pub fn is_standalone(&self) -> bool { - if self.unsafe_token().is_some() || self.async_token().is_some() { + if self.modifier().is_some() { return false; } let parent = match self.syntax().parent() { -- cgit v1.2.3