Repository: intellij-rust/intellij-rust
Issue: `Self::` prefix for enum breaks navigation

## Environment

* **IntelliJ Rust plugin version:** 0.2.117.2854-193-nightly
* **Rust toolchain version:** 1.41 stable
* **IDE name and version:** IntelliJ IDEA 2019.3.3 Ultimate
* **Operating system:** Windows 10 x64

## Problem description
If referring to an enum variant with a `Self::` prefix, IntelliJ cannot find it.

## Steps to reproduce

main.rs:

```rust
fn main() {
    let _ = Si7021Commands::MeasureTemperatureNoHold.as_bytes();
}

pub trait Command {
    fn as_bytes(&self) -> &[u8];
}

#[non_exhaustive]
enum Si7021Commands {
    MeasureHumidityNoHold,
    MeasureTemperatureNoHold,
}

impl Command for Si7021Commands {
    fn as_bytes(&self) -> &[u8] {
        match *self {
            Si7021Commands::MeasureHumidityNoHold => &[0xF5],
            Self::MeasureTemperatureNoHold => &[0xF3],
        }
    }
}
```

This compiles fine.

Ctrl-clicking `MeasureHumidityNoHold` in the match takes caret to its declaration in the enum.

Ctrl-clicking `MeasureTemperatureNoHold` gives error "Cannot find declaration to go to".

(I was also making a repro for a bug with `#[non_exhaustive]` but it was already reported as #4896)

Changed files:
src/test/kotlin/org/rust/lang/core/completion/RsCompletionTest.kt, src/main/kotlin/org/rust/lang/core/resolve/ItemResolution.kt, src/test/kotlin/org/rust/lang/core/resolve/RsResolveTest.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 f88ea37eb..af0a6317e 100644
--- a/src/main/kotlin/org/rust/lang/core/resolve/ItemResolution.kt
+++ b/src/main/kotlin/org/rust/lang/core/resolve/ItemResolution.kt
@@ -36,6 +36,13 @@ fun processItemOrEnumVariantDeclarations(
                 if (processAllWithSubst(item.variants, subst, processor)) return true
             }
         }
+        is RsImplItem -> {
+            val (item, subst) = (scope.typeReference?.skipParens() as? RsBaseType)
+                ?.path?.reference?.advancedDeepResolve() ?: return false
+            if (item is RsEnumItem) {
+                if (processAllWithSubst(item.variants, subst, processor)) return true
+            }
+        }
         is RsEnumItem -> {
             if (processAll(scope.variants, processor)) return true
         }
diff --git a/src/test/kotlin/org/rust/lang/core/completion/RsCompletionTest.kt b/src/test/kotlin/org/rust/lang/core/completion/RsCompletionTest.kt
index ba19b8175..ad5a2a64c 100644
--- a/src/test/kotlin/org/rust/lang/core/completion/RsCompletionTest.kt
+++ b/src/test/kotlin/org/rust/lang/core/completion/RsCompletionTest.kt
@@ -490,6 +490,22 @@ class RsCompletionTest : RsCompletionTestBase() {
         }
     """)
 
+    fun `test complete enum variants after Self`() = doSingleCompletion("""
+        enum Expr { Unit, BinOp(Box<Expr>, Box<Expr>) }
+        impl Expr {
+            fn new() -> Self {
+                Self::B/*caret*/
+            }
+        }
+    """, """
+        enum Expr { Unit, BinOp(Box<Expr>, Box<Expr>) }
+        impl Expr {
+            fn new() -> Self {
+                Self::BinOp(/*caret*/)
+            }
+        }
+    """)
+
     fun `test should not complete for test functions`() = checkNoCompletion("""
         #[test]
         fn foobar() {}
diff --git a/src/test/kotlin/org/rust/lang/core/resolve/RsResolveTest.kt b/src/test/kotlin/org/rust/lang/core/resolve/RsResolveTest.kt
index e95477164..5c7aaaa3b 100644
--- a/src/test/kotlin/org/rust/lang/core/resolve/RsResolveTest.kt
+++ b/src/test/kotlin/org/rust/lang/core/resolve/RsResolveTest.kt
@@ -559,6 +559,14 @@ class RsResolveTest : RsResolveTestBase() {
         }
     """)
 
+    fun `test enum Self in impl block`() = checkByCode("""
+        enum E { X }
+               //X
+
+        impl E { fn foo() -> Self { Self::X }}
+                                        //^
+    """)
+
     fun `test enum variant 2`() = checkByCode("""
         enum E { X, Y(X) }
                     //^ unresolved