mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
Merge #2641
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:
commit
d33493d779
6 changed files with 71 additions and 0 deletions
|
@ -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,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue