Skip to content

Mutate NonZero<T> generic return types#602

Open
sourcefrog wants to merge 2 commits intomainfrom
nonzero
Open

Mutate NonZero<T> generic return types#602
sourcefrog wants to merge 2 commits intomainfrom
nonzero

Conversation

@sourcefrog
Copy link
Copy Markdown
Owner

Summary

  • 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 T is unknown, assume it could be signed and generate both
  • Adds tests for unsigned, signed, and unknown type parameter cases

Closes #595

Test plan

  • Unit tests for NonZero<u32>, NonZero<usize>, std::num::NonZero<u8> (unsigned)
  • Unit tests for NonZero<i32>, NonZero<isize>, std::num::NonZero<i64> (signed)
  • Unit test for NonZero<T> with unknown type parameter
  • All existing tests continue to pass

🤖 Generated with Claude Code

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>
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.

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_replacements to recognize NonZero<T> and generate appropriate non-zero integer candidates based on whether T is 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 generic NonZero<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.

Comment on lines +72 to +85
} 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() },
]
}
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mutate NonZero<T>

2 participants