Skip to content

Commit 508e815

Browse files
authored
Merge pull request github#17746 from github/aibaars/macro-pat-irrefutable
Rust: add MacroPat to isExhaustiveMatch
2 parents cc1e33f + ae7afa7 commit 508e815

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ private predicate isExhaustiveMatch(Pat pat) {
139139
// `match` expressions must be exhaustive, so last arm cannot fail
140140
pat = any(MatchExpr me).getLastArm().getPat()
141141
or
142+
// macro invocations are exhaustive if their expansion is
143+
pat = any(MacroPat mp | isExhaustiveMatch(mp.getMacroCall().getExpanded()))
144+
or
142145
// parameter patterns must be exhaustive
143146
pat = any(Param p).getPat()
144147
) and
@@ -149,6 +152,8 @@ private predicate isExhaustiveMatch(Pat pat) {
149152
or
150153
pat = parent.(IdentPat).getPat()
151154
or
155+
pat = parent.(MacroPat).getMacroCall().getExpanded()
156+
or
152157
pat = parent.(ParenPat).getPat()
153158
or
154159
pat = parent.(RecordPat).getRecordPatFieldList().getField(_).getPat()

0 commit comments

Comments
 (0)