Introduce BlockModifier

This commit is contained in:
Aleksey Kladov 2020-04-30 22:43:06 +02:00
parent 292ba6a1f8
commit 1865dedadf
2 changed files with 19 additions and 2 deletions

View file

@ -16,7 +16,9 @@ use crate::{
}; };
pub use self::{ pub use self::{
expr_extensions::{ArrayExprKind, BinOp, ElseBranch, LiteralKind, PrefixOp, RangeOp}, expr_extensions::{
ArrayExprKind, BinOp, BlockModifier, ElseBranch, LiteralKind, PrefixOp, RangeOp,
},
extensions::{ extensions::{
AttrKind, FieldKind, NameOrNameRef, PathSegmentKind, SelfParamKind, SlicePatComponents, AttrKind, FieldKind, NameOrNameRef, PathSegmentKind, SelfParamKind, SlicePatComponents,
StructKind, TypeBoundKind, VisibilityKind, StructKind, TypeBoundKind, VisibilityKind,

View file

@ -359,7 +359,22 @@ impl ast::Literal {
} }
} }
pub enum BlockModifier {
Async(SyntaxToken),
Unsafe(SyntaxToken),
}
impl ast::BlockExpr { impl ast::BlockExpr {
pub fn modifier(&self) -> Option<BlockModifier> {
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 /// false if the block is an intrinsic part of the syntax and can't be
/// replaced with arbitrary expression. /// replaced with arbitrary expression.
/// ///
@ -368,7 +383,7 @@ impl ast::BlockExpr {
/// const FOO: () = { stand_alone }; /// const FOO: () = { stand_alone };
/// ``` /// ```
pub fn is_standalone(&self) -> bool { pub fn is_standalone(&self) -> bool {
if self.unsafe_token().is_some() || self.async_token().is_some() { if self.modifier().is_some() {
return false; return false;
} }
let parent = match self.syntax().parent() { let parent = match self.syntax().parent() {