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:
Michael Chesser 2020-01-07 09:29:03 +10:30
parent c92a090f49
commit ce1b34fd59
9 changed files with 123 additions and 21 deletions

View file

@ -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,
}