Skip to content

Commit e6f1edc

Browse files
committed
Rust: Conditional completion of match arm expression should now flow to next arm
1 parent 04f2062 commit e6f1edc

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

rust/ql/lib/codeql/rust/controlflow/internal/ControlFlowGraphImpl.qll

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,9 +507,12 @@ class MatchExprTree extends PostOrderTree instanceof MatchExpr {
507507
first(super.getArm(0).getPat(), succ) and
508508
completionIsNormal(c)
509509
or
510-
// Edge from a failed match/guard in one arm to the beginning of the next arm.
510+
// Edge from a failed pattern or guard in one arm to the beginning of the next arm.
511511
exists(int i |
512-
last(super.getArm(i), pred, c) and
512+
(
513+
last(super.getArm(i).getPat(), pred, c) or
514+
last(super.getArm(i).getGuard().getCondition(), pred, c)
515+
) and
513516
first(super.getArm(i + 1), succ) and
514517
c.(ConditionalCompletion).failed()
515518
)

rust/ql/test/library-tests/controlflow/Cfg.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,6 @@ edges
661661
| test.rs:297:18:297:18 | a | test.rs:297:24:297:24 | a | match |
662662
| test.rs:297:24:297:24 | a | test.rs:296:10:299:9 | [boolean(false)] MatchExpr | false |
663663
| test.rs:297:24:297:24 | a | test.rs:296:10:299:9 | [boolean(true)] MatchExpr | true |
664-
| test.rs:297:24:297:24 | a | test.rs:298:13:298:13 | WildcardPat | false |
665664
| test.rs:298:13:298:13 | WildcardPat | test.rs:298:18:298:22 | false | match |
666665
| test.rs:298:18:298:22 | false | test.rs:296:10:299:9 | [boolean(false)] MatchExpr | false |
667666
| test.rs:299:15:299:18 | cond | test.rs:296:9:299:18 | ... && ... | |

0 commit comments

Comments
 (0)