mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 20:42:04 +00:00
refactor: leverage HasAttrs
for code brevity
This commit is contained in:
parent
2e7d2c2d04
commit
356d12eae4
3 changed files with 47 additions and 36 deletions
|
@ -680,6 +680,36 @@ impl TypeOrConstParam {
|
|||
}
|
||||
}
|
||||
|
||||
impl AstNode for TypeOrConstParam {
|
||||
fn can_cast(kind: SyntaxKind) -> bool
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
matches!(kind, SyntaxKind::TYPE_PARAM | SyntaxKind::CONST_PARAM)
|
||||
}
|
||||
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
let res = match syntax.kind() {
|
||||
SyntaxKind::TYPE_PARAM => TypeOrConstParam::Type(ast::TypeParam { syntax }),
|
||||
SyntaxKind::CONST_PARAM => TypeOrConstParam::Const(ast::ConstParam { syntax }),
|
||||
_ => return None,
|
||||
};
|
||||
Some(res)
|
||||
}
|
||||
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
match self {
|
||||
TypeOrConstParam::Type(it) => it.syntax(),
|
||||
TypeOrConstParam::Const(it) => it.syntax(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl HasAttrs for TypeOrConstParam {}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum TraitOrAlias {
|
||||
Trait(ast::Trait),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue