Repository: intellij-rust/intellij-rust
Issue: The plugin can't find items from generated impl blocks 

<!--
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.
Feel free to remove all the irrelevant text to request a new feature.
-->

## Environment

* **IntelliJ Rust plugin version:** 0.4.160.4218-212-nightly
* **Rust toolchain version:** 1.56.1 (59eed8a2a 2021-11-01) x86_64-apple-darwin
* **IDE name and version:** IntelliJ IDEA 2021.2.3 Ultimate Edition (IU-212.5457.46)
* **Operating system:** macOS 10.15.6
* **Macro expansion engine:** new
* **Name resolution engine:** new

## Problem description
After #8012, the plugin stops navigating to items from `impl` blocks located in generated sources. Looks like changes from #8012 changed the scope of generated files so any code that uses index search with `GlobalSearchScope.allScope(project)` or `RsWithMacrosProjectScope` scopes doesn't process code from generated files

## Steps to reproduce
`src/main.rs`
```rust
include!(concat!(env!("OUT_DIR"), "/hello.rs"));

fn main() {
    Hello.hello();
}
```

`build.rs`
```rust
use std::{fs, path, env};

fn main() {
    let content = "\\
    pub struct Hello;
    impl Hello {
        pub fn hello(&self) {
            println!(\\"Hello!\\");
        }
    }
    ";

    let out_dir = env::var_os("OUT_DIR").unwrap();
    let path = path::Path::new(&out_dir).join("hello.rs");
    fs::write(&path, content).unwrap();
}
```


