Skip to content

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

Open
zmanian wants to merge 6 commits into
ZcashFoundation:mainfrom
zmanian:refactor/remove-wildcard-match-arms
Open

refactor: replace wildcard match arms with explicit enum variants#10440
zmanian wants to merge 6 commits into
ZcashFoundation: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!

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 41 out of 41 changed files in this pull request and generated no comments.

@gustavovalverde gustavovalverde added run-stateful-tests Allos to manually trigger a stateful tests run in GCP in PRs labels Apr 9, 2026
@arya2 arya2 added do-not-merge Tells Mergify not to merge this PR and removed do-not-merge Tells Mergify not to merge this PR labels Apr 17, 2026
…ard-match-arms

# Conflicts:
#	zebra-network/src/peer/connection/tests/vectors.rs
#	zebra-rpc/src/methods.rs
@oxarbitrage
Copy link
Copy Markdown
Contributor

Thanks for working on this @zmanian — the refactor aligns with #10211 and conradoplg's acknowledgment there.

I did a detailed review of commit f8f812d5d8. The approach is correct — all the replacements are mechanical, no behavior changes, and the #[non_exhaustive] cases (halo2::plonk::Error, std::io::ErrorKind, ValidateContextError) are properly handled with #[allow] annotations. Nice work.

Two issues to fix and a rebase needed before we can merge:

Bug 1 — Missing Transaction::V6 cfg arms in tests (8 sites)

The non-test code correctly includes the cfg-gated V6 arm, but these test files don't:

  • zebra-consensus/src/transaction/tests.rs (4 sites)
  • zebra-state/src/service/check/tests/anchors.rs (3 sites)
  • zebrad/src/components/mempool/storage/tests/prop.rs (2 sites)

Each needs:

#[cfg(all(zcash_unstable = "nu7", feature = "tx_v6"))]
Transaction::V6 { .. } => // same body as the other arms

Without this, the build breaks under --features tx_v6 with zcash_unstable = "nu7".

Bug 2 — Missing NetworkUpgrade::ZFuture cfg arms (2 sites)

  • zebra-rpc/src/methods/types/get_block_template/proposal.rs
  • zebrad/tests/acceptance.rs

Each needs:

#[cfg(zcash_unstable = "zfuture")]
NetworkUpgrade::ZFuture => // same body as the other arms

Rebase needed

The branch has 6 commits but only f8f812d5d8 is the actual change — the rest are merge commits and unrelated work. Could you rebase onto current main with just that single commit? You'll hit 3 conflicts:

  • zebra-state/src/service/read/tests/vectors.rs — trivial, capitalization change in a tracing::warn!
  • zebra-network/src/peer/connection/tests/vectors.rs — trivial, panic format string was updated on main
  • zebra-rpc/src/methods.rs — moderate, main restructured the getrawtransaction handler with caller_block_context. Your explicit enum variants need to be placed into the new code flow.

Timing note: This PR touches files that overlap with other in-flight work, so we may need to coordinate merge timing. Getting the rebase and fixes done now means it's ready when the window opens.

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

Labels

external contribution extra-reviews This PR needs at least 2 reviews to merge run-stateful-tests Allos to manually trigger a stateful tests run in GCP in PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: remove some/all default match arms

6 participants