Skip to content

Commit

Permalink
#7016: Fix control flow of break/continue expanded from a macro
Browse files Browse the repository at this point in the history
  • Loading branch information
artemmukhin committed Mar 24, 2021
1 parent 23ab684 commit 8164858
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/kotlin/org/rust/lang/core/dfa/CFGBuilder.kt
Expand Up @@ -135,7 +135,7 @@ class CFGBuilder(
}
} else {
// otherwise, try to find the corresponding loop
val exprBlock = expr.ancestors.filterIsInstance<RsLooplikeExpr>().firstOrNull()?.block
val exprBlock = expr.contexts.filterIsInstance<RsLooplikeExpr>().firstOrNull()?.block

for ((loop, continueNode, breakNode) in loopScopes) {
if (loop.block == exprBlock) {
Expand Down
26 changes: 26 additions & 0 deletions src/test/kotlin/org/rust/lang/core/dfa/RsControlFlowGraphTest.kt
Expand Up @@ -1066,6 +1066,32 @@ class RsControlFlowGraphTest : RsTestBase() {
Termination
""")

fun `test break expanded from macro`() = testCFG("""
macro_rules! break_macro {
() => { break };
}
fn main() {
1;
loop {
break_macro!();
}
2;
}
""", """
Entry
1
1;
Dummy
break
LOOP
LOOP;
2
2;
BLOCK
Exit
Termination
""")

private fun testCFG(@Language("Rust") code: String, expectedIndented: String) {
InlineFile(code)
val function = myFixture.file.descendantsOfType<RsFunction>().firstOrNull() ?: return
Expand Down

0 comments on commit 8164858

Please sign in to comment.