mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
Introduce BlockModifier
This commit is contained in:
parent
292ba6a1f8
commit
1865dedadf
2 changed files with 19 additions and 2 deletions
|
@ -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,
|
||||||
|
|
|
@ -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() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue