Repository: intellij-rust/intellij-rust
Issue: Documentation/auto-complete not working for enabled features of crates

<!--
Hello and thank you for the issue!
If you would like to report a bug, we have added some points below that you can fill out.
Consider using "Help | Create New Issue" action that fills out all necessary information automatically.
Feel free to remove all the irrelevant text to request a new feature.
-->

## Environment

* **IntelliJ Rust plugin version:** 0.4.162.4321-213
* **Rust toolchain version:** 1.57.0
* **IDE name and version:** CLion 2021.3.2
* **Operating system:** Windows 10

## Problem description

When I enable a feature of a crate in Cargo.toml (e.g. `thisCrate = {version = "0.1.0", features = ["thisFeature"]}`), new types that the enabled feature provide do not have any documentation or code completion. 

## Steps to reproduce

1. Create new rust binary project.
2. In Cargo.toml, under `[dependencies]`, add the following:
```rust
rand = "0.8.4"
p256 = {version = "0.10.0", features = ["ecdsa"]}
```
3. Build the project
4. In `main.rs`, in the `main` function, *type* the following:
```rust
let key = p256::ecdsa::SigningKey::random(&mut rand::thread_rng());
```
While typing, notice that typing `p256` provides autocomplete. Adding `::` Shows more code completion options, but beginning to type `ecdsa` does not provide autocomplete. Similar when typing `::SigningKey::random`. When finished typing this line, hover over the various words. Hovering over `p256`, `rand`, and `thread_rng` show documentation, but hovering over `ecdsa`, `SigningKey`, and `random` do not have documentation. Furthermore, the variable `key`'s type is not known by the IDE.

These problems do not present using rust-analyzer.

Changed files:
src/main/kotlin/org/rust/cargo/project/workspace/CargoWorkspace.kt, src/test/kotlin/org/rustSlowTests/lang/resolve/CargoProjectResolveTest.kt

diff --git a/src/main/kotlin/org/rust/cargo/project/workspace/CargoWorkspace.kt b/src/main/kotlin/org/rust/cargo/project/workspace/CargoWorkspace.kt
index 2e75192d6..d8d21babf 100644
--- a/src/main/kotlin/org/rust/cargo/project/workspace/CargoWorkspace.kt
+++ b/src/main/kotlin/org/rust/cargo/project/workspace/CargoWorkspace.kt
@@ -648,7 +648,8 @@ private fun PackageImpl.addDependencies(workspaceData: CargoWorkspaceData, packa
             dep.depKinds,
             rawDeps.any { it.optional },
             rawDeps.any { it.uses_default_features },
-            rawDeps.flatMap { it.features }.toSet()
+            rawDeps.flatMap { it.features }.toSet(),
+            rawDeps.firstOrNull()?.rename ?: dependencyPackage.name
         )
     }
 }
@@ -678,13 +679,20 @@ private class DependencyImpl(
     override val depKinds: List<CargoWorkspace.DepKindInfo>,
     val isOptional: Boolean = false,
     val areDefaultFeaturesEnabled: Boolean = true,
-    override val requiredFeatures: Set<String> = emptySet()
+    override val requiredFeatures: Set<String> = emptySet(),
+    override val cargoFeatureDependencyPackageName: String = if (name == pkg.libTarget?.normName) pkg.name else name
 ) : CargoWorkspace.Dependency {
-    override val cargoFeatureDependencyPackageName: String
-        get() = if (name == pkg.libTarget?.normName) pkg.name else name
 
     fun withPackage(newPkg: PackageImpl): DependencyImpl =
-        DependencyImpl(newPkg, name, depKinds, isOptional, areDefaultFeaturesEnabled, requiredFeatures)
+        DependencyImpl(
+            newPkg,
+            name,
+            depKinds,
+            isOptional,
+            areDefaultFeaturesEnabled,
+            requiredFeatures,
+            cargoFeatureDependencyPackageName
+        )
 
     override fun toString(): String = name
 }
diff --git a/src/test/kotlin/org/rustSlowTests/lang/resolve/CargoProjectResolveTest.kt b/src/test/kotlin/org/rustSlowTests/lang/resolve/CargoProjectResolveTest.kt
index b55143807..662d19da4 100644
--- a/src/test/kotlin/org/rustSlowTests/lang/resolve/CargoProjectResolveTest.kt
+++ b/src/test/kotlin/org/rustSlowTests/lang/resolve/CargoProjectResolveTest.kt
@@ -17,7 +17,6 @@ import org.rust.*
 import org.rust.cargo.RsWithToolchainTestBase
 import org.rust.cargo.project.model.cargoProjects
 import org.rust.cargo.project.model.impl.testCargoProjects
-import org.rust.cargo.project.settings.toolchain
 import org.rust.lang.core.crate.impl.CrateGraphTestmarks
 import org.rust.lang.core.psi.RsPath
 import org.rust.lang.core.resolve.NameResolutionTestmarks
@@ -711,16 +710,16 @@ class CargoProjectResolveTest : RsWithToolchainTestBase() {
                 edition = "2018"
 
                 [features]
-                foo_feature = ["bar_renamed/bar_feature"]
+                foo_feature = ["bar-renamed/bar_feature"]
 
-                [dependencies.bar_renamed]
+                [dependencies.bar-renamed]
                 package = "bar"
                 path = "../bar"
                 optional = true
             """)
             dir("src") {
                 rust("lib.rs", """
-                    #[cfg(feature="bar_renamed")]
+                    #[cfg(feature="bar-renamed")]
                     pub use bar_renamed::bar;
                 """)
             }
@@ -743,7 +742,7 @@ class CargoProjectResolveTest : RsWithToolchainTestBase() {
         }
     }.run {
         project.cargoProjects.singlePackage("foo").checkFeatureEnabled("foo_feature")
-        project.cargoProjects.singlePackage("foo").checkFeatureEnabled("bar_renamed")
+        project.cargoProjects.singlePackage("foo").checkFeatureEnabled("bar-renamed")
         project.cargoProjects.singlePackage("bar").checkFeatureEnabled("bar_feature")
         checkReferenceIsResolved<RsPath>("src/main.rs")
     }