Repository: intellij-rust/intellij-rust
Issue: Import of enum variants, via crate::mymodule::* not working.

## Environment
* **IntelliJ Rust plugin version:**
0.2.110.2150-192
* **Rust toolchain version:**
stable-x86_64-unknown-linux-gnu (default)
rustc 1.39.0 (4560ea788 2019-11-04)
* **IDE name and version:**
IntelliJ IDEA 2019.2.4 (Community Edition)
Build #IC-192.7142.36, built on October 29, 2019
Runtime version: 11.0.4+10-b304.77 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
* **Operating system:**
Mint
Linux 4.15.0-66-generic

## Problem description
IDE highlights enum variant A as unknown/unimported, but rustc compiles the code without error.

## Steps to reproduce
1. Create a library rust project.
2. In file lib.rs put:
```rust
mod mymodule;
```
3. In file mymodule.rs put:
```rust
use Enum::*;

enum Enum {
    A
}

mod submodule {
    use crate::mymodule::*;

    fn foo() {
        A;
    }
}
```
4. Observe that A i highlighted red.
5. Observe that the project compiles successfully.

Changed files:
src/main/kotlin/org/rust/lang/core/resolve/NameResolution.kt, src/main/kotlin/org/rust/lang/core/resolve/ItemResolution.kt, src/test/kotlin/org/rust/lang/core/resolve/RsUseResolveTest.kt

diff --git a/src/main/kotlin/org/rust/lang/core/resolve/ItemResolution.kt b/src/main/kotlin/org/rust/lang/core/resolve/ItemResolution.kt
index 1ae9c3cff..fa3f06347 100644
--- a/src/main/kotlin/org/rust/lang/core/resolve/ItemResolution.kt
+++ b/src/main/kotlin/org/rust/lang/core/resolve/ItemResolution.kt
@@ -224,7 +224,7 @@ fun processItemDeclarations(
                     mod,
                     ns,
                     processor = shadowingProcessor,
-                    withPrivateImports = basePath != null && isSuperChain(basePath)
+                    withPrivateImports = basePath != null && withPrivateImports(basePath)
                 )
             }
         }, memoize = false)
diff --git a/src/main/kotlin/org/rust/lang/core/resolve/NameResolution.kt b/src/main/kotlin/org/rust/lang/core/resolve/NameResolution.kt
index 68d7d5ef5..bd8551798 100644
--- a/src/main/kotlin/org/rust/lang/core/resolve/NameResolution.kt
+++ b/src/main/kotlin/org/rust/lang/core/resolve/NameResolution.kt
@@ -367,12 +367,11 @@ private fun processQualifiedPathResolveVariants(
         }
         return false
     }
-    val isSuperChain = isSuperChain(qualifier)
     if (base is RsMod) {
         val s = base.`super`
         // `super` is allowed only after `self` and `super`
         // so we add `super` in completion only when it produces valid path
-        if (s != null && (!isCompletion || isSuperChain) && processor("super", s)) return true
+        if (s != null && (!isCompletion || isSuperChain(qualifier)) && processor("super", s)) return true
 
         val containingMod = path.containingMod
         if (Namespace.Macros in ns && base is RsFile && base.isCrateRoot &&
@@ -396,7 +395,7 @@ private fun processQualifiedPathResolveVariants(
 
     // Procedural macros definitions are functions, so they get added twice (once as macros, and once as items). To
     // avoid this, we exclude `MACROS` from passed namespaces
-    if (processItemOrEnumVariantDeclarations(base, ns - MACROS, processor, withPrivateImports = isSuperChain)) {
+    if (processItemOrEnumVariantDeclarations(base, ns - MACROS, processor, withPrivateImports = withPrivateImports(qualifier))) {
         return true
     }
 
@@ -1570,10 +1569,17 @@ private fun walkUp(
     return false
 }
 
-fun isSuperChain(path: RsPath): Boolean {
-    val qualifier = path.path
-    val referenceName = path.referenceName
-    return (referenceName == "super" || referenceName == "self" || referenceName == "crate") &&
+fun withPrivateImports(path: RsPath): Boolean {
+    if (path.basePath().kind == PathKind.CRATE) {
+        return true
+    }
+    return isSuperChain(path)
+}
+
+private fun isSuperChain(path: RsPath): Boolean {
+    val qualifier = path.qualifier
+    val pathKind = path.kind
+    return (pathKind == PathKind.SUPER || pathKind == PathKind.SELF) &&
         (qualifier == null || isSuperChain(qualifier))
 }
 
diff --git a/src/test/kotlin/org/rust/lang/core/resolve/RsUseResolveTest.kt b/src/test/kotlin/org/rust/lang/core/resolve/RsUseResolveTest.kt
index d519a0964..86fcfcef0 100644
--- a/src/test/kotlin/org/rust/lang/core/resolve/RsUseResolveTest.kt
+++ b/src/test/kotlin/org/rust/lang/core/resolve/RsUseResolveTest.kt
@@ -561,7 +561,7 @@ class RsUseResolveTest : RsResolveTestBase() {
         }                                   //^
     """)
 
-    fun `test private reexport with crate keyword`() = checkByCode("""
+    fun `test private reexport with crate keyword 1`() = checkByCode("""
         mod a {
             pub struct Foo;
         }            //X
@@ -573,6 +573,20 @@ class RsUseResolveTest : RsResolveTestBase() {
         }          //^
     """)
 
+    fun `test private reexport with crate keyword 2`() = checkByCode("""
+        mod root {
+            mod a {
+                pub struct Foo;
+            }            //X
+            use self::a::Foo;
+            mod b {
+                use crate::root::Foo;
+
+                type T = Foo;
+            }          //^
+        }
+    """)
+
     fun `test can't import methods`() = checkByCode("""
         mod m {
             pub enum E {}