Skip to content

Commit

Permalink
Merge pull request #17751 from paldepind/rust-rename-predicate
Browse files Browse the repository at this point in the history
Rust: Rename isIrrefutablePattern to isExhaustiveMatch
  • Loading branch information
paldepind authored Oct 14, 2024
2 parents d0f978d + 22261c1 commit ef1592f
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions rust/ql/lib/codeql/rust/controlflow/internal/Completion.qll
Original file line number Diff line number Diff line change
Expand Up @@ -123,28 +123,28 @@ class BooleanCompletion extends ConditionalCompletion, TBooleanCompletion {
override string toString() { result = "boolean(" + value + ")" }
}

/** Holds if `pat` is guaranteed to match. */
/** Holds if `pat` is guaranteed to match at the point in the AST where it occurs. */
pragma[nomagic]
private predicate isIrrefutablePattern(Pat pat) {
private predicate isExhaustiveMatch(Pat pat) {
(
pat instanceof WildcardPat
or
pat = any(IdentPat ip | not ip.hasPat() and ip = any(Variable v).getPat())
or
pat instanceof RestPat
or
// `let` statements without an `else` branch must be irrefutible
// `let` statements without an `else` branch must be exhaustive
pat = any(LetStmt let | not let.hasLetElse()).getPat()
or
// `match` expressions must be irrefutible, so last arm cannot fail
// `match` expressions must be exhaustive, so last arm cannot fail
pat = any(MatchExpr me).getLastArm().getPat()
or
// parameter patterns must be irrefutible
// parameter patterns must be exhaustive
pat = any(Param p).getPat()
) and
not pat = any(ForExpr for).getPat() // workaround until `for` loops are desugared
or
exists(Pat parent | isIrrefutablePattern(parent) |
exists(Pat parent | isExhaustiveMatch(parent) |
pat = parent.(BoxPat).getPat()
or
pat = parent.(IdentPat).getPat()
Expand All @@ -171,7 +171,7 @@ class MatchCompletion extends TMatchCompletion, ConditionalCompletion {

override predicate isValidForSpecific(AstNode e) {
e instanceof Pat and
if isIrrefutablePattern(e) then value = true else any()
if isExhaustiveMatch(e) then value = true else any()
}

override MatchSuccessor getAMatchingSuccessorType() { result.getValue() = value }
Expand Down

0 comments on commit ef1592f

Please sign in to comment.