Skip to content

Commit

Permalink
Merge #9107
Browse files Browse the repository at this point in the history
9107: RES: Fix propagation of `include!`-ed macros to child modules r=vlad20012 a=dima74

Fixes #8559

changelog: Fix resolve of macros declared in `include!`-ed files in some cases


Co-authored-by: Dmitry Murzin <diralik@yandex.ru>
  • Loading branch information
bors[bot] and dima74 committed Jul 23, 2022
2 parents b613dfb + e8d608f commit 5aa5c86
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
Expand Up @@ -407,7 +407,7 @@ class DefCollector(
val includingRsFile = includingFile?.toPsiFile(project)?.rustFile
if (includingRsFile != null) {
val context = getModCollectorContextForExpandedElements(call) ?: return
collectScope(includingRsFile, call.containingMod, context, call.macroIndex)
collectScope(includingRsFile, call.containingMod, context, call.macroIndex, propagateLegacyMacros = true)
} else if (!context.isHangingMode) {
val filePath = parentDirectory.pathAsPath.resolve(includePath)
defMap.missedFiles.add(filePath)
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/org/rust/lang/core/resolve2/ModCollector.kt
Expand Up @@ -58,12 +58,13 @@ fun collectScope(
context: ModCollectorContext,
modMacroIndex: MacroIndex = modData.macroIndex,
dollarCrateHelper: DollarCrateHelper? = null,
propagateLegacyMacros: Boolean = false,
): LegacyMacros {
val hashCalculator = HashCalculator(modData.isEnabledByCfgInner)
.takeIf { modData.isNormalCrate }

val collector = ModCollector(modData, context, modMacroIndex, hashCalculator, dollarCrateHelper)
collector.collectMod(scope.getOrBuildStub() ?: return emptyMap())
collector.collectMod(scope.getOrBuildStub() ?: return emptyMap(), propagateLegacyMacros)

if (hashCalculator != null && scope is RsFile) {
val fileHash = hashCalculator.getFileHash()
Expand Down
Expand Up @@ -218,6 +218,16 @@ class RsIncludeMacroResolveTest : RsResolveTestBase() {
gen_use!();
""")

fun `test macro def in included file`() = checkResolve("""
//- main.rs
include!("foo.rs");
mod other {
foo!();
} //^ foo.rs
//- foo.rs
macro_rules! foo { () => {} }
""")

fun `test concat in include 1`() = checkResolve("""
//- main.rs
include!(concat!("foo.rs"));
Expand Down

0 comments on commit 5aa5c86

Please sign in to comment.