Skip to content

Commit e8cb349

Browse files
committed
Rust: Refine deadEnd consistency check
1 parent 8595776 commit e8cb349

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

rust/ql/consistency-queries/CfgConsistency.ql

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,13 @@ query predicate scopeNoFirst(CfgScope scope) {
2626
not scope = any(ClosureExpr c | not exists(c.getBody()))
2727
}
2828

29+
/** Holds if `be` is the `else` branch of a `let` statement that results in a panic. */
30+
private predicate letElsePanic(BlockExpr be) {
31+
be = any(LetStmt let).getLetElse().getBlockExpr() and
32+
exists(Completion c | CfgImpl::last(be, _, c) | completionIsNormal(c))
33+
}
34+
2935
query predicate deadEnd(CfgImpl::Node node) {
3036
Consistency::deadEnd(node) and
31-
// `else` blocks in `let` statements diverge, so they are by definition dead ends
32-
not node.getAstNode() = any(LetStmt let).getLetElse().getBlockExpr()
37+
not letElsePanic(node.getAstNode())
3338
}

0 commit comments

Comments
 (0)