Repository: intellij-rust/intellij-rust
Issue: "Import -> Item to Import" suggestion works incorrectly in nested module

Minimal example:
```rust
mod a {
    pub struct S;
}
mod b {
    pub struct S;
}
mod c {
    fn x() -> S {

    }
}
```
When I put the cursor on `S` inside `mod c`, press Alt + Enter, select "Import" and then select one of the items, the plugin puts the import statement in the top module:
```rust
use crate::a::S;

mod a {
    pub struct S;
}
mod b {
    pub struct S;
}
mod c {
    fn x() -> S {

    }
}
```
The expected behavior is to put the import statement inside `mod c`. The issue seems to reproduce only when multiple items are available and the "Item to Import" menu appears.

Changed files:
src/test/kotlin/org/rust/ide/inspections/import/AutoImportFixTest.kt, src/main/kotlin/org/rust/ide/inspections/import/AutoImportFix.kt

diff --git a/src/main/kotlin/org/rust/ide/inspections/import/AutoImportFix.kt b/src/main/kotlin/org/rust/ide/inspections/import/AutoImportFix.kt
index 653463da8..2ce981b12 100644
--- a/src/main/kotlin/org/rust/ide/inspections/import/AutoImportFix.kt
+++ b/src/main/kotlin/org/rust/ide/inspections/import/AutoImportFix.kt
@@ -66,11 +66,11 @@ class AutoImportFix(element: RsElement) : LocalQuickFixOnPsiElement(element), Hi
         project: Project,
         dataContext: DataContext,
         items: List<ImportCandidate>,
-        originalElement: RsElement
+        mod: RsMod
     ) {
         showItemsToImportChooser(project, dataContext, items) { selectedValue ->
             project.runWriteCommandAction {
-                originalElement.containingMod.importItem(selectedValue)
+                mod.importItem(selectedValue)
             }
         }
     }
diff --git a/src/test/kotlin/org/rust/ide/inspections/import/AutoImportFixTest.kt b/src/test/kotlin/org/rust/ide/inspections/import/AutoImportFixTest.kt
index 3e2264ec0..ffbaaded8 100644
--- a/src/test/kotlin/org/rust/ide/inspections/import/AutoImportFixTest.kt
+++ b/src/test/kotlin/org/rust/ide/inspections/import/AutoImportFixTest.kt
@@ -1342,4 +1342,54 @@ class AutoImportFixTest : AutoImportFixTestBase() {
             let f = Foo/*caret*/;
         }
     """)
+
+    fun `test import inside nested module`() = checkAutoImportFixByText("""
+        mod b {
+            pub struct S;
+        }
+        mod c {
+            fn x() -> <error descr="Unresolved reference: `S`">S/*caret*/</error> {
+
+            }
+        }
+    """, """
+        mod b {
+            pub struct S;
+        }
+        mod c {
+            use b::S;
+
+            fn x() -> S {
+
+            }
+        }
+    """)
+
+    fun `test import inside nested module with multiple choice`() = checkAutoImportFixByTextWithMultipleChoice("""
+        mod a {
+            pub struct S;
+        }
+        mod b {
+            pub struct S;
+        }
+        mod c {
+            fn x() -> <error descr="Unresolved reference: `S`">S/*caret*/</error> {
+
+            }
+        }
+    """, setOf("a::S", "b::S"), "b::S", """
+        mod a {
+            pub struct S;
+        }
+        mod b {
+            pub struct S;
+        }
+        mod c {
+            use b::S;
+
+            fn x() -> S {
+
+            }
+        }
+    """)
 }