From 493a68a2328a027557dc97e6e7a7a2125476be40 Mon Sep 17 00:00:00 2001 From: Arthur Baars Date: Sat, 12 Oct 2024 10:49:59 +0200 Subject: [PATCH 1/2] Rust: add MacroPat to isExhaustiveMatch --- rust/ql/lib/codeql/rust/controlflow/internal/Completion.qll | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/rust/ql/lib/codeql/rust/controlflow/internal/Completion.qll b/rust/ql/lib/codeql/rust/controlflow/internal/Completion.qll index faf3508379b8..ca74a10fe4ba 100644 --- a/rust/ql/lib/codeql/rust/controlflow/internal/Completion.qll +++ b/rust/ql/lib/codeql/rust/controlflow/internal/Completion.qll @@ -139,6 +139,9 @@ private predicate isExhaustiveMatch(Pat pat) { // `match` expressions must be exhaustive, so last arm cannot fail pat = any(MatchExpr me).getLastArm().getPat() or + // macro patterns is exhaustive if its expansion is + pat = any(MacroPat mp | isExhaustiveMatch(mp.getMacroCall().getExpanded())) + or // parameter patterns must be exhaustive pat = any(Param p).getPat() ) and @@ -149,6 +152,8 @@ private predicate isExhaustiveMatch(Pat pat) { or pat = parent.(IdentPat).getPat() or + pat = parent.(MacroPat).getMacroCall().getExpanded() + or pat = parent.(ParenPat).getPat() or pat = parent.(RecordPat).getRecordPatFieldList().getField(_).getPat() From ae7afa7aff0f8cca10885faaccaea5648f2eaef0 Mon Sep 17 00:00:00 2001 From: Arthur Baars Date: Mon, 14 Oct 2024 15:20:43 +0200 Subject: [PATCH 2/2] Update rust/ql/lib/codeql/rust/controlflow/internal/Completion.qll Co-authored-by: Simon Friis Vindum --- rust/ql/lib/codeql/rust/controlflow/internal/Completion.qll | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/ql/lib/codeql/rust/controlflow/internal/Completion.qll b/rust/ql/lib/codeql/rust/controlflow/internal/Completion.qll index ca74a10fe4ba..a72b904dcf1b 100644 --- a/rust/ql/lib/codeql/rust/controlflow/internal/Completion.qll +++ b/rust/ql/lib/codeql/rust/controlflow/internal/Completion.qll @@ -139,7 +139,7 @@ private predicate isExhaustiveMatch(Pat pat) { // `match` expressions must be exhaustive, so last arm cannot fail pat = any(MatchExpr me).getLastArm().getPat() or - // macro patterns is exhaustive if its expansion is + // macro invocations are exhaustive if their expansion is pat = any(MacroPat mp | isExhaustiveMatch(mp.getMacroCall().getExpanded())) or // parameter patterns must be exhaustive