<!--
Please include as much of your codebase as needed to reproduce the error.
If the relevant files are large, please provide a link to a public repository or a [Gist](https://gist.github.com/).
-->

Changed files:
src/main/kotlin/org/rust/lang/core/indexing/RsIndexableSetContributor.kt
src/test/kotlin/org/rustSlowTests/lang/resolve/CargoGeneratedItemsResolveTest.kt
src/main/kotlin/org/rust/cargo/project/workspace/RsAdditionalLibraryRootsProvider.kt

diff --git a/src/main/kotlin/org/rust/cargo/project/workspace/RsAdditionalLibraryRootsProvider.kt b/src/main/kotlin/org/rust/cargo/project/workspace/RsAdditionalLibraryRootsProvider.kt
index a20fd7380..5ab9e49bc 100644
--- a/src/main/kotlin/org/rust/cargo/project/workspace/RsAdditionalLibraryRootsProvider.kt
+++ b/src/main/kotlin/org/rust/cargo/project/workspace/RsAdditionalLibraryRootsProvider.kt
@@ -47,8 +47,25 @@ class CargoLibrary(
     override fun getPresentableText(): String = if (version != null) "$name $version" else name
 }
 
+class GeneratedCodeFakeLibrary(private val sourceRoots: Set<VirtualFile>) : SyntheticLibrary() {
+    override fun equals(other: Any?): Boolean {
+        return other is GeneratedCodeFakeLibrary && other.sourceRoots == sourceRoots
+    }
+
+    override fun hashCode(): Int = sourceRoots.hashCode()
+    override fun getSourceRoots(): Collection<VirtualFile> = sourceRoots
+    override fun isShowInExternalLibrariesNode(): Boolean = false
+
+    companion object {
+        fun create(cargoProject: CargoProject): GeneratedCodeFakeLibrary? {
+            val generatedRoots = cargoProject.workspace?.packages.orEmpty().mapNotNullTo(HashSet()) { it.outDir }
+            return if (generatedRoots.isEmpty()) null else GeneratedCodeFakeLibrary(generatedRoots)
+        }
+    }
+}
+
 class RsAdditionalLibraryRootsProvider : AdditionalLibraryRootsProvider() {
-    override fun getAdditionalProjectLibraries(project: Project): Collection<CargoLibrary> {
+    override fun getAdditionalProjectLibraries(project: Project): Collection<SyntheticLibrary> {
         checkReadAccessAllowed()
         return project.cargoProjects.allProjects
             .smartFlatMap { it.ideaLibraries }
@@ -65,7 +82,7 @@ private fun <U, V> Collection<U>.smartFlatMap(transform: (U) -> Collection<V>):
         else -> this.flatMap(transform)
     }
 
-private val CargoProject.ideaLibraries: Collection<CargoLibrary>
+private val CargoProject.ideaLibraries: Collection<SyntheticLibrary>
     get() {
         val workspace = workspace ?: return emptyList()
         val stdlibPackages = mutableListOf<CargoWorkspace.Package>()
@@ -83,6 +100,7 @@ private val CargoProject.ideaLibraries: Collection<CargoLibrary>
             for (pkg in dependencyPackages) {
                 pkg.toCargoLibrary()?.let(this::add)
             }
+            GeneratedCodeFakeLibrary.create(this@ideaLibraries)?.let(::add)
         }
     }
 
diff --git a/src/main/kotlin/org/rust/lang/core/indexing/RsIndexableSetContributor.kt b/src/main/kotlin/org/rust/lang/core/indexing/RsIndexableSetContributor.kt
index edc6d0a88..92ef0f4d4 100644
--- a/src/main/kotlin/org/rust/lang/core/indexing/RsIndexableSetContributor.kt
+++ b/src/main/kotlin/org/rust/lang/core/indexing/RsIndexableSetContributor.kt
@@ -8,7 +8,6 @@ package org.rust.lang.core.indexing
 import com.intellij.openapi.project.Project
 import com.intellij.openapi.vfs.VirtualFile
 import com.intellij.util.indexing.IndexableSetContributor
-import org.rust.cargo.project.model.cargoProjects
 import org.rust.lang.core.macros.macroExpansionManagerIfCreated
 
 class RsIndexableSetContributor : IndexableSetContributor() {
@@ -17,9 +16,6 @@ class RsIndexableSetContributor : IndexableSetContributor() {
     override fun getAdditionalProjectRootsToIndex(project: Project): Set<VirtualFile> {
         val additionalProjectRootsToIndex = hashSetOf<VirtualFile>()
 
-        project.cargoProjects.allProjects.forEach { cargoProject ->
-            cargoProject.workspace?.packages.orEmpty().mapNotNullTo(additionalProjectRootsToIndex) { it.outDir }
-        }
         project.macroExpansionManagerIfCreated?.indexableDirectory?.let {
             additionalProjectRootsToIndex += it
         }
diff --git a/src/test/kotlin/org/rustSlowTests/lang/resolve/CargoGeneratedItemsResolveTest.kt b/src/test/kotlin/org/rustSlowTests/lang/resolve/CargoGeneratedItemsResolveTest.kt
index ccd23a363..969f8370f 100644
--- a/src/test/kotlin/org/rustSlowTests/lang/resolve/CargoGeneratedItemsResolveTest.kt
+++ b/src/test/kotlin/org/rustSlowTests/lang/resolve/CargoGeneratedItemsResolveTest.kt
@@ -12,6 +12,7 @@ import org.intellij.lang.annotations.Language
 import org.rust.WithExperimentalFeatures
 import org.rust.fileTree
 import org.rust.ide.experiments.RsExperiments
+import org.rust.lang.core.psi.RsMethodCall
 import org.rust.lang.core.psi.RsPath
 import org.rustSlowTests.cargo.runconfig.RunConfigurationTestBase
 
@@ -791,6 +792,46 @@ class CargoGeneratedItemsResolveTest : RunConfigurationTestBase() {
         }.checkReferenceIsResolved<RsPath>("intellij-rust-test-2/src/main.rs", toFile = ".../hello.rs")
     }
 
+    // https://github.com/intellij-rust/intellij-rust/issues/8057
+    fun `test generated impl block`() {
+        buildProject {
+            toml("Cargo.toml", """
+                [package]
+                name = "intellij-rust-test"
+                version = "0.1.0"
+                authors = []
+            """)
+
+            dir("src") {
+                rust("main.rs", """
+                    include!(concat!(env!("OUT_DIR"), "/hello.rs"));
+
+                    fn main() {
+                        Hello.hello();
+                    }          //^
+                """)
+            }
+            rust("build.rs", """
+                use std::{fs, path, env};
+
+                fn main() {
+                    let content = "\\
+                    pub struct Hello;
+                    impl Hello {
+                        pub fn hello(&self) {
+                            println!(\\"Hello!\\");
+                        }
+                    }
+                    ";
+
+                    let out_dir = env::var_os("OUT_DIR").unwrap();
+                    let path = path::Path::new(&out_dir).join("hello.rs");
+                    fs::write(&path, content).unwrap();
+                }
+            """)
+        }.checkReferenceIsResolved<RsMethodCall>("src/main.rs", toFile = ".../hello.rs")
+    }
+
     companion object {
         @Language("Rust")
         private const val MAIN_RS = """