Skip to content

Commit

Permalink
Use processElementsWithMacros when resolving pattern binding
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
missingdays committed Jul 26, 2023
1 parent 8eb0ece commit b5c154b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/main/kotlin/org/rust/lang/core/resolve/NameResolution.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import com.intellij.psi.stubs.StubElement
import com.intellij.psi.util.CachedValue
import com.intellij.psi.util.CachedValueProvider
import com.intellij.psi.util.CachedValuesManager
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.util.ThreeState
import org.rust.cargo.project.workspace.CargoWorkspace
import org.rust.cargo.project.workspace.PackageOrigin
Expand Down Expand Up @@ -1517,12 +1516,22 @@ private fun processLexicalDeclarations(
alreadyProcessedNames.add(e.name) // Process element if it is not in the set
}

return PsiTreeUtil.findChildrenOfType(pattern, RsPatBinding::class.java).any { binding ->
val name = binding.name ?: return@any false
patternProcessor.lazy(name, VALUES) {
binding.takeIf { (it.parent is RsPatField || !it.isReferenceToConstant) && hygieneFilter(it) }
}
}
return !processElementsWithMacros(pattern) { binding ->
if (binding !is RsPatBinding) {
return@processElementsWithMacros TreeStatus.VISIT_CHILDREN
}

val name = binding.name ?: return@processElementsWithMacros TreeStatus.SKIP_CHILDREN
val result = patternProcessor.lazy(name, VALUES) {
binding.takeIf { (binding.parent is RsPatField || !binding.isReferenceToConstant) && hygieneFilter(binding) }
}

if (result) {
TreeStatus.ABORT
} else {
TreeStatus.SKIP_CHILDREN
}
}
}

fun processLetExprs(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1086,4 +1086,16 @@ class RsMacroExpansionResolveTest : RsResolveTestBase() {
foo! {}
}
""")

fun `test expansion in pattern context`() = checkByCode("""
macro_rules! var {
($ i:ident) => { $ i };
}
fn foo() {
let var!(a) = 1;
//X
a;
} //^
""")
}

0 comments on commit b5c154b

Please sign in to comment.