Skip to content

Commit

Permalink
Merge #8542
Browse files Browse the repository at this point in the history
8542: GRAM: Fix parsing of generic parameters for assoc types / type aliases and assoc type bindings r=vlad20012 a=mchernyavsky

Relates to #6633.

changelog: Fix parsing of generic parameters for assoc types / type aliases and assoc type bindings


Co-authored-by: mhernyavsky <chernyavsky.mikhail@gmail.com>
  • Loading branch information
bors[bot] and mhernyavsky committed Feb 22, 2022
2 parents 42deeae + 954229d commit 648b39d
Show file tree
Hide file tree
Showing 8 changed files with 488 additions and 11 deletions.
6 changes: 2 additions & 4 deletions src/main/grammars/RustParser.bnf
Expand Up @@ -231,7 +231,7 @@ ColonTypeArgumentList ::= &'::' TypeArgumentListImpl { elementType = TypeArgumen
private TypeArgumentListImpl ::= '::'? '<' !'=' <<list_element AnyTypeArgument>>* '>' { pin = 3 }
private AnyTypeArgument ::= AssocTypeBinding | TypeReference | Lifetime | RestrictedConstExpr

AssocTypeBinding ::= identifier (AssocTypeBindingType | AssocTypeBindingBound) {
AssocTypeBinding ::= identifier TypeArgumentList? (AssocTypeBindingType | AssocTypeBindingBound) {
implements = [ "org.rust.lang.core.psi.ext.RsMandatoryReferenceElement" ]
mixin = "org.rust.lang.core.psi.ext.RsAssocTypeBindingMixin"
stubClass = "org.rust.lang.core.stubs.RsAssocTypeBindingStub"
Expand Down Expand Up @@ -1008,9 +1008,7 @@ private ImplicitTraitTypeInner ::= Polybound ('+' Polybound)+

private TraitType_upper ::= ('+' Polybound)+

upper TypeAlias ::= TYPE_KW identifier
[ TypeParameterList WhereClause? | WhereClause | TypeParamBounds ]
[ '=' TypeReference ] ';' {
upper TypeAlias ::= TYPE_KW identifier TypeParameterList? TypeParamBounds? WhereClause? [ '=' TypeReference ] ';' {
pin = 'identifier'
name = ""
implements = [ "org.rust.lang.core.psi.ext.RsQualifiedNamedElement"
Expand Down
Expand Up @@ -104,6 +104,6 @@ class RustParserDefinition : ParserDefinition {
/**
* Should be increased after any change of parser rules
*/
const val PARSER_VERSION: Int = LEXER_VERSION + 37
const val PARSER_VERSION: Int = LEXER_VERSION + 38
}
}
@@ -1,10 +1,13 @@
trait T {
type B;
type A = Self;
type A;
type B = Self;
type C<U>;
type D<U> = E<U>;
}

struct S;

impl T for S {
type B = T;
type A = T;
type C<U> = T<U>;
}
Expand Up @@ -10,20 +10,54 @@ FILE
RsTypeAliasImpl(TYPE_ALIAS)
PsiElement(type)('type')
PsiWhiteSpace(' ')
PsiElement(identifier)('B')
PsiElement(identifier)('A')
PsiElement(;)(';')
PsiWhiteSpace('\n ')
RsTypeAliasImpl(TYPE_ALIAS)
PsiElement(type)('type')
PsiWhiteSpace(' ')
PsiElement(identifier)('A')
PsiElement(identifier)('B')
PsiWhiteSpace(' ')
PsiElement(=)('=')
PsiWhiteSpace(' ')
RsBaseTypeImpl(BASE_TYPE)
RsPathImpl(PATH)
PsiElement(Self)('Self')
PsiElement(;)(';')
PsiWhiteSpace('\n ')
RsTypeAliasImpl(TYPE_ALIAS)
PsiElement(type)('type')
PsiWhiteSpace(' ')
PsiElement(identifier)('C')
RsTypeParameterListImpl(TYPE_PARAMETER_LIST)
PsiElement(<)('<')
RsTypeParameterImpl(TYPE_PARAMETER)
PsiElement(identifier)('U')
PsiElement(>)('>')
PsiElement(;)(';')
PsiWhiteSpace('\n ')
RsTypeAliasImpl(TYPE_ALIAS)
PsiElement(type)('type')
PsiWhiteSpace(' ')
PsiElement(identifier)('D')
RsTypeParameterListImpl(TYPE_PARAMETER_LIST)
PsiElement(<)('<')
RsTypeParameterImpl(TYPE_PARAMETER)
PsiElement(identifier)('U')
PsiElement(>)('>')
PsiWhiteSpace(' ')
PsiElement(=)('=')
PsiWhiteSpace(' ')
RsBaseTypeImpl(BASE_TYPE)
RsPathImpl(PATH)
PsiElement(identifier)('E')
RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST)
PsiElement(<)('<')
RsBaseTypeImpl(BASE_TYPE)
RsPathImpl(PATH)
PsiElement(identifier)('U')
PsiElement(>)('>')
PsiElement(;)(';')
PsiWhiteSpace('\n')
PsiElement(})('}')
PsiWhiteSpace('\n\n')
Expand Down Expand Up @@ -52,13 +86,36 @@ FILE
RsTypeAliasImpl(TYPE_ALIAS)
PsiElement(type)('type')
PsiWhiteSpace(' ')
PsiElement(identifier)('B')
PsiElement(identifier)('A')
PsiWhiteSpace(' ')
PsiElement(=)('=')
PsiWhiteSpace(' ')
RsBaseTypeImpl(BASE_TYPE)
RsPathImpl(PATH)
PsiElement(identifier)('T')
PsiElement(;)(';')
PsiWhiteSpace('\n ')
RsTypeAliasImpl(TYPE_ALIAS)
PsiElement(type)('type')
PsiWhiteSpace(' ')
PsiElement(identifier)('C')
RsTypeParameterListImpl(TYPE_PARAMETER_LIST)
PsiElement(<)('<')
RsTypeParameterImpl(TYPE_PARAMETER)
PsiElement(identifier)('U')
PsiElement(>)('>')
PsiWhiteSpace(' ')
PsiElement(=)('=')
PsiWhiteSpace(' ')
RsBaseTypeImpl(BASE_TYPE)
RsPathImpl(PATH)
PsiElement(identifier)('T')
RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST)
PsiElement(<)('<')
RsBaseTypeImpl(BASE_TYPE)
RsPathImpl(PATH)
PsiElement(identifier)('U')
PsiElement(>)('>')
PsiElement(;)(';')
PsiWhiteSpace('\n')
PsiElement(})('}')
Expand Up @@ -46,3 +46,9 @@ fn assoc_type_bounds2<T: Foo<Item: Bar+Baz>>(t: T) {}
fn assoc_type_bounds3<T: Foo<Item1: Bar, Item2 = ()>>(t: T) {}
fn assoc_type_bounds4<T: Foo<Item1 = (), Item2: Bar>>(t: T) {}
fn assoc_type_bounds_in_args(t: &dyn Foo<Item: Bar>) {}

fn gat_bounds1<T: Foo<Item<T>: Bar>>(t: T) {}
fn gat_bounds2<T: Foo<Item<T>: Bar+Baz>>(t: T) {}
fn gat_bounds3<T: Foo<Item1<T>: Bar, Item2<T> = ()>>(t: T) {}
fn gat_bounds4<T: Foo<Item1<T> = (), Item2<T>: Bar>>(t: T) {}
fn gat_in_args(t: &dyn Foo<Item<T>: Bar>) {}

0 comments on commit 648b39d

Please sign in to comment.