2641: Parse const generics r=matklad a=roblabla

Adds very primitive support for parsing const generics (`const IDENT: TY`) so that rust-analyzer stops complaining about the syntax being invalid.

Fixes #1574
Fixes #2281 

Co-authored-by: roblabla <unfiltered@roblab.la>
This commit is contained in:
bors[bot] 2019-12-22 07:56:33 +00:00 committed by GitHub
commit d33493d779
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 71 additions and 0 deletions

View file

@ -551,6 +551,36 @@ impl ConstDef {
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ConstParam {
pub(crate) syntax: SyntaxNode,
}
impl AstNode for ConstParam {
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
CONST_PARAM => 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 ast::NameOwner for ConstParam {}
impl ast::AttrsOwner for ConstParam {}
impl ast::TypeAscriptionOwner for ConstParam {}
impl ConstParam {
pub fn default_val(&self) -> Option<Expr> {
AstChildren::new(&self.syntax).next()
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ContinueExpr {
pub(crate) syntax: SyntaxNode,
}