Conversation
Support the generic NonZero<T> form (stabilized in Rust 1.79) in addition to the existing NonZeroUsize, NonZeroI32, etc. type-specific matching. When T is a known unsigned type, generate 1; when signed, generate 1 and -1; when unknown, assume signed. Closes #595 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds mutation-generation support for Rust’s generic std::num::NonZero<T> return types (in addition to the existing NonZeroU32, NonZeroIsize, etc. matching), plus accompanying unit tests. Also updates release metadata to 27.0.0.
Changes:
- Extend
type_replacementsto recognizeNonZero<T>and generate appropriate non-zero integer candidates based on whetherTis signed/unsigned/unknown. - Add unit tests covering unsigned, signed, and unknown generic
NonZero<T>cases. - Bump crate version and update changelog/release metadata for 27.0.0.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/fnvalue.rs |
Adds NonZero<T> detection and new tests validating generated replacement expressions. |
NEWS.md |
Updates top-of-file release section to 27.0.0 with a release date. |
Cargo.toml |
Bumps package version from 27.0.0-pre to 27.0.0. |
Cargo.lock |
Updates the lockfile entry to reflect the new package version. |
Comments suppressed due to low confidence (1)
NEWS.md:9
- The 27.0.0 changelog entry doesn’t mention the new
NonZero<T>mutation support added in this PR. Consider adding a bullet (e.g., New/Fixed) describing the genericNonZero<T>return-type replacements so the release notes reflect the user-visible change.
## 27.0.0
Released 2026-03-07.
- Changed: Command line values for `--file`, `--exclude`, `--examine-re`, and `--exclude-re` are now combined with, rather than replacing, values given in the configuration file, consistently with every other option that takes a list. (Use `--config=OTHER` or `--no-config` to avoid using values in the configuration.) Thanks to @sandersaares for pointing this out.
- New: `--Zmutate-file` lists the mutants generated from a single Rust source file in text or JSON, without reading or requiring a containing package. This is intended as an aid for developing and debugging mutation patterns.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } else { | ||
| // Unknown T, assume it could be signed | ||
| vec![ | ||
| quote! { 1.try_into().unwrap() }, | ||
| quote! { (-1).try_into().unwrap() }, | ||
| ] | ||
| } | ||
| } else { | ||
| // T is not a simple path, assume it could be signed | ||
| vec![ | ||
| quote! { 1.try_into().unwrap() }, | ||
| quote! { (-1).try_into().unwrap() }, | ||
| ] | ||
| } |
There was a problem hiding this comment.
The NonZero<T> branch repeats the same two-value vec![1.try_into()..., (-1).try_into()...] construction in multiple places. Consider extracting this into a small local variable/helper to reduce duplication and make future tweaks (e.g., additional candidate values) less error-prone.
Summary
NonZero<T>form (stabilized in Rust 1.79) in addition to the existingNonZeroUsize,NonZeroI32, etc. type-specific matchingTis a known unsigned type, generate1; when signed, generate1and-1; whenTis unknown, assume it could be signed and generate bothCloses #595
Test plan
NonZero<u32>,NonZero<usize>,std::num::NonZero<u8>(unsigned)NonZero<i32>,NonZero<isize>,std::num::NonZero<i64>(signed)NonZero<T>with unknown type parameter🤖 Generated with Claude Code