Repository: intellij-rust/intellij-rust
Issue: New Name Resolution Not Working With The Windows Crate

<!--
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.3.143.3737-203
* **Rust toolchain version:** 1.50.0 (cb75ad5db 2021-02-10) x86_64-pc-windows-msvc
* **IDE name and version:** CLion 2020.3.2 (CL-203.7148.70)
* **Operating system:** Windows 10 10.0
* **Macro expansion engine:** new
* **Name resolution engine:** new

## Problem description

With the new name resolution turned on, the resolution for the [`windows`](https://github.com/microsoft/windows-rs) crate is broken (this isn't the case with the old one).

## Steps to reproduce

0. Enable the new resolution engine
1. Create a new rust project
2. Use the [simple example](https://github.com/microsoft/windows-rs/tree/master/examples/simple) (except replace the dependencies to `windows = "0.6"`)
3. Build or run the project (to generate binding-files)
4. Optionally refresh the project (this should be done in step 3 - just to be sure)

Now in `main.rs` the `use bindings::windows::ui::Colors;` import isn't highlighted. To verify, turn off the new engine and reload the project.

Changed files:
src/test/kotlin/org/rust/lang/core/resolve/RsPackageLibraryResolveTest.kt, src/main/kotlin/org/rust/lang/core/resolve2/FacadeResolve.kt

diff --git a/src/main/kotlin/org/rust/lang/core/resolve2/FacadeResolve.kt b/src/main/kotlin/org/rust/lang/core/resolve2/FacadeResolve.kt
index ad1732951..eb8e0cc5e 100644
--- a/src/main/kotlin/org/rust/lang/core/resolve2/FacadeResolve.kt
+++ b/src/main/kotlin/org/rust/lang/core/resolve2/FacadeResolve.kt
@@ -290,12 +290,19 @@ private fun getMacroIndexInParent(item: PsiElement, parent: PsiElement): Int {
 
 private val RsMacroCall.pathSegments: List<String>?
     get() {
-        val segments = generateSequence(path) { it.path }
-            .map { it.referenceName }
-            .toMutableList()
-        if (segments.any { it == null }) return null
+        val segments = mutableListOf<String>()
+        var path: RsPath? = path
+        while (path != null) {
+            segments += path.referenceName ?: return null
+            val qualifier = path.path
+            if (qualifier == null && path.hasColonColon) {
+                // ::crate_name::macro!()
+                segments += ""
+            }
+            path = qualifier
+        }
         segments.reverse()
-        return segments.requireNoNulls()
+        return segments
     }
 
 /**
diff --git a/src/test/kotlin/org/rust/lang/core/resolve/RsPackageLibraryResolveTest.kt b/src/test/kotlin/org/rust/lang/core/resolve/RsPackageLibraryResolveTest.kt
index 52234e98f..fecaac44a 100644
--- a/src/test/kotlin/org/rust/lang/core/resolve/RsPackageLibraryResolveTest.kt
+++ b/src/test/kotlin/org/rust/lang/core/resolve/RsPackageLibraryResolveTest.kt
@@ -356,6 +356,19 @@ class RsPackageLibraryResolveTest : RsResolveTestBase() {
         }
     """)
 
+    @MockEdition(CargoWorkspace.Edition.EDITION_2018)
+    fun `test macro with absolute path`() = stubOnlyResolve("""
+    //- main.rs
+        mod test_package {}
+        ::test_package::foo!();
+                      //^ lib.rs
+        fn main() {}
+    //- lib.rs
+        #[macro_export]
+        macro_rules! foo { () => {} }
+                   //X
+    """)
+
     // Issue https://github.com/intellij-rust/intellij-rust/issues/3642
     fun `test issue 3642 1`() = stubOnlyResolve("""
     //- lib.rs