Repository: intellij-rust/intellij-rust
Issue: Autoimport prefers imports from private uses from a supermod

## Environment

* **IntelliJ Rust plugin version:** 0.4.176.4797-222-nightly
* **Rust toolchain version:** 1.62.1 (e092d0b6b 2022-07-16) x86_64-unknown-linux-gnu
* **IDE name and version:** IntelliJ IDEA 2022.2 Ultimate Edition (IU-222.3345.118)
* **Operating system:** Linux 5.15.0-43-generic
* **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

## Steps to reproduce
```rust
mod foo {
    pub struct Foo;
}

use foo::Foo;

mod bar {
    type T = Foo/*caret*/;
}
```

Then invoke autoimport at `type T = Foo`.

```rust
mod foo {
    pub struct Foo;
}

use foo::Foo;

mod bar {
    use crate::Foo;

    type T = Foo;
}
```

The plugin inserted `use crate::Foo` instead of `use crate::foo::Foo;`

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

diff --git a/src/main/kotlin/org/rust/ide/utils/import/ImportCandidatesCollector2.kt b/src/main/kotlin/org/rust/ide/utils/import/ImportCandidatesCollector2.kt
index a61fc0ff6..49b64d97e 100644
--- a/src/main/kotlin/org/rust/ide/utils/import/ImportCandidatesCollector2.kt
+++ b/src/main/kotlin/org/rust/ide/utils/import/ImportCandidatesCollector2.kt
@@ -274,7 +274,7 @@ private fun ImportContext2.checkVisibility(visItem: VisItem, modData: ModData):
     val visibility = visItem.visibility
     if (!visibility.isVisibleFromMod(rootModData)) return false
     if (visibility is Visibility.Restricted) {
-        val isPrivate = visibility.inMod == modData && !visibility.inMod.isCrateRoot
+        val isPrivate = visibility.inMod == modData
         val isExplicitlyDeclared = !visItem.isCrateRoot && visItem.containingMod == modData.path
         if (isPrivate && !isExplicitlyDeclared) {
             Testmarks.IgnorePrivateImportInParentMod.hit()
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 5197fe548..31732d761 100644
--- a/src/test/kotlin/org/rust/ide/inspections/import/AutoImportFixTest.kt
+++ b/src/test/kotlin/org/rust/ide/inspections/import/AutoImportFixTest.kt
@@ -518,6 +518,35 @@ class AutoImportFixTest : AutoImportFixTestBase() {
         }
     """)
 
+    @CheckTestmarkHit(Testmarks.IgnorePrivateImportInParentMod::class)
+    fun `test don't try to import private reexport from crate root`() = checkAutoImportFixByText("""
+        use mod1::func;
+
+        mod mod1 {
+            pub fn func() {}
+        }
+
+        mod inner {
+            fn test() {
+                /*error descr="Unresolved reference: `func`"*//*caret*/func/*error**/();
+            }
+        }
+    """, """
+        use mod1::func;
+
+        mod mod1 {
+            pub fn func() {}
+        }
+
+        mod inner {
+            use crate::mod1::func;
+
+            fn test() {
+                func();
+            }
+        }
+    """)
+
     fun `test complex module structure`() = checkAutoImportFixByText("""
         mod aaa {
             mod bbb {