mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-18 01:44:04 +00:00
Introduce BlockModifier
This commit is contained in:
parent
292ba6a1f8
commit
1865dedadf
@ -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,
|
||||
|
@ -359,7 +359,22 @@ impl ast::Literal {
|
||||
}
|
||||
}
|
||||
|
||||
pub enum BlockModifier {
|
||||
Async(SyntaxToken),
|
||||
Unsafe(SyntaxToken),
|
||||
}
|
||||
|
||||
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
|
||||
/// 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() {
|
||||
|
Loading…
Reference in New Issue
Block a user