Skip to content

Commit 2dafeaf

Browse files
mchernyavskyyopox
authored andcommitted
PARSE: Parse Const Generics Defaults
1 parent ae15152 commit 2dafeaf

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

src/main/grammars/RustParser.bnf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ TypeParameter ::= OuterAttr* identifier TypeParamBounds? DefaultTypeParameterTyp
448448
}
449449
private DefaultTypeParameterType ::= '=' TypeReference { pin = 1 }
450450

451-
ConstParameter ::= OuterAttr* const identifier TypeAscription {
451+
ConstParameter ::= OuterAttr* const identifier TypeAscription DefaultConstParameter? {
452452
pin = 2
453453
implements = [ "org.rust.lang.core.psi.ext.RsGenericParameter"
454454
"org.rust.lang.core.psi.ext.RsOuterAttributeOwner" ]
@@ -457,6 +457,8 @@ ConstParameter ::= OuterAttr* const identifier TypeAscription {
457457
elementTypeFactory = "org.rust.lang.core.stubs.StubImplementationsKt.factory"
458458
}
459459

460+
private DefaultConstParameter ::= '=' BlockExpr { pin = 1 }
461+
460462
private TypeBounds ::= [ Polybound ('+' Polybound)* '+'? ]
461463

462464
TypeParamBounds ::= ':' TypeBounds {

src/main/kotlin/org/rust/lang/core/parser/RustParserDefinition.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,6 @@ class RustParserDefinition : ParserDefinition {
104104
/**
105105
* Should be increased after any change of parser rules
106106
*/
107-
const val PARSER_VERSION: Int = LEXER_VERSION + 29
107+
const val PARSER_VERSION: Int = LEXER_VERSION + 30
108108
}
109109
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
struct S<T, const N: i32, const M: &'static str>;
2-
fn foo<T, const N: i32, const M: &'static str>() {}
1+
struct S<T, const N: i32, const M: &'static str = { "" }>;
2+
fn foo<T, const N: i32, const M: &'static str = { "" }>() {}
33
fn main() { foo::<S<i32, 0, { x }>, -0, "">() }

src/test/resources/org/rust/lang/core/parser/fixtures/complete/const_generics.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ FILE
3434
RsBaseTypeImpl(BASE_TYPE)
3535
RsPathImpl(PATH)
3636
PsiElement(identifier)('str')
37+
PsiWhiteSpace(' ')
38+
PsiElement(=)('=')
39+
PsiWhiteSpace(' ')
40+
RsBlockExprImpl(BLOCK_EXPR)
41+
RsBlockImpl(BLOCK)
42+
PsiElement({)('{')
43+
PsiWhiteSpace(' ')
44+
RsLitExprImpl(LIT_EXPR)
45+
PsiElement(STRING_LITERAL)('""')
46+
PsiWhiteSpace(' ')
47+
PsiElement(})('}')
3748
PsiElement(>)('>')
3849
PsiElement(;)(';')
3950
PsiWhiteSpace('\n')
@@ -72,6 +83,17 @@ FILE
7283
RsBaseTypeImpl(BASE_TYPE)
7384
RsPathImpl(PATH)
7485
PsiElement(identifier)('str')
86+
PsiWhiteSpace(' ')
87+
PsiElement(=)('=')
88+
PsiWhiteSpace(' ')
89+
RsBlockExprImpl(BLOCK_EXPR)
90+
RsBlockImpl(BLOCK)
91+
PsiElement({)('{')
92+
PsiWhiteSpace(' ')
93+
RsLitExprImpl(LIT_EXPR)
94+
PsiElement(STRING_LITERAL)('""')
95+
PsiWhiteSpace(' ')
96+
PsiElement(})('}')
7597
PsiElement(>)('>')
7698
RsValueParameterListImpl(VALUE_PARAMETER_LIST)
7799
PsiElement(()('(')

0 commit comments

Comments
 (0)