diff --git a/src/main/grammars/RustParser.bnf b/src/main/grammars/RustParser.bnf index 00838aecb9c..da710751163 100644 --- a/src/main/grammars/RustParser.bnf +++ b/src/main/grammars/RustParser.bnf @@ -229,15 +229,18 @@ TypeArgumentList ::= TypeArgumentListImpl { ColonTypeArgumentList ::= &'::' TypeArgumentListImpl { elementType = TypeArgumentList } private TypeArgumentListImpl ::= '::'? '<' !'=' <>* '>' { pin = 3 } -private AnyTypeArgument ::= AssocTypeBinding | TypeReference | Lifetime | RestrictedConstExpr +private AnyTypeArgument ::= <> + | Lifetime + | RestrictedConstExpr + | never (AssocTypeBinding | TypeReference) -AssocTypeBinding ::= identifier (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" +AssocTypeBinding ::= TypePathGenericArgsNoTypeQual (AssocTypeBindingType | AssocTypeBindingBound) { + extends = "org.rust.lang.core.psi.ext.RsStubbedElementImpl" + stubClass = "org.rust.lang.core.stubs.RsPlaceholderStub" elementTypeFactory = "org.rust.lang.core.stubs.StubImplementationsKt.factory" } +private AssocTypeBinding_upper ::= AssocTypeBindingType | AssocTypeBindingBound private AssocTypeBindingType ::= '=' TypeReference { pin = 1 } private AssocTypeBindingBound ::= ':' TypeBounds { pin = 1 } @@ -941,7 +944,7 @@ ScalarTypeReference ::= ArrayType ArrayType ::= '[' TypeReference [';' AnyExpr] ']' { pin = 1 implements = [ "org.rust.lang.core.psi.ext.RsInferenceContextOwner" ] - elementTypeFactory = "org.rust.lang.core.stubs.StubImplementationsKt.factory" + elementTypeFactory = "org.rust.lang.core.stubs.StubImplementationsKt.factory"i } private RefLikeStart ::= ( '&' Lifetime? mut? | '*' [ const | mut ] ) @@ -1008,9 +1011,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" @@ -1138,7 +1139,7 @@ AddBinExpr ::= Expr <> AddBinOp <> MulBinOp <> Expr <> CompBinOp ::= '==' | '!=' { name = "operator" } -RelCompBinOp ::= lteq | gteq | !ltlt '<' | !gtgt <> '>' { name = "operator" } +RelCompBinOp ::= lteq | <> gteq | !ltlt '<' | !gtgt <> '>' { name = "operator" } BitShiftBinOp ::= ltlt | <> gtgt { name = "operator" } AddBinOp ::= '+' | '-' { name = "operator" } MulBinOp ::= '*' | '/' | '%' { name = "operator" } diff --git a/src/main/kotlin/org/rust/ide/docs/RsDocumentationProvider.kt b/src/main/kotlin/org/rust/ide/docs/RsDocumentationProvider.kt index d2de49aa517..98314688b0b 100644 --- a/src/main/kotlin/org/rust/ide/docs/RsDocumentationProvider.kt +++ b/src/main/kotlin/org/rust/ide/docs/RsDocumentationProvider.kt @@ -419,7 +419,7 @@ private fun PsiElement.generateDocumentation(buffer: StringBuilder, prefix: Stri when (this) { is RsPath -> generatePathDocumentation(this, buffer) is RsAssocTypeBinding -> { - buffer += identifier.text + path.generateDocumentation(buffer) typeReference?.generateDocumentation(buffer, " = ") } is RsTraitRef -> path.generateDocumentation(buffer) diff --git a/src/main/kotlin/org/rust/ide/presentation/RsPsiRenderer.kt b/src/main/kotlin/org/rust/ide/presentation/RsPsiRenderer.kt index 300904c977c..34c30206c8c 100644 --- a/src/main/kotlin/org/rust/ide/presentation/RsPsiRenderer.kt +++ b/src/main/kotlin/org/rust/ide/presentation/RsPsiRenderer.kt @@ -457,7 +457,7 @@ open class RsPsiRenderer( } } assocTypeBindings.joinToWithBuffer(sb, ", ") { sb -> - sb.append(referenceName) + appendPath(sb, this.path) sb.append("=") typeReference?.let { appendTypeReference(sb, it) } } diff --git a/src/main/kotlin/org/rust/lang/core/parser/RustParserDefinition.kt b/src/main/kotlin/org/rust/lang/core/parser/RustParserDefinition.kt index 96e1b169537..48f4cb7d723 100644 --- a/src/main/kotlin/org/rust/lang/core/parser/RustParserDefinition.kt +++ b/src/main/kotlin/org/rust/lang/core/parser/RustParserDefinition.kt @@ -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 } } diff --git a/src/main/kotlin/org/rust/lang/core/parser/RustParserUtil.kt b/src/main/kotlin/org/rust/lang/core/parser/RustParserUtil.kt index 09269ab30bd..d04092d2fa3 100644 --- a/src/main/kotlin/org/rust/lang/core/parser/RustParserUtil.kt +++ b/src/main/kotlin/org/rust/lang/core/parser/RustParserUtil.kt @@ -429,6 +429,56 @@ object RustParserUtil : GeneratedParserUtilBase() { return result } + @Suppress("DuplicatedCode") + @JvmStatic + fun typeReferenceOrAssocTypeBinding( + b: PsiBuilder, + level: Int, + pathP: Parser, + assocTypeBindingUpperP: Parser, + typeReferenceP: Parser, + traitTypeUpperP: Parser, + ): Boolean { + if (b.tokenType == DYN || b.tokenType == IDENTIFIER && b.tokenText == "dyn" && b.lookAhead(1) != EXCL) { + return typeReferenceP.parse(b, level) + } + + val typeOrAssoc = enter_section_(b) + val polybound = enter_section_(b) + val bound = enter_section_(b) + val traitRef = enter_section_(b) + + if (!pathP.parse(b, level) || nextTokenIsFast(b, EXCL)) { + exit_section_(b, traitRef, null, false) + exit_section_(b, bound, null, false) + exit_section_(b, polybound, null, false) + exit_section_(b, typeOrAssoc, null, false) + return typeReferenceP.parse(b, level) + } + + if (nextTokenIsFast(b, PLUS) ) { + exit_section_(b, traitRef, TRAIT_REF, true) + exit_section_(b, bound, BOUND, true) + exit_section_(b, polybound, POLYBOUND, true) + val result = traitTypeUpperP.parse(b, level) + exit_section_(b, typeOrAssoc, TRAIT_TYPE, result) + return result + } + + exit_section_(b, traitRef, null, true) + exit_section_(b, bound, null, true) + exit_section_(b, polybound, null, true) + + if (!nextTokenIsFast(b, EQ) && !nextTokenIsFast(b, COLON)) { + exit_section_(b, typeOrAssoc, BASE_TYPE, true) + return true + } + + val result = assocTypeBindingUpperP.parse(b, level) + exit_section_(b, typeOrAssoc, ASSOC_TYPE_BINDING, result) + return result + } + private val SPECIAL_MACRO_PARSERS: Map Boolean> private val SPECIAL_EXPR_MACROS: Set diff --git a/src/main/kotlin/org/rust/lang/core/psi/ext/RsAssocTypeBinding.kt b/src/main/kotlin/org/rust/lang/core/psi/ext/RsAssocTypeBinding.kt index 029b3b94a12..54dc2fc4a34 100644 --- a/src/main/kotlin/org/rust/lang/core/psi/ext/RsAssocTypeBinding.kt +++ b/src/main/kotlin/org/rust/lang/core/psi/ext/RsAssocTypeBinding.kt @@ -5,30 +5,10 @@ package org.rust.lang.core.psi.ext -import com.intellij.lang.ASTNode -import com.intellij.psi.PsiElement -import com.intellij.psi.stubs.IStubElementType import org.rust.lang.core.psi.RsAssocTypeBinding import org.rust.lang.core.psi.RsPath -import org.rust.lang.core.resolve.ref.RsAssocTypeBindingReferenceImpl -import org.rust.lang.core.resolve.ref.RsReference -import org.rust.lang.core.stubs.RsAssocTypeBindingStub // Current grammar allows to write assoc type bindings in method calls, e.g. // `a.foo::()`, so it's nullable val RsAssocTypeBinding.parentPath: RsPath? get() = ancestorStrict() - -abstract class RsAssocTypeBindingMixin : RsStubbedElementImpl, - RsAssocTypeBinding { - - constructor(node: ASTNode) : super(node) - - constructor(stub: RsAssocTypeBindingStub, nodeType: IStubElementType<*, *>) : super(stub, nodeType) - - override fun getReference(): RsReference = RsAssocTypeBindingReferenceImpl(this) - - override val referenceNameElement: PsiElement get() = identifier - - override val referenceName: String get() = greenStub?.referenceName ?: super.referenceName -} diff --git a/src/main/kotlin/org/rust/lang/core/psi/ext/RsMethodOrPath.kt b/src/main/kotlin/org/rust/lang/core/psi/ext/RsMethodOrPath.kt index 28f81b649b8..bdd72d70624 100644 --- a/src/main/kotlin/org/rust/lang/core/psi/ext/RsMethodOrPath.kt +++ b/src/main/kotlin/org/rust/lang/core/psi/ext/RsMethodOrPath.kt @@ -5,6 +5,7 @@ package org.rust.lang.core.psi.ext +import org.rust.lang.core.psi.RsAssocTypeBinding import org.rust.lang.core.psi.RsLifetime import org.rust.lang.core.psi.RsTypeArgumentList import org.rust.lang.core.psi.RsTypeReference @@ -12,6 +13,7 @@ import org.rust.lang.core.psi.RsTypeReference val RsMethodOrPath.lifetimeArguments: List get() = typeArgumentList?.lifetimeArguments.orEmpty() val RsMethodOrPath.typeArguments: List get() = typeArgumentList?.typeArguments.orEmpty() val RsMethodOrPath.constArguments: List get() = typeArgumentList?.constArguments.orEmpty() +val RsMethodOrPath.assocTypeBindings: List get() = typeArgumentList?.assocTypeBindingList.orEmpty() fun RsMethodOrPath.getGenericArguments( includeLifetimes: Boolean = true, diff --git a/src/main/kotlin/org/rust/lang/core/resolve/NameResolution.kt b/src/main/kotlin/org/rust/lang/core/resolve/NameResolution.kt index 87f56e645e5..24d7b4cbdd4 100644 --- a/src/main/kotlin/org/rust/lang/core/resolve/NameResolution.kt +++ b/src/main/kotlin/org/rust/lang/core/resolve/NameResolution.kt @@ -324,6 +324,9 @@ fun processPathResolveVariants(lookup: ImplLookup?, path: RsPath, isCompletion: if (parent is RsMacroCall) { error("Tried to use `processPathResolveVariants` for macro path. See `RsMacroPathReferenceImpl`") } + if (parent is RsAssocTypeBinding) { + return processAssocTypeVariants(parent, processor) + } val qualifier = path.qualifier val typeQual = path.typeQual val ns = path.allowedNamespaces(isCompletion) diff --git a/src/main/kotlin/org/rust/lang/core/resolve/ref/RsAssocTypeBindingReferenceImpl.kt b/src/main/kotlin/org/rust/lang/core/resolve/ref/RsAssocTypeBindingReferenceImpl.kt deleted file mode 100644 index 27bc13d7798..00000000000 --- a/src/main/kotlin/org/rust/lang/core/resolve/ref/RsAssocTypeBindingReferenceImpl.kt +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Use of this source code is governed by the MIT license that can be - * found in the LICENSE file. - */ - -package org.rust.lang.core.resolve.ref - -import com.intellij.psi.PsiElement -import org.rust.lang.core.psi.RsAssocTypeBinding -import org.rust.lang.core.psi.RsTypeAlias -import org.rust.lang.core.psi.ext.RsElement -import org.rust.lang.core.psi.ext.owner -import org.rust.lang.core.resolve.collectResolveVariants -import org.rust.lang.core.resolve.processAssocTypeVariants - -class RsAssocTypeBindingReferenceImpl( - element: RsAssocTypeBinding -) : RsReferenceCached(element) { - - override fun resolveInner(): List = - collectResolveVariants(element.referenceName) { processAssocTypeVariants(element, it) } - - override fun isReferenceTo(element: PsiElement): Boolean = - element is RsTypeAlias && element.owner.isImplOrTrait && super.isReferenceTo(element) -} diff --git a/src/main/kotlin/org/rust/lang/core/resolve/ref/RsPathReferenceImpl.kt b/src/main/kotlin/org/rust/lang/core/resolve/ref/RsPathReferenceImpl.kt index a725418f677..04aed92a7e6 100644 --- a/src/main/kotlin/org/rust/lang/core/resolve/ref/RsPathReferenceImpl.kt +++ b/src/main/kotlin/org/rust/lang/core/resolve/ref/RsPathReferenceImpl.kt @@ -38,6 +38,11 @@ class RsPathReferenceImpl( if (target is RsAbstractable) { val owner = target.owner + + if (target is RsTypeAlias && owner.isImplOrTrait && path.parent is RsAssocTypeBinding) { + return super.isReferenceTo(target) + } + if (owner.isImplOrTrait && (path.parent is RsUseSpeck || path.path == null && path.typeQual == null)) { return false } @@ -417,7 +422,7 @@ private fun pathTypeParameters(path: RsPath): RsPsiPathParameters? { } private fun resolveAssocTypeBinding(trait: RsTraitItem, binding: RsAssocTypeBinding): RsTypeAlias? = - collectResolveVariants(binding.referenceName) { processAssocTypeVariants(trait, it) } + collectResolveVariants(binding.path.referenceName) { processAssocTypeVariants(trait, it) } .singleOrNull() as? RsTypeAlias? /** Resolves a reference through type aliases */ diff --git a/src/main/kotlin/org/rust/lang/core/stubs/StubImplementations.kt b/src/main/kotlin/org/rust/lang/core/stubs/StubImplementations.kt index 861d1abeab6..426cfccb20a 100644 --- a/src/main/kotlin/org/rust/lang/core/stubs/StubImplementations.kt +++ b/src/main/kotlin/org/rust/lang/core/stubs/StubImplementations.kt @@ -272,7 +272,7 @@ fun factory(name: String): RsStubElementType<*, *> = when (name) { "LIFETIME_PARAMETER" -> RsLifetimeParameterStub.Type "FOR_LIFETIMES" -> RsPlaceholderStub.Type("FOR_LIFETIMES", ::RsForLifetimesImpl) "TYPE_ARGUMENT_LIST" -> RsPlaceholderStub.Type("TYPE_ARGUMENT_LIST", ::RsTypeArgumentListImpl) - "ASSOC_TYPE_BINDING" -> RsAssocTypeBindingStub.Type + "ASSOC_TYPE_BINDING" -> RsPlaceholderStub.Type("ASSOC_TYPE_BINDING", ::RsAssocTypeBindingImpl) "TYPE_PARAM_BOUNDS" -> RsPlaceholderStub.Type("TYPE_PARAM_BOUNDS", ::RsTypeParamBoundsImpl) "POLYBOUND" -> RsPolyboundStub.Type @@ -2155,31 +2155,6 @@ private fun RsStubLiteralKind?.serialize(dataStream: StubOutputStream) { } } -class RsAssocTypeBindingStub( - parent: StubElement<*>?, elementType: IStubElementType<*, *>, - val referenceName: String -) : StubBase(parent, elementType) { - - object Type : RsStubElementType("ASSOC_TYPE_BINDING") { - override fun deserialize(dataStream: StubInputStream, parentStub: StubElement<*>?) = - RsAssocTypeBindingStub( - parentStub, this, - dataStream.readNameAsString()!! - ) - - override fun serialize(stub: RsAssocTypeBindingStub, dataStream: StubOutputStream) = - with(dataStream) { - writeName(stub.referenceName) - } - - override fun createPsi(stub: RsAssocTypeBindingStub): RsAssocTypeBinding = - RsAssocTypeBindingImpl(stub, this) - - override fun createStub(psi: RsAssocTypeBinding, parentStub: StubElement<*>?) = - RsAssocTypeBindingStub(parentStub, this, psi.referenceName) - } -} - class RsPolyboundStub( parent: StubElement<*>?, elementType: IStubElementType<*, *>, val hasQ: Boolean, diff --git a/src/main/kotlin/org/rust/lang/core/types/infer/TypeInference.kt b/src/main/kotlin/org/rust/lang/core/types/infer/TypeInference.kt index 39ce983d90b..dd2aa3b8c21 100644 --- a/src/main/kotlin/org/rust/lang/core/types/infer/TypeInference.kt +++ b/src/main/kotlin/org/rust/lang/core/types/infer/TypeInference.kt @@ -1028,9 +1028,9 @@ private fun List?.toPredicates(selfTy: Ty): Sequence val traitRef = bound.bound.traitRef ?: return@flatMap emptySequence() val boundTrait = traitRef.resolveToBoundTrait() ?: return@flatMap emptySequence() - val assocTypeBounds = traitRef.path.typeArgumentList?.assocTypeBindingList.orEmpty().asSequence() + val assocTypeBounds = traitRef.path.assocTypeBindings.asSequence() .flatMap nestedFlatMap@{ - val assoc = it.reference.resolve() as? RsTypeAlias + val assoc = it.path.reference?.resolve() as? RsTypeAlias ?: return@nestedFlatMap emptySequence() val projectionTy = TyProjection.valueOf(selfTy, assoc) val typeRef = it.typeReference diff --git a/src/test/resources/org/rust/lang/core/parser/fixtures/complete/associated_types.rs b/src/test/resources/org/rust/lang/core/parser/fixtures/complete/associated_types.rs index 16c5a61ff05..e8913167a2b 100644 --- a/src/test/resources/org/rust/lang/core/parser/fixtures/complete/associated_types.rs +++ b/src/test/resources/org/rust/lang/core/parser/fixtures/complete/associated_types.rs @@ -1,10 +1,13 @@ trait T { - type B; - type A = Self; + type A; + type B = Self; + type C; + type D = E; } struct S; impl T for S { - type B = T; + type A = T; + type C = T; } diff --git a/src/test/resources/org/rust/lang/core/parser/fixtures/complete/associated_types.txt b/src/test/resources/org/rust/lang/core/parser/fixtures/complete/associated_types.txt index 68922abf957..dec66b049d2 100644 --- a/src/test/resources/org/rust/lang/core/parser/fixtures/complete/associated_types.txt +++ b/src/test/resources/org/rust/lang/core/parser/fixtures/complete/associated_types.txt @@ -10,13 +10,13 @@ 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(' ') @@ -24,6 +24,40 @@ FILE 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') @@ -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(})('}') diff --git a/src/test/resources/org/rust/lang/core/parser/fixtures/complete/polybounds.rs b/src/test/resources/org/rust/lang/core/parser/fixtures/complete/polybounds.rs index c1e6f33f317..49fc1b6b829 100644 --- a/src/test/resources/org/rust/lang/core/parser/fixtures/complete/polybounds.rs +++ b/src/test/resources/org/rust/lang/core/parser/fixtures/complete/polybounds.rs @@ -46,3 +46,9 @@ fn assoc_type_bounds2>(t: T) {} fn assoc_type_bounds3>(t: T) {} fn assoc_type_bounds4>(t: T) {} fn assoc_type_bounds_in_args(t: &dyn Foo) {} + +fn gat_bounds1: Bar>>(t: T) {} +fn gat_bounds2: Bar+Baz>>(t: T) {} +fn gat_bounds3: Bar, Item2 = ()>>(t: T) {} +fn gat_bounds4 = (), Item2: Bar>>(t: T) {} +fn gat_in_args(t: &dyn Foo: Bar>) {} diff --git a/src/test/resources/org/rust/lang/core/parser/fixtures/complete/polybounds.txt b/src/test/resources/org/rust/lang/core/parser/fixtures/complete/polybounds.txt index 8c8fc3048c2..4b2da42d507 100644 --- a/src/test/resources/org/rust/lang/core/parser/fixtures/complete/polybounds.txt +++ b/src/test/resources/org/rust/lang/core/parser/fixtures/complete/polybounds.txt @@ -781,7 +781,8 @@ FILE RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST) PsiElement(<)('<') RsAssocTypeBindingImpl(ASSOC_TYPE_BINDING) - PsiElement(identifier)('Item') + RsPathImpl(PATH) + PsiElement(identifier)('Item') PsiElement(:)(':') PsiWhiteSpace(' ') RsPolyboundImpl(POLYBOUND) @@ -827,7 +828,8 @@ FILE RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST) PsiElement(<)('<') RsAssocTypeBindingImpl(ASSOC_TYPE_BINDING) - PsiElement(identifier)('Item') + RsPathImpl(PATH) + PsiElement(identifier)('Item') PsiElement(:)(':') PsiWhiteSpace(' ') RsPolyboundImpl(POLYBOUND) @@ -879,7 +881,8 @@ FILE RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST) PsiElement(<)('<') RsAssocTypeBindingImpl(ASSOC_TYPE_BINDING) - PsiElement(identifier)('Item1') + RsPathImpl(PATH) + PsiElement(identifier)('Item1') PsiElement(:)(':') PsiWhiteSpace(' ') RsPolyboundImpl(POLYBOUND) @@ -890,7 +893,8 @@ FILE PsiElement(,)(',') PsiWhiteSpace(' ') RsAssocTypeBindingImpl(ASSOC_TYPE_BINDING) - PsiElement(identifier)('Item2') + RsPathImpl(PATH) + PsiElement(identifier)('Item2') PsiWhiteSpace(' ') PsiElement(=)('=') PsiWhiteSpace(' ') @@ -935,7 +939,8 @@ FILE RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST) PsiElement(<)('<') RsAssocTypeBindingImpl(ASSOC_TYPE_BINDING) - PsiElement(identifier)('Item1') + RsPathImpl(PATH) + PsiElement(identifier)('Item1') PsiWhiteSpace(' ') PsiElement(=)('=') PsiWhiteSpace(' ') @@ -945,7 +950,8 @@ FILE PsiElement(,)(',') PsiWhiteSpace(' ') RsAssocTypeBindingImpl(ASSOC_TYPE_BINDING) - PsiElement(identifier)('Item2') + RsPathImpl(PATH) + PsiElement(identifier)('Item2') PsiElement(:)(':') PsiWhiteSpace(' ') RsPolyboundImpl(POLYBOUND) @@ -997,7 +1003,307 @@ FILE RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST) PsiElement(<)('<') RsAssocTypeBindingImpl(ASSOC_TYPE_BINDING) + RsPathImpl(PATH) + PsiElement(identifier)('Item') + PsiElement(:)(':') + PsiWhiteSpace(' ') + RsPolyboundImpl(POLYBOUND) + RsBoundImpl(BOUND) + RsTraitRefImpl(TRAIT_REF) + RsPathImpl(PATH) + PsiElement(identifier)('Bar') + PsiElement(>)('>') + PsiElement())(')') + PsiWhiteSpace(' ') + RsBlockImpl(BLOCK) + PsiElement({)('{') + PsiElement(})('}') + PsiWhiteSpace('\n\n') + RsFunctionImpl(FUNCTION) + PsiElement(fn)('fn') + PsiWhiteSpace(' ') + PsiElement(identifier)('gat_bounds1') + RsTypeParameterListImpl(TYPE_PARAMETER_LIST) + PsiElement(<)('<') + RsTypeParameterImpl(TYPE_PARAMETER) + PsiElement(identifier)('T') + RsTypeParamBoundsImpl(TYPE_PARAM_BOUNDS) + PsiElement(:)(':') + PsiWhiteSpace(' ') + RsPolyboundImpl(POLYBOUND) + RsBoundImpl(BOUND) + RsTraitRefImpl(TRAIT_REF) + RsPathImpl(PATH) + PsiElement(identifier)('Foo') + RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST) + PsiElement(<)('<') + RsAssocTypeBindingImpl(ASSOC_TYPE_BINDING) + RsPathImpl(PATH) PsiElement(identifier)('Item') + RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST) + PsiElement(<)('<') + RsBaseTypeImpl(BASE_TYPE) + RsPathImpl(PATH) + PsiElement(identifier)('T') + PsiElement(>)('>') + PsiElement(:)(':') + PsiWhiteSpace(' ') + RsPolyboundImpl(POLYBOUND) + RsBoundImpl(BOUND) + RsTraitRefImpl(TRAIT_REF) + RsPathImpl(PATH) + PsiElement(identifier)('Bar') + PsiElement(>)('>') + PsiElement(>)('>') + RsValueParameterListImpl(VALUE_PARAMETER_LIST) + PsiElement(()('(') + RsValueParameterImpl(VALUE_PARAMETER) + RsPatIdentImpl(PAT_IDENT) + RsPatBindingImpl(PAT_BINDING) + PsiElement(identifier)('t') + PsiElement(:)(':') + PsiWhiteSpace(' ') + RsBaseTypeImpl(BASE_TYPE) + RsPathImpl(PATH) + PsiElement(identifier)('T') + PsiElement())(')') + PsiWhiteSpace(' ') + RsBlockImpl(BLOCK) + PsiElement({)('{') + PsiElement(})('}') + PsiWhiteSpace('\n') + RsFunctionImpl(FUNCTION) + PsiElement(fn)('fn') + PsiWhiteSpace(' ') + PsiElement(identifier)('gat_bounds2') + RsTypeParameterListImpl(TYPE_PARAMETER_LIST) + PsiElement(<)('<') + RsTypeParameterImpl(TYPE_PARAMETER) + PsiElement(identifier)('T') + RsTypeParamBoundsImpl(TYPE_PARAM_BOUNDS) + PsiElement(:)(':') + PsiWhiteSpace(' ') + RsPolyboundImpl(POLYBOUND) + RsBoundImpl(BOUND) + RsTraitRefImpl(TRAIT_REF) + RsPathImpl(PATH) + PsiElement(identifier)('Foo') + RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST) + PsiElement(<)('<') + RsAssocTypeBindingImpl(ASSOC_TYPE_BINDING) + RsPathImpl(PATH) + PsiElement(identifier)('Item') + RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST) + PsiElement(<)('<') + RsBaseTypeImpl(BASE_TYPE) + RsPathImpl(PATH) + PsiElement(identifier)('T') + PsiElement(>)('>') + PsiElement(:)(':') + PsiWhiteSpace(' ') + RsPolyboundImpl(POLYBOUND) + RsBoundImpl(BOUND) + RsTraitRefImpl(TRAIT_REF) + RsPathImpl(PATH) + PsiElement(identifier)('Bar') + PsiElement(+)('+') + RsPolyboundImpl(POLYBOUND) + RsBoundImpl(BOUND) + RsTraitRefImpl(TRAIT_REF) + RsPathImpl(PATH) + PsiElement(identifier)('Baz') + PsiElement(>)('>') + PsiElement(>)('>') + RsValueParameterListImpl(VALUE_PARAMETER_LIST) + PsiElement(()('(') + RsValueParameterImpl(VALUE_PARAMETER) + RsPatIdentImpl(PAT_IDENT) + RsPatBindingImpl(PAT_BINDING) + PsiElement(identifier)('t') + PsiElement(:)(':') + PsiWhiteSpace(' ') + RsBaseTypeImpl(BASE_TYPE) + RsPathImpl(PATH) + PsiElement(identifier)('T') + PsiElement())(')') + PsiWhiteSpace(' ') + RsBlockImpl(BLOCK) + PsiElement({)('{') + PsiElement(})('}') + PsiWhiteSpace('\n') + RsFunctionImpl(FUNCTION) + PsiElement(fn)('fn') + PsiWhiteSpace(' ') + PsiElement(identifier)('gat_bounds3') + RsTypeParameterListImpl(TYPE_PARAMETER_LIST) + PsiElement(<)('<') + RsTypeParameterImpl(TYPE_PARAMETER) + PsiElement(identifier)('T') + RsTypeParamBoundsImpl(TYPE_PARAM_BOUNDS) + PsiElement(:)(':') + PsiWhiteSpace(' ') + RsPolyboundImpl(POLYBOUND) + RsBoundImpl(BOUND) + RsTraitRefImpl(TRAIT_REF) + RsPathImpl(PATH) + PsiElement(identifier)('Foo') + RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST) + PsiElement(<)('<') + RsAssocTypeBindingImpl(ASSOC_TYPE_BINDING) + RsPathImpl(PATH) + PsiElement(identifier)('Item1') + RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST) + PsiElement(<)('<') + RsBaseTypeImpl(BASE_TYPE) + RsPathImpl(PATH) + PsiElement(identifier)('T') + PsiElement(>)('>') + PsiElement(:)(':') + PsiWhiteSpace(' ') + RsPolyboundImpl(POLYBOUND) + RsBoundImpl(BOUND) + RsTraitRefImpl(TRAIT_REF) + RsPathImpl(PATH) + PsiElement(identifier)('Bar') + PsiElement(,)(',') + PsiWhiteSpace(' ') + RsAssocTypeBindingImpl(ASSOC_TYPE_BINDING) + RsPathImpl(PATH) + PsiElement(identifier)('Item2') + RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST) + PsiElement(<)('<') + RsBaseTypeImpl(BASE_TYPE) + RsPathImpl(PATH) + PsiElement(identifier)('T') + PsiElement(>)('>') + PsiWhiteSpace(' ') + PsiElement(=)('=') + PsiWhiteSpace(' ') + RsBaseTypeImpl(BASE_TYPE) + PsiElement(()('(') + PsiElement())(')') + PsiElement(>)('>') + PsiElement(>)('>') + RsValueParameterListImpl(VALUE_PARAMETER_LIST) + PsiElement(()('(') + RsValueParameterImpl(VALUE_PARAMETER) + RsPatIdentImpl(PAT_IDENT) + RsPatBindingImpl(PAT_BINDING) + PsiElement(identifier)('t') + PsiElement(:)(':') + PsiWhiteSpace(' ') + RsBaseTypeImpl(BASE_TYPE) + RsPathImpl(PATH) + PsiElement(identifier)('T') + PsiElement())(')') + PsiWhiteSpace(' ') + RsBlockImpl(BLOCK) + PsiElement({)('{') + PsiElement(})('}') + PsiWhiteSpace('\n') + RsFunctionImpl(FUNCTION) + PsiElement(fn)('fn') + PsiWhiteSpace(' ') + PsiElement(identifier)('gat_bounds4') + RsTypeParameterListImpl(TYPE_PARAMETER_LIST) + PsiElement(<)('<') + RsTypeParameterImpl(TYPE_PARAMETER) + PsiElement(identifier)('T') + RsTypeParamBoundsImpl(TYPE_PARAM_BOUNDS) + PsiElement(:)(':') + PsiWhiteSpace(' ') + RsPolyboundImpl(POLYBOUND) + RsBoundImpl(BOUND) + RsTraitRefImpl(TRAIT_REF) + RsPathImpl(PATH) + PsiElement(identifier)('Foo') + RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST) + PsiElement(<)('<') + RsAssocTypeBindingImpl(ASSOC_TYPE_BINDING) + RsPathImpl(PATH) + PsiElement(identifier)('Item1') + RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST) + PsiElement(<)('<') + RsBaseTypeImpl(BASE_TYPE) + RsPathImpl(PATH) + PsiElement(identifier)('T') + PsiElement(>)('>') + PsiWhiteSpace(' ') + PsiElement(=)('=') + PsiWhiteSpace(' ') + RsBaseTypeImpl(BASE_TYPE) + PsiElement(()('(') + PsiElement())(')') + PsiElement(,)(',') + PsiWhiteSpace(' ') + RsAssocTypeBindingImpl(ASSOC_TYPE_BINDING) + RsPathImpl(PATH) + PsiElement(identifier)('Item2') + RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST) + PsiElement(<)('<') + RsBaseTypeImpl(BASE_TYPE) + RsPathImpl(PATH) + PsiElement(identifier)('T') + PsiElement(>)('>') + PsiElement(:)(':') + PsiWhiteSpace(' ') + RsPolyboundImpl(POLYBOUND) + RsBoundImpl(BOUND) + RsTraitRefImpl(TRAIT_REF) + RsPathImpl(PATH) + PsiElement(identifier)('Bar') + PsiElement(>)('>') + PsiElement(>)('>') + RsValueParameterListImpl(VALUE_PARAMETER_LIST) + PsiElement(()('(') + RsValueParameterImpl(VALUE_PARAMETER) + RsPatIdentImpl(PAT_IDENT) + RsPatBindingImpl(PAT_BINDING) + PsiElement(identifier)('t') + PsiElement(:)(':') + PsiWhiteSpace(' ') + RsBaseTypeImpl(BASE_TYPE) + RsPathImpl(PATH) + PsiElement(identifier)('T') + PsiElement())(')') + PsiWhiteSpace(' ') + RsBlockImpl(BLOCK) + PsiElement({)('{') + PsiElement(})('}') + PsiWhiteSpace('\n') + RsFunctionImpl(FUNCTION) + PsiElement(fn)('fn') + PsiWhiteSpace(' ') + PsiElement(identifier)('gat_in_args') + RsValueParameterListImpl(VALUE_PARAMETER_LIST) + PsiElement(()('(') + RsValueParameterImpl(VALUE_PARAMETER) + RsPatIdentImpl(PAT_IDENT) + RsPatBindingImpl(PAT_BINDING) + PsiElement(identifier)('t') + PsiElement(:)(':') + PsiWhiteSpace(' ') + RsRefLikeTypeImpl(REF_LIKE_TYPE) + PsiElement(&)('&') + RsTraitTypeImpl(TRAIT_TYPE) + PsiElement(dyn_kw)('dyn') + PsiWhiteSpace(' ') + RsPolyboundImpl(POLYBOUND) + RsBoundImpl(BOUND) + RsTraitRefImpl(TRAIT_REF) + RsPathImpl(PATH) + PsiElement(identifier)('Foo') + RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST) + PsiElement(<)('<') + RsAssocTypeBindingImpl(ASSOC_TYPE_BINDING) + RsPathImpl(PATH) + PsiElement(identifier)('Item') + RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST) + PsiElement(<)('<') + RsBaseTypeImpl(BASE_TYPE) + RsPathImpl(PATH) + PsiElement(identifier)('T') + PsiElement(>)('>') PsiElement(:)(':') PsiWhiteSpace(' ') RsPolyboundImpl(POLYBOUND) diff --git a/src/test/resources/org/rust/lang/core/parser/fixtures/complete/type.rs b/src/test/resources/org/rust/lang/core/parser/fixtures/complete/type.rs index b882056c82c..f80cf8655cf 100644 --- a/src/test/resources/org/rust/lang/core/parser/fixtures/complete/type.rs +++ b/src/test/resources/org/rust/lang/core/parser/fixtures/complete/type.rs @@ -48,3 +48,8 @@ type ExternCFn = extern "C" fn(); type ExternFnWithEscapeInAbi = extern "R\x75st" fn(); type ExternFnWithRawAbi = extern r"system" fn(); type ExternFnWithInvalidAbi = extern true fn(); + +type GatSimple = (); +type GatBound: Bound = (); +type GatWhere where T: Bound = (); +type GatBoundWhere: Bound where T: Bound = (); diff --git a/src/test/resources/org/rust/lang/core/parser/fixtures/complete/type.txt b/src/test/resources/org/rust/lang/core/parser/fixtures/complete/type.txt index 66214b58777..b103076e123 100644 --- a/src/test/resources/org/rust/lang/core/parser/fixtures/complete/type.txt +++ b/src/test/resources/org/rust/lang/core/parser/fixtures/complete/type.txt @@ -353,7 +353,8 @@ FILE PsiElement(,)(',') PsiWhiteSpace(' ') RsAssocTypeBindingImpl(ASSOC_TYPE_BINDING) - PsiElement(identifier)('T') + RsPathImpl(PATH) + PsiElement(identifier)('T') PsiElement(=)('=') RsBaseTypeImpl(BASE_TYPE) RsPathImpl(PATH) @@ -427,7 +428,8 @@ FILE RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST) PsiElement(<)('<') RsAssocTypeBindingImpl(ASSOC_TYPE_BINDING) - PsiElement(identifier)('Item') + RsPathImpl(PATH) + PsiElement(identifier)('Item') PsiElement(=)('=') RsTupleTypeImpl(TUPLE_TYPE) PsiElement(()('(') @@ -469,7 +471,8 @@ FILE PsiElement(,)(',') PsiWhiteSpace(' ') RsAssocTypeBindingImpl(ASSOC_TYPE_BINDING) - PsiElement(identifier)('U') + RsPathImpl(PATH) + PsiElement(identifier)('U') PsiElement(=)('=') RsBaseTypeImpl(BASE_TYPE) RsPathImpl(PATH) @@ -610,7 +613,8 @@ FILE RsTypeArgumentListImpl(TYPE_ARGUMENT_LIST) PsiElement(<)('<') RsAssocTypeBindingImpl(ASSOC_TYPE_BINDING) - PsiElement(identifier)('Item') + RsPathImpl(PATH) + PsiElement(identifier)('Item') PsiElement(=)('=') RsTraitTypeImpl(TRAIT_TYPE) PsiElement(impl)('impl') @@ -948,3 +952,119 @@ FILE PsiElement(()('(') PsiElement())(')') PsiElement(;)(';') + PsiWhiteSpace('\n\n') + RsTypeAliasImpl(TYPE_ALIAS) + PsiElement(type)('type') + PsiWhiteSpace(' ') + PsiElement(identifier)('GatSimple') + RsTypeParameterListImpl(TYPE_PARAMETER_LIST) + PsiElement(<)('<') + RsTypeParameterImpl(TYPE_PARAMETER) + PsiElement(identifier)('T') + PsiElement(>)('>') + PsiWhiteSpace(' ') + PsiElement(=)('=') + PsiWhiteSpace(' ') + RsBaseTypeImpl(BASE_TYPE) + PsiElement(()('(') + PsiElement())(')') + PsiElement(;)(';') + PsiWhiteSpace('\n') + RsTypeAliasImpl(TYPE_ALIAS) + PsiElement(type)('type') + PsiWhiteSpace(' ') + PsiElement(identifier)('GatBound') + RsTypeParameterListImpl(TYPE_PARAMETER_LIST) + PsiElement(<)('<') + RsTypeParameterImpl(TYPE_PARAMETER) + PsiElement(identifier)('T') + PsiElement(>)('>') + RsTypeParamBoundsImpl(TYPE_PARAM_BOUNDS) + PsiElement(:)(':') + PsiWhiteSpace(' ') + RsPolyboundImpl(POLYBOUND) + RsBoundImpl(BOUND) + RsTraitRefImpl(TRAIT_REF) + RsPathImpl(PATH) + PsiElement(identifier)('Bound') + PsiWhiteSpace(' ') + PsiElement(=)('=') + PsiWhiteSpace(' ') + RsBaseTypeImpl(BASE_TYPE) + PsiElement(()('(') + PsiElement())(')') + PsiElement(;)(';') + PsiWhiteSpace('\n') + RsTypeAliasImpl(TYPE_ALIAS) + PsiElement(type)('type') + PsiWhiteSpace(' ') + PsiElement(identifier)('GatWhere') + RsTypeParameterListImpl(TYPE_PARAMETER_LIST) + PsiElement(<)('<') + RsTypeParameterImpl(TYPE_PARAMETER) + PsiElement(identifier)('T') + PsiElement(>)('>') + PsiWhiteSpace(' ') + RsWhereClauseImpl(WHERE_CLAUSE) + PsiElement(where)('where') + PsiWhiteSpace(' ') + RsWherePredImpl(WHERE_PRED) + RsBaseTypeImpl(BASE_TYPE) + RsPathImpl(PATH) + PsiElement(identifier)('T') + RsTypeParamBoundsImpl(TYPE_PARAM_BOUNDS) + PsiElement(:)(':') + PsiWhiteSpace(' ') + RsPolyboundImpl(POLYBOUND) + RsBoundImpl(BOUND) + RsTraitRefImpl(TRAIT_REF) + RsPathImpl(PATH) + PsiElement(identifier)('Bound') + PsiWhiteSpace(' ') + PsiElement(=)('=') + PsiWhiteSpace(' ') + RsBaseTypeImpl(BASE_TYPE) + PsiElement(()('(') + PsiElement())(')') + PsiElement(;)(';') + PsiWhiteSpace('\n') + RsTypeAliasImpl(TYPE_ALIAS) + PsiElement(type)('type') + PsiWhiteSpace(' ') + PsiElement(identifier)('GatBoundWhere') + RsTypeParameterListImpl(TYPE_PARAMETER_LIST) + PsiElement(<)('<') + RsTypeParameterImpl(TYPE_PARAMETER) + PsiElement(identifier)('T') + PsiElement(>)('>') + RsTypeParamBoundsImpl(TYPE_PARAM_BOUNDS) + PsiElement(:)(':') + PsiWhiteSpace(' ') + RsPolyboundImpl(POLYBOUND) + RsBoundImpl(BOUND) + RsTraitRefImpl(TRAIT_REF) + RsPathImpl(PATH) + PsiElement(identifier)('Bound') + PsiWhiteSpace(' ') + RsWhereClauseImpl(WHERE_CLAUSE) + PsiElement(where)('where') + PsiWhiteSpace(' ') + RsWherePredImpl(WHERE_PRED) + RsBaseTypeImpl(BASE_TYPE) + RsPathImpl(PATH) + PsiElement(identifier)('T') + RsTypeParamBoundsImpl(TYPE_PARAM_BOUNDS) + PsiElement(:)(':') + PsiWhiteSpace(' ') + RsPolyboundImpl(POLYBOUND) + RsBoundImpl(BOUND) + RsTraitRefImpl(TRAIT_REF) + RsPathImpl(PATH) + PsiElement(identifier)('Bound') + PsiWhiteSpace(' ') + PsiElement(=)('=') + PsiWhiteSpace(' ') + RsBaseTypeImpl(BASE_TYPE) + PsiElement(()('(') + PsiElement())(')') + PsiElement(;)(';') diff --git a/src/test/resources/org/rust/lang/core/parser/fixtures/partial/no_lifetime_bounds_in_generic_args.txt b/src/test/resources/org/rust/lang/core/parser/fixtures/partial/no_lifetime_bounds_in_generic_args.txt index 4bdae8a6faf..a18f225deb7 100644 --- a/src/test/resources/org/rust/lang/core/parser/fixtures/partial/no_lifetime_bounds_in_generic_args.txt +++ b/src/test/resources/org/rust/lang/core/parser/fixtures/partial/no_lifetime_bounds_in_generic_args.txt @@ -19,7 +19,7 @@ FILE PsiElement(<)('<') RsLifetimeImpl(LIFETIME) PsiElement(QUOTE_IDENTIFIER)(''static') - PsiErrorElement:'+', ',', '::', , , '>', QUOTE_IDENTIFIER, identifier or '{' expected, got ':' + PsiErrorElement:'+', ',', '::', , , , '>', QUOTE_IDENTIFIER or '{' expected, got ':' PsiElement(:)(':') PsiWhiteSpace(' ') diff --git a/src/test/resources/org/rust/lang/core/parser/fixtures/partial/paths.txt b/src/test/resources/org/rust/lang/core/parser/fixtures/partial/paths.txt index d426fa3b04f..ceb3ee93c49 100644 --- a/src/test/resources/org/rust/lang/core/parser/fixtures/partial/paths.txt +++ b/src/test/resources/org/rust/lang/core/parser/fixtures/partial/paths.txt @@ -192,7 +192,7 @@ FILE RsPathImpl(PATH) PsiElement(identifier)('bar') PsiElement(::)('::') - PsiErrorElement:'!', '(', '+', ',', '::', <, , , '>' or identifier expected, got '>' + PsiErrorElement:'(', ',', '::', <, , , '>' or identifier expected, got '>' PsiElement(>)('>') PsiElement(::)('::')