Skip to content

Commit

Permalink
RES: resolve derive proc macros in with new resolve engine
Browse files Browse the repository at this point in the history
  • Loading branch information
vlad20012 committed Dec 15, 2020
1 parent 77c4fd6 commit cd9cf30
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/main/kotlin/org/rust/lang/core/psi/ext/RsMetaItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ val RsMetaItem.value: String? get() = litExpr?.stringValue
val RsMetaItem.hasEq: Boolean get() = greenStub?.hasEq ?: (eq != null)

fun RsMetaItem.resolveToDerivedTrait(): RsTraitItem? =
path?.reference?.resolve() as? RsTraitItem
path?.reference?.multiResolve()?.filterIsInstance<RsTraitItem>()?.singleOrNull()

/**
* In the case of `#[foo(bar)]`, the `foo(bar)` meta item is considered "root" but `bar` is not.
Expand Down
12 changes: 5 additions & 7 deletions src/main/kotlin/org/rust/lang/core/resolve2/FacadeResolve.kt
Original file line number Diff line number Diff line change
Expand Up @@ -336,18 +336,16 @@ private fun VisItem.toPsi(defMap: CrateDefMap, project: Project, ns: Namespace):
return when (containingModOrEnum) {
is RsMod -> {
if (ns == Namespace.Macros) {
val macros = containingModOrEnum.expandedItemsCached.macros
val items = containingModOrEnum.expandedItemsCached
val macros = items.macros
.filter { it.name == name && matchesIsEnabledByCfg(it, this) }
// TODO: Multiresolve for macro 2.0
if (macros.isNotEmpty()) return listOf(macros.last())

containingModOrEnum
// Note: name of bang and attribute proc macros is same as name of item
.getExpandedItemsWithName<RsFunction>(name)
items.rest
.filterIsInstance<RsFunction>()
.filter {
// TODO: derive proc macros are currently ignored, because of multiresolve of serde::Serialize
val isProcMacro = it.isBangProcMacroDef || it.isAttributeProcMacroDef
isProcMacro && matchesIsEnabledByCfg(it, this)
it.isProcMacroDef && it.procMacroName == name && matchesIsEnabledByCfg(it, this)
}
} else {
containingModOrEnum
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package org.rust.lang.core.resolve

import org.rust.IgnoreInNewResolve
import org.rust.MockEdition
import org.rust.ProjectDescriptor
import org.rust.WithDependencyRustProjectDescriptor
Expand Down Expand Up @@ -127,7 +126,6 @@ class RsProcMacroResolveTest : RsResolveTestBase() {
""")
}

@IgnoreInNewResolve
fun `test resolve custom derive proc macro in use item`() = stubOnlyResolve("""
//- dep-proc-macro/lib.rs
#[proc_macro_derive(ProcMacroName)]
Expand All @@ -137,7 +135,6 @@ class RsProcMacroResolveTest : RsResolveTestBase() {
//^ dep-proc-macro/lib.rs
""")

@IgnoreInNewResolve
fun `test resolve custom derive proc macro from derive attribute`() = stubOnlyResolve("""
//- dep-proc-macro/lib.rs
#[proc_macro_derive(ProcMacroName)]
Expand Down Expand Up @@ -189,7 +186,6 @@ class RsProcMacroResolveTest : RsResolveTestBase() {
//^ dep-proc-macro/lib.rs
""")

@IgnoreInNewResolve
fun `test resolve custom derive proc macro reexported from lib to main from use item`() = stubOnlyResolve("""
//- lib.rs
extern crate dep_proc_macro;
Expand All @@ -204,7 +200,6 @@ class RsProcMacroResolveTest : RsResolveTestBase() {
//^ dep-proc-macro/lib.rs
""")

@IgnoreInNewResolve
fun `test resolve custom derive proc macro reexported from lib to main from macro call`() = stubOnlyResolve("""
//- lib.rs
extern crate dep_proc_macro;
Expand Down

0 comments on commit cd9cf30

Please sign in to comment.