Merge pull request #19643 from ChayimFriedman2/generic-const-items

feat: Parse generic consts
This commit is contained in:
Lukas Wirth 2025-04-21 12:17:08 +00:00 committed by GitHub
commit e3f7d18458
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 305 additions and 3 deletions

View file

@ -287,8 +287,9 @@ VariantDef =
Const =
Attr* Visibility?
'default'?
'const' (Name | '_') ':' Type
('=' body:Expr)? ';'
'const' (Name | '_') GenericParamList? ':' Type
('=' body:Expr)?
WhereClause? ';'
Static =
Attr* Visibility?

View file

@ -405,6 +405,7 @@ pub struct Const {
}
impl ast::HasAttrs for Const {}
impl ast::HasDocComments for Const {}
impl ast::HasGenericParams for Const {}
impl ast::HasName for Const {}
impl ast::HasVisibility for Const {}
impl Const {
@ -9423,7 +9424,7 @@ impl ast::HasGenericParams for AnyHasGenericParams {}
impl AstNode for AnyHasGenericParams {
#[inline]
fn can_cast(kind: SyntaxKind) -> bool {
matches!(kind, ENUM | FN | IMPL | STRUCT | TRAIT | TRAIT_ALIAS | TYPE_ALIAS | UNION)
matches!(kind, CONST | ENUM | FN | IMPL | STRUCT | TRAIT | TRAIT_ALIAS | TYPE_ALIAS | UNION)
}
#[inline]
fn cast(syntax: SyntaxNode) -> Option<Self> {
@ -9447,6 +9448,10 @@ impl fmt::Debug for AnyHasGenericParams {
f.debug_struct("AnyHasGenericParams").field("syntax", &self.syntax).finish()
}
}
impl From<Const> for AnyHasGenericParams {
#[inline]
fn from(node: Const) -> AnyHasGenericParams { AnyHasGenericParams { syntax: node.syntax } }
}
impl From<Enum> for AnyHasGenericParams {
#[inline]
fn from(node: Enum) -> AnyHasGenericParams { AnyHasGenericParams { syntax: node.syntax } }