10438: minor: Simplify r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
bors[bot] 2021-10-03 11:06:06 +00:00 committed by GitHub
commit ebe6c38a44
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 91 additions and 143 deletions

View file

@ -18,7 +18,7 @@ use crate::{
};
pub use self::{
expr_ext::{ArrayExprKind, BlockModifier, ElseBranch, LiteralKind},
expr_ext::{ArrayExprKind, BlockModifier, CallableExpr, ElseBranch, LiteralKind},
generated::{nodes::*, tokens::*},
node_ext::{
AttrKind, FieldKind, Macro, NameLike, NameOrNameRef, PathSegmentKind, SelfParamKind,

View file

@ -10,7 +10,7 @@ use crate::{
},
AstToken,
SyntaxKind::*,
SyntaxToken, T,
SyntaxNode, SyntaxToken, T,
};
impl ast::HasAttrs for ast::Expr {}
@ -312,3 +312,41 @@ impl ast::RecordExprField {
self.syntax().ancestors().find_map(ast::RecordExpr::cast).unwrap()
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum CallableExpr {
Call(ast::CallExpr),
MethodCall(ast::MethodCallExpr),
}
impl ast::HasAttrs for CallableExpr {}
impl ast::HasArgList for CallableExpr {}
impl AstNode for CallableExpr {
fn can_cast(kind: parser::SyntaxKind) -> bool
where
Self: Sized,
{
ast::CallExpr::can_cast(kind) || ast::MethodCallExpr::can_cast(kind)
}
fn cast(syntax: SyntaxNode) -> Option<Self>
where
Self: Sized,
{
if let Some(it) = ast::CallExpr::cast(syntax.clone()) {
Some(Self::Call(it))
} else if let Some(it) = ast::MethodCallExpr::cast(syntax.clone()) {
Some(Self::MethodCall(it))
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
match self {
Self::Call(it) => it.syntax(),
Self::MethodCall(it) => it.syntax(),
}
}
}