Skip to content

Commit 895e6a2

Browse files
bors[bot]Undin
andauthored
Merge #4667
4667: GRAM: fix type path parsing r=vlad20012 a=Undin After rust-lang/rust#43540 disambiguator `::` is allowed in "type" paths. But our grammar forbade it previously because it had been written before the corresponding changes in rustc. These changes fix the grammar. Also, they highlight redundant `::` in type paths and provide fix to remove it ![2019-11-21 11 25 22](https://user-images.githubusercontent.com/2539310/69320139-a5193b80-0c51-11ea-85ba-2ddfe0a41fcb.gif) Fixes #4430 Co-authored-by: Arseniy Pendryak <[email protected]>
2 parents 57f953a + a6db191 commit 895e6a2

File tree

17 files changed

+230
-115
lines changed

17 files changed

+230
-115
lines changed

src/main/grammars/RustParser.bnf

+25-25
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ File ::= [ SHEBANG_LINE ] InnerAttr* Items
112112
ExprCodeFragment ::= Expr?
113113
StmtCodeFragment ::= Stmt?
114114
TypeRefCodeFragment ::= TypeReference?
115-
PathWithColonsCodeFragment ::= PathGenericArgsWithColons?
116-
PathWithoutColonsCodeFragment ::= PathGenericArgsWithoutColons?
115+
ValuePathCodeFragment ::= ValuePathGenericArgs?
116+
TypePathCodeFragment ::= TypePathGenericArgs?
117117

118118
///////////////////////////////////////////////////////////////////////////////////////////////////
119119
// Attributes
@@ -194,20 +194,20 @@ TypeQual ::= '<' TypeReference [ as TraitRef] '>' '::' {
194194

195195
left PathSegment ::= '::' PathIdent PathTypeArguments? { elementType = Path }
196196

197-
private PathTypeArguments ::= <<isPathMode 'COLONS'>> ColonTypeArgumentList
198-
| <<isPathMode 'NO_COLONS '>> ( TypeArgumentList | PathParameters RetType? ) // Fn(i32) -> i32 sugar
197+
private PathTypeArguments ::= <<isPathMode 'VALUE'>> ColonTypeArgumentList
198+
| <<isPathMode 'TYPE'>> ( TypeArgumentList | PathParameters RetType? ) // Fn(i32) -> i32 sugar
199199

200200
TypeArgumentList ::= TypeArgumentListImpl {
201201
extends = "org.rust.lang.core.psi.ext.RsStubbedElementImpl<?>"
202202
stubClass = "org.rust.lang.core.stubs.RsPlaceholderStub"
203203
elementTypeFactory = "org.rust.lang.core.stubs.StubImplementationsKt.factory"
204204
}
205-
ColonTypeArgumentList ::= '::' TypeArgumentListImpl { elementType = TypeArgumentList }
205+
ColonTypeArgumentList ::= &'::' TypeArgumentListImpl { elementType = TypeArgumentList }
206206

207-
private TypeArgumentListImpl ::= '<' !'=' ( <<list_element Lifetime>>*
208-
<<list_element (!(identifier ('='|':')) !'>' TypeReference)>>*
209-
<<list_element (!'>' (BlockExpr | LitExpr | &('-' LitExpr) UnaryExpr))>>*
210-
<<list_element AssocTypeBinding>>*) '>' { pin = 2 }
207+
private TypeArgumentListImpl ::= '::'? '<' !'=' ( <<list_element Lifetime>>*
208+
<<list_element (!(identifier ('='|':')) !'>' TypeReference)>>*
209+
<<list_element (!'>' (BlockExpr | LitExpr | &('-' LitExpr) UnaryExpr))>>*
210+
<<list_element AssocTypeBinding>>*) '>' { pin = 3 }
211211
AssocTypeBinding ::= identifier (AssocTypeBindingType | AssocTypeBindingBound) {
212212
implements = [ "org.rust.lang.core.psi.ext.RsNameIdentifierOwner"
213213
"org.rust.lang.core.psi.ext.RsReferenceElement" ]
@@ -225,20 +225,20 @@ private AssocTypeBindingBound ::= ':' TypeBounds { pin = 1 }
225225
// a::b<T,U>::c<V,W>
226226
// std::Fn(V) -> W
227227
// std::Fn(V)
228-
PathGenericArgsWithoutColons ::= <<typeQuals 'ON' <<pathMode 'NO_COLONS' PathImpl>>>> { elementType = Path }
229-
PathGenericArgsWithoutColonsNoTypeQual ::= <<typeQuals 'OFF' <<pathMode 'NO_COLONS' PathImpl>>>> { elementType = Path }
228+
TypePathGenericArgs ::= <<typeQuals 'ON' <<pathMode 'TYPE' PathImpl>>>> { elementType = Path }
229+
TypePathGenericArgsNoTypeQual ::= <<typeQuals 'OFF' <<pathMode 'TYPE' PathImpl>>>> { elementType = Path }
230230

231231
// Paths without type arguments, for use declarations:
232232
// a::b::c
233-
PathWithoutTypes ::= <<typeQuals 'OFF' <<pathMode 'NO_TYPES' PathImpl>>>> { elementType = Path }
233+
PathWithoutTypeArgs ::= <<typeQuals 'OFF' <<pathMode 'NO_TYPE_ARGS' PathImpl>>>> { elementType = Path }
234234

235235
// Paths for expressions:
236236
// a::b::<T,U>::c
237-
PathGenericArgsWithColons ::= <<typeQuals 'ON' <<pathMode 'COLONS' PathImpl>>>> { elementType = Path }
238-
PathGenericArgsWithColonsNoTypeQual ::= <<typeQuals 'OFF' <<pathMode 'COLONS' PathImpl>>>> { elementType = Path }
237+
ValuePathGenericArgs ::= <<typeQuals 'ON' <<pathMode 'VALUE' PathImpl>>>> { elementType = Path }
238+
ValuePathGenericArgsNoTypeQual ::= <<typeQuals 'OFF' <<pathMode 'VALUE' PathImpl>>>> { elementType = Path }
239239

240240
// Path semantically constrained to resolve to a trait
241-
TraitRef ::= PathGenericArgsWithoutColonsNoTypeQual {
241+
TraitRef ::= TypePathGenericArgsNoTypeQual {
242242
extends = "org.rust.lang.core.psi.ext.RsStubbedElementImpl<?>"
243243
stubClass = "org.rust.lang.core.stubs.RsPlaceholderStub"
244244
elementTypeFactory = "org.rust.lang.core.stubs.StubImplementationsKt.factory"
@@ -253,7 +253,7 @@ Vis ::= crate | pub VisRestriction? {
253253
stubClass = "org.rust.lang.core.stubs.RsVisStub"
254254
elementTypeFactory = "org.rust.lang.core.stubs.StubImplementationsKt.factory"
255255
}
256-
VisRestriction ::= '(' in? PathWithoutTypes ')' {
256+
VisRestriction ::= '(' in? PathWithoutTypeArgs ')' {
257257
extends = "org.rust.lang.core.psi.ext.RsStubbedElementImpl<?>"
258258
stubClass = "org.rust.lang.core.stubs.RsPlaceholderStub"
259259
elementTypeFactory = "org.rust.lang.core.stubs.StubImplementationsKt.factory"
@@ -349,7 +349,7 @@ FnParameters ::= '(' !',' [ SelfParameter (',' | &')') ]
349349
LambdaParameters ::= '|' !',' [ <<comma_separated_list LambdaParameter>> ] '|'
350350

351351
FnTypeParameters ::= <<variadic_params_impl AnonParameter>>
352-
PathParameters ::= '(' [ <<comma_separated_list PathParameter>> ] ')' { pin = 1 }
352+
PathParameters ::= '::'? '(' [ <<comma_separated_list PathParameter>> ] ')' { pin = 2 }
353353

354354

355355
private meta variadic_params_impl ::= '(' [ <<param>> (',' <<param>>)* [ ',' '...'? ] ] ')' { pin = 1 }
@@ -496,8 +496,8 @@ PatBox ::= box Pat
496496
// }
497497
PatIdent ::= PatBinding [ '@' Pat ]
498498

499-
PatStruct ::= PathGenericArgsWithColonsNoTypeQual '{' PatField_with_recover* '..'? '}'
500-
PatTupleStruct ::= PathGenericArgsWithColonsNoTypeQual '(' SeqPat ')'
499+
PatStruct ::= ValuePathGenericArgsNoTypeQual '{' PatField_with_recover* '..'? '}'
500+
PatTupleStruct ::= ValuePathGenericArgsNoTypeQual '(' SeqPat ')'
501501

502502
// TODO: actual recover
503503
private Pat_with_recover ::= Pat (',' | &(')' | ']' | '..'))
@@ -561,7 +561,7 @@ UseItem ::= AttrsAndVis use UseSpeck ';' {
561561
// foo::bar::{self, foo};
562562
// foo::{};
563563
// ::foo::*;
564-
UseSpeck ::= PathWithoutTypes [ Alias | '::' UseSpeckProjection ]
564+
UseSpeck ::= PathWithoutTypeArgs [ Alias | '::' UseSpeckProjection ]
565565
| '::'? UseSpeckProjection {
566566
extends = "org.rust.lang.core.psi.ext.RsUseSpeckImplMixin"
567567
stubClass = "org.rust.lang.core.stubs.RsUseSpeckStub"
@@ -808,7 +808,7 @@ private TypeReferenceInner ::= ArrayType
808808
| ExplicitTraitType
809809
| TrivialBaseType
810810
// External rule to find the difference between `T` and `T+T`
811-
| <<baseOrTraitType PathGenericArgsWithoutColons ImplicitTraitType TraitType_upper>>
811+
| <<baseOrTraitType TypePathGenericArgs ImplicitTraitType TraitType_upper>>
812812
| MacroType
813813
| ForInType // FIXME O(2^n) for types like `for<'a> A<for<'b> B<for<'c> C<...>>>`
814814

@@ -889,7 +889,7 @@ ForInType ::= ForLifetimes (FnPointerType | TraitRef) {
889889
elementTypeFactory = "org.rust.lang.core.stubs.StubImplementationsKt.factory"
890890
}
891891

892-
BaseType ::= TrivialBaseTypeInner | PathGenericArgsWithoutColons {
892+
BaseType ::= TrivialBaseTypeInner | TypePathGenericArgs {
893893
implements = "org.rust.lang.core.psi.ext.RsTypeElement"
894894
extends = "org.rust.lang.core.psi.ext.RsStubbedElementImpl<?>"
895895
stubClass = "org.rust.lang.core.stubs.RsBaseTypeStub"
@@ -1070,7 +1070,7 @@ LambdaExpr ::= OuterAttr* [asyncBlock | static] move? LambdaParameters RetType?
10701070
elementTypeFactory = "org.rust.lang.core.stubs.StubImplementationsKt.factory"
10711071
}
10721072

1073-
StructLiteral ::= <<checkStructAllowed>> OuterAttr* PathGenericArgsWithColonsNoTypeQual StructLiteralBody {
1073+
StructLiteral ::= <<checkStructAllowed>> OuterAttr* ValuePathGenericArgsNoTypeQual StructLiteralBody {
10741074
implements = [ "org.rust.lang.core.psi.ext.RsOuterAttributeOwner" ]
10751075
elementTypeFactory = "org.rust.lang.core.stubs.StubImplementationsKt.factory"
10761076
}
@@ -1092,7 +1092,7 @@ private StructLiteralField_with_recover ::= StructLiteralField (',' | &'}') {
10921092

10931093
private StructLiteralField_recover ::= !(identifier | INTEGER_LITERAL | ',' | '}' | '..' | '#')
10941094

1095-
PathExpr ::= OuterAttr* PathGenericArgsWithColons {
1095+
PathExpr ::= OuterAttr* ValuePathGenericArgs {
10961096
implements = [ "org.rust.lang.core.psi.ext.RsOuterAttributeOwner" ]
10971097
elementTypeFactory = "org.rust.lang.core.stubs.StubImplementationsKt.factory"
10981098
}
@@ -1318,7 +1318,7 @@ Macro2 ::= AttrsAndVis MACRO_KW identifier ( Macro2FunctionLikeBody | Macro2Matc
13181318
private Macro2FunctionLikeBody ::= '(' MacroPatternContents ')' '{' MacroExpansionContents '}'
13191319
private Macro2MatchLikeBody ::= '{' (MacroCase ','?)* '}'
13201320

1321-
fake MacroCall ::= AttrsAndVis PathWithoutTypes '!' identifier? (
1321+
fake MacroCall ::= AttrsAndVis PathWithoutTypeArgs '!' identifier? (
13221322
MacroArgument | ExprMacroArgument | FormatMacroArgument | AssertMacroArgument |
13231323
VecMacroArgument | LogMacroArgument | IncludeMacroArgument | ConcatMacroArgument | EnvMacroArgument
13241324
) ';'? {

src/main/kotlin/org/rust/ide/annotator/RsErrorAnnotator.kt

+25-4
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,17 @@
66
package org.rust.ide.annotator
77

88
import com.intellij.codeInsight.daemon.impl.HighlightRangeExtension
9+
import com.intellij.codeInspection.ProblemHighlightType
910
import com.intellij.ide.annotator.AnnotatorBase
1011
import com.intellij.lang.annotation.AnnotationHolder
1112
import com.intellij.lang.annotation.AnnotationSession
1213
import com.intellij.openapi.util.Key
1314
import com.intellij.psi.PsiElement
1415
import com.intellij.psi.PsiFile
16+
import com.intellij.psi.util.PsiTreeUtil
1517
import org.rust.cargo.project.workspace.CargoWorkspace.Edition
1618
import org.rust.cargo.project.workspace.PackageOrigin
17-
import org.rust.ide.annotator.fixes.AddModuleFileFix
18-
import org.rust.ide.annotator.fixes.AddTurbofishFix
19-
import org.rust.ide.annotator.fixes.CreateLifetimeParameterFromUsageFix
20-
import org.rust.ide.annotator.fixes.MakePublicFix
19+
import org.rust.ide.annotator.fixes.*
2120
import org.rust.ide.refactoring.RsNamesValidator.Companion.RESERVED_LIFETIME_NAMES
2221
import org.rust.ide.utils.isCfgUnknown
2322
import org.rust.ide.utils.isEnabledByCfg
@@ -47,6 +46,8 @@ class RsErrorAnnotator : AnnotatorBase(), HighlightRangeExtension {
4746
override fun visitBaseType(o: RsBaseType) = checkBaseType(holder, o)
4847
override fun visitCondition(o: RsCondition) = checkCondition(holder, o)
4948
override fun visitConstant(o: RsConstant) = checkConstant(holder, o)
49+
override fun visitTypeArgumentList(o: RsTypeArgumentList) = checkTypeArgumentList(holder, o)
50+
override fun visitValueParameterList(o: RsValueParameterList) = checkValueParameterList(holder, o)
5051
override fun visitValueArgumentList(o: RsValueArgumentList) = checkValueArgumentList(holder, o)
5152
override fun visitStructItem(o: RsStructItem) = checkDuplicates(holder, o)
5253
override fun visitEnumItem(o: RsEnumItem) = checkEnumItem(holder, o)
@@ -563,6 +564,26 @@ class RsErrorAnnotator : AnnotatorBase(), HighlightRangeExtension {
563564
}
564565
}
565566

567+
private fun checkTypeArgumentList(holder: RsAnnotationHolder, args: RsTypeArgumentList) {
568+
checkRedundantColonColon(holder, args)
569+
}
570+
571+
private fun checkValueParameterList(holder: RsAnnotationHolder, args: RsValueParameterList) {
572+
checkRedundantColonColon(holder, args)
573+
}
574+
575+
private fun checkRedundantColonColon(holder: RsAnnotationHolder, args: RsElement) {
576+
// For some reason `::(i32) -> i32` in `Fn::(i32) -> i32` has `RsValueParameterList` instead of `RsTypeArgumentList`.
577+
// `RsValueParameterList` and `RsTypeArgumentList` shouldn't have common interfaces
578+
// So we have to use low level ASTNode API to avoid code duplication
579+
val coloncolon = args.node.findChildByType(RsElementTypes.COLONCOLON)?.psi ?: return
580+
// `::` is redundant only in types
581+
if (PsiTreeUtil.getParentOfType(args, RsTypeReference::class.java, RsTraitRef::class.java) == null) return
582+
val annotation = holder.createWeakWarningAnnotation(coloncolon, "Redundant `::`") ?: return
583+
annotation.highlightType = ProblemHighlightType.LIKE_UNUSED_SYMBOL
584+
annotation.registerFix(RemoveElementFix(coloncolon))
585+
}
586+
566587
private fun checkValueArgumentList(holder: RsAnnotationHolder, args: RsValueArgumentList) {
567588
val (expectedCount, variadic) = when (val parent = args.parent) {
568589
is RsCallExpr -> parent.expectedParamsCount()

src/main/kotlin/org/rust/ide/annotator/fixes/RemoveAttrFix.kt

+1-19
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,7 @@
55

66
package org.rust.ide.annotator.fixes
77

8-
import com.intellij.codeInspection.LocalQuickFixOnPsiElement
9-
import com.intellij.openapi.project.Project
10-
import com.intellij.psi.PsiElement
11-
import com.intellij.psi.PsiFile
128
import org.rust.lang.core.psi.ext.RsAttr
139
import org.rust.lang.core.psi.ext.name
1410

15-
class RemoveAttrFix(attr: RsAttr) : LocalQuickFixOnPsiElement(attr) {
16-
private val _text = run {
17-
val suffix = attr.metaItem.name?.let { " `$it`" } ?: ""
18-
19-
"Remove attribute$suffix"
20-
}
21-
22-
override fun getText() = _text
23-
override fun getFamilyName() = "Remove attribute"
24-
25-
override fun invoke(project: Project, file: PsiFile, startElement: PsiElement, endElement: PsiElement) {
26-
val attr = startElement as? RsAttr ?: return
27-
attr.delete()
28-
}
29-
}
11+
class RemoveAttrFix(attr: RsAttr) : RemoveElementFix(attr, "attribute" + (attr.metaItem.name?.let { " `$it`" } ?: ""))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Use of this source code is governed by the MIT license that can be
3+
* found in the LICENSE file.
4+
*/
5+
6+
package org.rust.ide.annotator.fixes
7+
8+
import com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement
9+
import com.intellij.openapi.editor.Editor
10+
import com.intellij.openapi.project.Project
11+
import com.intellij.psi.PsiElement
12+
import com.intellij.psi.PsiFile
13+
14+
open class RemoveElementFix(
15+
element: PsiElement,
16+
private val removingElementName: String = "`${element.text}`"
17+
) : LocalQuickFixAndIntentionActionOnPsiElement(element) {
18+
override fun getFamilyName(): String = "Remove"
19+
override fun getText(): String = "Remove $removingElementName"
20+
override fun invoke(project: Project, file: PsiFile, editor: Editor?, startElement: PsiElement, endElement: PsiElement) {
21+
startElement.delete()
22+
}
23+
}

src/main/kotlin/org/rust/ide/inspections/import/AutoImportFix.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ data class ImportContext private constructor(
677677
mod = element.containingMod,
678678
superMods = LinkedHashSet(element.containingMod.superMods),
679679
scope = RsWithMacrosScope(project, GlobalSearchScope.allScope(project)),
680-
pathParsingMode = PathParsingMode.NO_COLONS,
680+
pathParsingMode = PathParsingMode.TYPE,
681681
attributes = element.stdlibAttributes,
682682
namespaceFilter = { true }
683683
)
@@ -689,8 +689,8 @@ private val RsPath.pathParsingMode: PathParsingMode
689689
is RsPathExpr,
690690
is RsStructLiteral,
691691
is RsPatStruct,
692-
is RsPatTupleStruct -> PathParsingMode.COLONS
693-
else -> PathParsingMode.NO_COLONS
692+
is RsPatTupleStruct -> PathParsingMode.VALUE
693+
else -> PathParsingMode.TYPE
694694
}
695695
private val RsElement.stdlibAttributes: RsFile.Attributes
696696
get() = (crateRoot?.containingFile as? RsFile)?.attributes ?: RsFile.Attributes.NONE

src/main/kotlin/org/rust/lang/core/macros/FragmentKind.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ enum class FragmentKind(private val kind: String) {
4444
.enter_section_(adaptBuilder, 0, 0, null)
4545

4646
val parsed = when (this) {
47-
Path -> RustParser.PathGenericArgsWithColons(adaptBuilder, 0)
47+
Path -> RustParser.ValuePathGenericArgs(adaptBuilder, 0)
4848
Expr -> RustParser.Expr(adaptBuilder, 0, -1)
4949
Ty -> RustParser.TypeReference(adaptBuilder, 0)
5050
Pat -> RustParser.Pat(adaptBuilder, 0)

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

+26-17
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,21 @@ import org.rust.stdext.removeLast
2828
@Suppress("UNUSED_PARAMETER")
2929
object RustParserUtil : GeneratedParserUtilBase() {
3030
enum class PathParsingMode {
31-
/** `Foo::<i32>` */
32-
COLONS,
33-
/** `Foo<i32>` */
34-
NO_COLONS,
35-
/** `Foo` */
36-
NO_TYPES
31+
/**
32+
* Accepts paths like `Foo::<i32>`
33+
* Should be used to parse references to values
34+
*/
35+
VALUE,
36+
/**
37+
* Accepts paths like `Foo<i32>`, `Foo::<i32>`, Fn(i32) -> i32 and Fn::(i32) -> i32
38+
* Should be used to parse type and trait references
39+
*/
40+
TYPE,
41+
/**
42+
* Accepts paths like `Foo`
43+
* Should be used to parse paths where type args cannot be specified: `use` items, macro calls, etc.
44+
*/
45+
NO_TYPE_ARGS
3746
}
3847
enum class BinaryMode { ON, OFF }
3948
enum class MacroCallParsingMode(val semicolon: Boolean, val pin: Boolean, val forbidExprSpecialMacros: Boolean) {
@@ -61,22 +70,22 @@ object RustParserUtil : GeneratedParserUtilBase() {
6170
private val TYPE_QUAL_ALLOWED: Int = makeBitMask(2)
6271
private val STMT_EXPR_MODE: Int = makeBitMask(3)
6372

64-
private val PATH_COLONS: Int = makeBitMask(4)
65-
private val PATH_NO_COLONS: Int = makeBitMask(5)
66-
private val PATH_NO_TYPES: Int = makeBitMask(6)
73+
private val PATH_VALUE: Int = makeBitMask(4)
74+
private val PATH_TYPE: Int = makeBitMask(5)
75+
private val PATH_NO_TYPE_ARGS: Int = makeBitMask(6)
6776
private fun setPathMod(flags: Int, mode: PathParsingMode): Int {
6877
val flag = when (mode) {
69-
PathParsingMode.COLONS -> PATH_COLONS
70-
PathParsingMode.NO_COLONS -> PATH_NO_COLONS
71-
PathParsingMode.NO_TYPES -> PATH_NO_TYPES
78+
PathParsingMode.VALUE -> PATH_VALUE
79+
PathParsingMode.TYPE -> PATH_TYPE
80+
PathParsingMode.NO_TYPE_ARGS -> PATH_NO_TYPE_ARGS
7281
}
73-
return flags and (PATH_COLONS or PATH_NO_COLONS or PATH_NO_TYPES).inv() or flag
82+
return flags and (PATH_VALUE or PATH_TYPE or PATH_NO_TYPE_ARGS).inv() or flag
7483
}
7584

7685
private fun getPathMod(flags: Int): PathParsingMode = when {
77-
BitUtil.isSet(flags, PATH_COLONS) -> PathParsingMode.COLONS
78-
BitUtil.isSet(flags, PATH_NO_COLONS) -> PathParsingMode.NO_COLONS
79-
BitUtil.isSet(flags, PATH_NO_TYPES) -> PathParsingMode.NO_TYPES
86+
BitUtil.isSet(flags, PATH_VALUE) -> PathParsingMode.VALUE
87+
BitUtil.isSet(flags, PATH_TYPE) -> PathParsingMode.TYPE
88+
BitUtil.isSet(flags, PATH_NO_TYPE_ARGS) -> PathParsingMode.NO_TYPE_ARGS
8089
else -> error("Path parsing mode not set")
8190
}
8291

@@ -313,7 +322,7 @@ object RustParserUtil : GeneratedParserUtilBase() {
313322
val macroName = lookupSimpleMacroName(b)
314323
if (mode.forbidExprSpecialMacros && macroName in SPECIAL_EXPR_MACROS) return false
315324

316-
if (!RustParser.PathWithoutTypes(b, level + 1) || !consumeToken(b, EXCL)) {
325+
if (!RustParser.PathWithoutTypeArgs(b, level + 1) || !consumeToken(b, EXCL)) {
317326
return false
318327
}
319328

src/main/kotlin/org/rust/lang/core/psi/RsCodeFragment.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import com.intellij.psi.util.PsiTreeUtil
1717
import com.intellij.testFramework.LightVirtualFile
1818
import org.rust.lang.RsFileType
1919
import org.rust.lang.RsLanguage
20-
import org.rust.lang.core.parser.RustParserUtil
2120
import org.rust.lang.core.parser.RustParserUtil.PathParsingMode
21+
import org.rust.lang.core.parser.RustParserUtil.PathParsingMode.*
2222
import org.rust.lang.core.psi.ext.RsElement
2323
import org.rust.lang.core.psi.ext.RsInferenceContextOwner
2424
import org.rust.lang.core.psi.ext.RsMod
@@ -149,9 +149,9 @@ class RsPathCodeFragment(
149149
companion object {
150150
@JvmStatic
151151
private fun PathParsingMode.elementType() = when (this) {
152-
PathParsingMode.NO_COLONS -> RsCodeFragmentElementType.PATH_WITHOUT_COLONS
153-
PathParsingMode.COLONS -> RsCodeFragmentElementType.PATH_WITH_COLONS
154-
PathParsingMode.NO_TYPES -> error("NO_TYPES mode is not supported; use NO_COLONS")
152+
TYPE -> RsCodeFragmentElementType.TYPE_PATH_CODE_FRAGMENT
153+
VALUE -> RsCodeFragmentElementType.VALUE_PATH_CODE_FRAGMENT
154+
NO_TYPE_ARGS -> error("$NO_TYPE_ARGS mode is not supported; use $TYPE")
155155
}
156156
}
157157
}

0 commit comments

Comments
 (0)