mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Support let...else
This commit is contained in:
parent
4675410f07
commit
f8acae7895
13 changed files with 162 additions and 8 deletions
|
@ -722,9 +722,19 @@ impl LetStmt {
|
|||
pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
|
||||
pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
|
||||
pub fn initializer(&self) -> Option<Expr> { support::child(&self.syntax) }
|
||||
pub fn let_else(&self) -> Option<LetElse> { support::child(&self.syntax) }
|
||||
pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct LetElse {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
impl LetElse {
|
||||
pub fn else_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![else]) }
|
||||
pub fn block_expr(&self) -> Option<BlockExpr> { support::child(&self.syntax) }
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct ArrayExpr {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
|
@ -2304,6 +2314,17 @@ impl AstNode for LetStmt {
|
|||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
impl AstNode for LetElse {
|
||||
fn can_cast(kind: SyntaxKind) -> bool { kind == LET_ELSE }
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
impl AstNode for ArrayExpr {
|
||||
fn can_cast(kind: SyntaxKind) -> bool { kind == ARRAY_EXPR }
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
|
@ -4320,6 +4341,11 @@ impl std::fmt::Display for LetStmt {
|
|||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for LetElse {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for ArrayExpr {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(self.syntax(), f)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue