Skip to content

refactor: replace wildcard match arms with explicit enum variants#10440

Open
zmanian wants to merge 5 commits intoZcashFoundation:mainfrom
zmanian:refactor/remove-wildcard-match-arms
Open

refactor: replace wildcard match arms with explicit enum variants#10440
zmanian wants to merge 5 commits intoZcashFoundation:mainfrom
zmanian:refactor/remove-wildcard-match-arms

Conversation

@zmanian
Copy link
Copy Markdown
Contributor

@zmanian zmanian commented Mar 30, 2026

Motivation

Closes #10211

Wildcard match arms (_ =>) silently swallow new enum variants, which can hide bugs when new variants are added. Replacing them with explicit variant listings ensures the compiler flags any match that needs updating.

Solution

  • Replaced all _ => patterns across 42 files with explicit enum variant listings
  • Feature-gated variants (ReadResponse::TransactionId behind indexer, Transaction::V6 behind nu7/tx_v6, NetworkUpgrade::ZFuture behind zfuture) handled with #[cfg] arms
  • halo2::plonk::Error retains wildcard with #[allow(clippy::wildcard_enum_match_arm)] due to upstream #[non_exhaustive]
  • Added indexer feature propagation from zebrad -> zebra-rpc -> zebra-state
  • Fixed pre-existing println! clippy lint in zebra-state/src/service/read/tests/vectors.rs (changed to tracing::warn!)

Verification

  • cargo fmt --all -- --check passes
  • cargo clippy --workspace --all-targets -- -D warnings passes (default features)
  • cargo clippy --workspace --all-targets --features indexer -- -D warnings passes

AI Disclosure

Used Claude Code for initial enumeration of wildcard patterns and mechanical replacement. All changes were reviewed and verified by the contributor.

zmanian and others added 4 commits March 5, 2026 08:17
Add comprehensive unit tests for policy functions added in ZcashFoundation#10314:
- count_script_push_ops: PUSHDATA1/2/4, mixed types, truncated scripts
- extract_p2sh_redeemed_script: existing + edge cases
- script_sig_args_expected: P2PK, multisig via script classification
- are_inputs_standard: P2PKH accept/reject, wrong stack depth,
  non-standard spent outputs, P2SH with standard/non-standard redeemed
  scripts, sigops boundary, multi-input rejection
- p2sh_sigop_count: P2SH/non-P2SH/multi-input summation

Also adds defensive improvements:
- saturating_add for sigop count arithmetic
- debug_assert_eq for input/spent_output alignment
- Expanded doc comments with correctness notes

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Remove unnecessary Hash derive from NonStandardTransactionError
- Move p2pkh_lock_script, p2sh_lock_script, p2pk_lock_script to module
  level in policy.rs as #[cfg(test)] pub(super) functions, eliminating
  duplication between policy::tests and tests::vectors

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace `_ =>` wildcard patterns with explicit enum variant listings
across the workspace to improve safety. When new enum variants are
added, the compiler will now produce errors instead of silently falling
through to a default case.

- 42 files modified across zebra-chain, zebra-consensus, zebra-network,
  zebra-rpc, zebra-state, and zebrad
- Feature-gated variants (ReadResponse::TransactionId behind `indexer`,
  Transaction::V6 behind `nu7`/`tx_v6`) handled with #[cfg] arms
- halo2::plonk::Error retains wildcard with #[allow] due to upstream
  #[non_exhaustive]
- Pre-existing println! lint fix in zebra-state test (-> tracing::warn!)

Closes ZcashFoundation#10211
@github-actions github-actions bot added the extra-reviews This PR needs at least 2 reviews to merge label Mar 30, 2026
@zmanian
Copy link
Copy Markdown
Contributor Author

zmanian commented Mar 31, 2026

@conradoplg This is ready for review — CI workflows need maintainer approval to run (fork PR). Could you approve the Actions runs when you get a chance? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extra-reviews This PR needs at least 2 reviews to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: remove some/all default match arms

1 participant