Repository: intellij-rust/intellij-rust
Issue: Change signature refactoring may add unneeded import

## Environment

* **IntelliJ Rust plugin version:** 0.4.178.4836-222-nightly
* **Rust toolchain version:** 1.64.0-nightly (f9cba6374 2022-07-31) x86_64-unknown-linux-gnu
* **IDE name and version:** CLion 2022.2.1 (CL-222.3739.54)
* **Operating system:** Linux 5.18.16-zen1-1-zen
* **Macro expansion engine:** new
* **Name resolution engine:** new
* **Additional experimental features:** org.rust.cargo.emulate.terminal, org.rust.cargo.evaluate.build.scripts, org.rust.macros.proc

## Problem description
* Invoke "Change signature" refactoring on `func`
* Don't change anything and run the refactoring
* Observe added import `use crate::inner::Struct;`

## Steps to reproduce
```rust
mod inner {
    pub struct Struct {}
}

fn func(x: inner::Struct) {}
```


Changed files:
src/main/kotlin/org/rust/ide/refactoring/changeSignature/impl.kt, src/main/kotlin/org/rust/ide/utils/import/RsImportHelper.kt, src/test/kotlin/org/rust/ide/refactoring/RsChangeSignatureTest.kt

diff --git a/src/main/kotlin/org/rust/ide/refactoring/changeSignature/impl.kt b/src/main/kotlin/org/rust/ide/refactoring/changeSignature/impl.kt
index 22c98e4d7..82d439f7d 100644
--- a/src/main/kotlin/org/rust/ide/refactoring/changeSignature/impl.kt
+++ b/src/main/kotlin/org/rust/ide/refactoring/changeSignature/impl.kt
@@ -141,7 +141,7 @@ private fun changeArguments(
     }
     for (parameter in config.parameters) {
         val defaultValue = parameter.defaultValue.item ?: continue
-        RsImportHelper.importTypeReferencesFromElements(arguments, setOf(defaultValue))
+        RsImportHelper.importTypeReferencesFromElement(arguments, defaultValue)
     }
     val argumentsCopy = arguments.copy() as RsValueArgumentList
     val argumentsList = argumentsCopy.exprList
@@ -282,7 +282,7 @@ private fun PsiElement.collectSurroundingWhiteSpaceAndComments(): List<PsiElemen
 
 private fun importParameterTypes(descriptors: List<Parameter>, context: RsElement) {
     for (descriptor in descriptors) {
-        RsImportHelper.importTypeReferencesFromElements(context, setOf(descriptor.typeReference))
+        RsImportHelper.importTypeReferencesFromElement(context, descriptor.typeReference)
     }
 }
 
diff --git a/src/main/kotlin/org/rust/ide/utils/import/RsImportHelper.kt b/src/main/kotlin/org/rust/ide/utils/import/RsImportHelper.kt
index 9b749e35a..071ad1fa8 100644
--- a/src/main/kotlin/org/rust/ide/utils/import/RsImportHelper.kt
+++ b/src/main/kotlin/org/rust/ide/utils/import/RsImportHelper.kt
@@ -7,7 +7,6 @@ package org.rust.ide.utils.import
 
 import org.rust.ide.settings.RsCodeInsightSettings
 import org.rust.lang.core.psi.RsPath
-import org.rust.lang.core.psi.RsTypeReference
 import org.rust.lang.core.psi.RsVisitor
 import org.rust.lang.core.psi.ext.RsElement
 import org.rust.lang.core.psi.ext.RsQualifiedNamedElement
@@ -20,18 +19,15 @@ import org.rust.lang.core.types.emptySubstitution
 import org.rust.lang.core.types.infer.TypeVisitor
 import org.rust.lang.core.types.infer.substitute
 import org.rust.lang.core.types.normType
-import org.rust.lang.core.types.rawType
 import org.rust.lang.core.types.ty.*
 
 object RsImportHelper {
-    fun importTypeReferencesFromElements(
-        context: RsElement,
-        elements: Collection<RsElement>,
-        subst: Substitution = emptySubstitution,
-        useAliases: Boolean = true,
-        skipUnchangedDefaultTypeArguments: Boolean = true
-    ) {
-        val (toImport, _) = getTypeReferencesInfoFromElements(context, elements, subst, useAliases, skipUnchangedDefaultTypeArguments)
+
+    fun importTypeReferencesFromElement(context: RsElement, element: RsElement) =
+        importTypeReferencesFromElements(context, listOf(element))
+
+    private fun importTypeReferencesFromElements(context: RsElement, elements: Collection<RsElement>) {
+        val (toImport, _) = getTypeReferencesInfoFromElements(context, elements)
         importElements(context, toImport)
     }
 
@@ -84,11 +80,8 @@ object RsImportHelper {
     private fun getTypeReferencesInfoFromElements(
         context: RsElement,
         elements: Collection<RsElement>,
-        subst: Substitution,
-        useAliases: Boolean,
-        skipUnchangedDefaultTypeArguments: Boolean
     ): TypeReferencesInfo = getTypeReferencesInfo(context, elements) { ty, result ->
-        collectImportSubjectsFromTypeReferences(ty, subst, result, useAliases, skipUnchangedDefaultTypeArguments)
+        collectImportSubjectsFromTypeReferences(ty, result)
     }
 
     /**
@@ -115,10 +108,7 @@ object RsImportHelper {
 
     private fun collectImportSubjectsFromTypeReferences(
         context: RsElement,
-        subst: Substitution,
         result: MutableSet<RsQualifiedNamedElement>,
-        useAliases: Boolean,
-        skipUnchangedDefaultTypeArguments: Boolean
     ) {
         context.accept(object : RsVisitor() {
             override fun visitPath(path: RsPath) {
@@ -132,9 +122,6 @@ object RsImportHelper {
                 super.visitPath(path)
             }
 
-            override fun visitTypeReference(reference: RsTypeReference) =
-                collectImportSubjectsFromTy(reference.rawType, subst, result, useAliases, skipUnchangedDefaultTypeArguments)
-
             override fun visitElement(element: RsElement) =
                 element.acceptChildren(this)
         })
diff --git a/src/test/kotlin/org/rust/ide/refactoring/RsChangeSignatureTest.kt b/src/test/kotlin/org/rust/ide/refactoring/RsChangeSignatureTest.kt
index 6bab329f1..9be98d5cb 100644
--- a/src/test/kotlin/org/rust/ide/refactoring/RsChangeSignatureTest.kt
+++ b/src/test/kotlin/org/rust/ide/refactoring/RsChangeSignatureTest.kt
@@ -58,6 +58,20 @@ Cannot change signature of function with cfg-disabled parameters""")
         }
     """) {}
 
+    fun `test do not change anything 2`() = doTest("""
+        mod inner {
+            pub struct Struct {}
+        }
+
+        fn func/*caret*/(a: inner::Struct) {}
+    """, """
+        mod inner {
+            pub struct Struct {}
+        }
+
+        fn func(a: inner::Struct) {}
+    """) {}
+
     fun `test rename function reference`() = doTest("""
         fn foo/*caret*/() {}
         fn id<T>(t: T) {}