mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
Improve const generics parsing
- Handle const generics type args - Fix issue with const generic as first parameter in trait impl
This commit is contained in:
parent
c92a090f49
commit
ce1b34fd59
9 changed files with 123 additions and 21 deletions
|
@ -3114,6 +3114,9 @@ impl TypeArgList {
|
|||
pub fn assoc_type_args(&self) -> AstChildren<AssocTypeArg> {
|
||||
AstChildren::new(&self.syntax)
|
||||
}
|
||||
pub fn const_arg(&self) -> AstChildren<ConstArg> {
|
||||
AstChildren::new(&self.syntax)
|
||||
}
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct TypeArg {
|
||||
|
@ -3196,6 +3199,36 @@ impl AstNode for LifetimeArg {
|
|||
}
|
||||
impl LifetimeArg {}
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct ConstArg {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
impl AstNode for ConstArg {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
CONST_ARG => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
}
|
||||
impl ConstArg {
|
||||
pub fn literal(&self) -> Option<Literal> {
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
pub fn block_expr(&self) -> Option<BlockExpr> {
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct MacroItems {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue