From 5918d04d7f51899a1d0ee89f54d9ab08ffe78ccd Mon Sep 17 00:00:00 2001 From: Arseniy Pendryak Date: Sun, 28 Apr 2019 00:37:56 +0300 Subject: [PATCH] INSP: drop RsAnchoredPathsInspection Finally, uniform path was chosen instead of anchored paths (see https://github.com/rust-lang/rust/issues/55618), so we don't need inspection related to anchored paths --- .../inspections/RsAnchoredPathsInspection.kt | 47 ---------- src/main/resources/META-INF/plugin.xml | 5 -- .../RsAnchoredPaths.html | 8 -- .../RsAnchoredPathsInspectionTest.kt | 86 ------------------- 4 files changed, 146 deletions(-) delete mode 100644 src/main/kotlin/org/rust/ide/inspections/RsAnchoredPathsInspection.kt delete mode 100644 src/main/resources/inspectionDescriptions/RsAnchoredPaths.html delete mode 100644 src/test/kotlin/org/rust/ide/inspections/RsAnchoredPathsInspectionTest.kt diff --git a/src/main/kotlin/org/rust/ide/inspections/RsAnchoredPathsInspection.kt b/src/main/kotlin/org/rust/ide/inspections/RsAnchoredPathsInspection.kt deleted file mode 100644 index 6c7a0eb75bb..00000000000 --- a/src/main/kotlin/org/rust/ide/inspections/RsAnchoredPathsInspection.kt +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Use of this source code is governed by the MIT license that can be - * found in the LICENSE file. - */ - -package org.rust.ide.inspections - -import com.intellij.codeInspection.ProblemsHolder -import com.intellij.psi.PsiElementVisitor -import org.rust.ide.inspections.fixes.AddCrateKeywordFix -import org.rust.lang.core.psi.* -import org.rust.lang.core.psi.ext.RsMod -import org.rust.lang.core.psi.ext.basePath -import org.rust.lang.core.psi.ext.isEdition2018 -import org.rust.lang.core.psi.ext.qualifier - -class RsAnchoredPathsInspection : RsLocalInspectionTool() { - - override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor = object : RsVisitor() { - override fun visitPath(path: RsPath) { - val parent = path.parent - if (path.isEdition2018 && parent is RsUseSpeck && parent.qualifier == null) { - checkPathInUseItem(path, holder) - } - } - } - - private fun checkPathInUseItem(path: RsPath, holder: ProblemsHolder) { - val basePath = path.basePath() - basePath.node.findChildByType(tokenSetOf(RsElementTypes.IDENTIFIER, RsElementTypes.CSELF)) ?: return - - val element = basePath.reference.resolve() - if (element is RsMod && element.isCrateRoot) return - - val fixes = if (element != null && element.crateRoot == path.crateRoot && element.containingMod.isCrateRoot) { - arrayOf(AddCrateKeywordFix(path)) - } else { - emptyArray() - } - - holder.registerProblem( - path, - "Paths in `use` declarations should start with a crate name, or with `crate`, `super`, or `self`", - *fixes - ) - } -} diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index fff4fd29388..55288ef3764 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -500,11 +500,6 @@ enabledByDefault="true" level="ERROR" implementationClass="org.rust.ide.inspections.RsAssignToImmutableInspection"/> - - - -Checks that all paths in use items start with a crate name, or with crate, -super, or self.
- -Related to "anchored paths" variant in Edition 2018. - - diff --git a/src/test/kotlin/org/rust/ide/inspections/RsAnchoredPathsInspectionTest.kt b/src/test/kotlin/org/rust/ide/inspections/RsAnchoredPathsInspectionTest.kt deleted file mode 100644 index 9ade4574f05..00000000000 --- a/src/test/kotlin/org/rust/ide/inspections/RsAnchoredPathsInspectionTest.kt +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Use of this source code is governed by the MIT license that can be - * found in the LICENSE file. - */ - -package org.rust.ide.inspections - -import org.rust.cargo.project.workspace.CargoWorkspace -import org.rust.MockEdition - -@MockEdition(CargoWorkspace.Edition.EDITION_2018) -class RsAnchoredPathsInspectionTest : RsInspectionsTestBase(RsAnchoredPathsInspection()) { - - fun `test add crate keyword 1`() = checkFixByText("Add `crate` at the beginning of path", """ - mod foo { - pub struct Foo; - } - - use foo::Foo/*caret*/; - """, """ - mod foo { - pub struct Foo; - } - - use crate::foo::Foo/*caret*/; - """) - - fun `test add crate keyword 2`() = checkFixByText("Add `crate` at the beginning of path", """ - mod foo { - pub struct Foo; - } - - use ::foo::Foo/*caret*/; - """, """ - mod foo { - pub struct Foo; - } - - use crate::foo::Foo/*caret*/; - """) - - fun `test add crate keyword with use group`() = checkFixByText("Add `crate` at the beginning of path", """ - mod foo { - pub struct Foo; - pub struct Bar; - } - - use foo/*caret*/::{Foo, Bar}; - """, """ - mod foo { - pub struct Foo; - pub struct Bar; - } - - use crate::foo/*caret*/::{Foo, Bar}; - """) - - fun `test add crate keyword in use group`() = checkFixByText("Add `crate` at the beginning of path", """ - mod foo { - pub struct Foo; - } - - use {foo::Foo/*caret*/}; - """, """ - mod foo { - pub struct Foo; - } - - use {crate::foo::Foo/*caret*/}; - """) - - fun `test do not insert crate keyword for unknown items`() = checkFixIsUnavailable("Add `crate` at the beginning of path", """ - use foo::Foo/*caret*/; - """) - - fun `test do not insert crate keyword for`() = checkFixIsUnavailable("Add `crate` at the beginning of path", """ - mod bar { - pub mod foo { - pub struct Foo; - } - } - - use crate::bar::foo; - use foo::Foo/*caret*/; - """) -}