Skip to content

Commit 1865ded

Browse files
committed
Introduce BlockModifier
1 parent 292ba6a commit 1865ded

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

crates/ra_syntax/src/ast.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ use crate::{
1616
};
1717

1818
pub use self::{
19-
expr_extensions::{ArrayExprKind, BinOp, ElseBranch, LiteralKind, PrefixOp, RangeOp},
19+
expr_extensions::{
20+
ArrayExprKind, BinOp, BlockModifier, ElseBranch, LiteralKind, PrefixOp, RangeOp,
21+
},
2022
extensions::{
2123
AttrKind, FieldKind, NameOrNameRef, PathSegmentKind, SelfParamKind, SlicePatComponents,
2224
StructKind, TypeBoundKind, VisibilityKind,

crates/ra_syntax/src/ast/expr_extensions.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,22 @@ impl ast::Literal {
359359
}
360360
}
361361

362+
pub enum BlockModifier {
363+
Async(SyntaxToken),
364+
Unsafe(SyntaxToken),
365+
}
366+
362367
impl 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+
363378
/// false if the block is an intrinsic part of the syntax and can't be
364379
/// replaced with arbitrary expression.
365380
///
@@ -368,7 +383,7 @@ impl ast::BlockExpr {
368383
/// const FOO: () = { stand_alone };
369384
/// ```
370385
pub fn is_standalone(&self) -> bool {
371-
if self.unsafe_token().is_some() || self.async_token().is_some() {
386+
if self.modifier().is_some() {
372387
return false;
373388
}
374389
let parent = match self.syntax().parent() {

0 commit comments

Comments
 (0)