Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust: Rename isIrrefutablePattern to isExhaustiveMatch #17751

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading