mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
Item is a Stmt
This commit is contained in:
parent
a7ca6583fb
commit
d4d986c7f8
6 changed files with 36 additions and 15 deletions
|
@ -17,14 +17,17 @@ impl AstNode for Stmt {
|
|||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
LET_STMT | EXPR_STMT => true,
|
||||
_ => false,
|
||||
_ => Item::can_cast(kind),
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
let res = match syntax.kind() {
|
||||
LET_STMT => Stmt::LetStmt(LetStmt { syntax }),
|
||||
EXPR_STMT => Stmt::ExprStmt(ExprStmt { syntax }),
|
||||
_ => return None,
|
||||
_ => {
|
||||
let item = Item::cast(syntax)?;
|
||||
Stmt::Item(item)
|
||||
}
|
||||
};
|
||||
Some(res)
|
||||
}
|
||||
|
@ -32,6 +35,7 @@ impl AstNode for Stmt {
|
|||
match self {
|
||||
Stmt::LetStmt(it) => &it.syntax,
|
||||
Stmt::ExprStmt(it) => &it.syntax,
|
||||
Stmt::Item(it) => it.syntax(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue