cargo-mutants icon indicating copy to clipboard operation
cargo-mutants copied to clipboard

Functions mutated to return constant with `NonZero` return value are always unviable

Open sandersaares opened this issue 1 month ago • 1 comments

fn foo() -> NonZero<usize> is mutaned to return a constant like NonZero::new(1) which will never compile because NonZero::new() returns an Option<NonZero<_>>. It needs an .unwrap() there!

Not sure how smart the type-specific mutation mechanism is but adding an .unwrap() for NonZero types could suddenly make a lot more mutants viable.

sandersaares avatar Nov 09 '25 18:11 sandersaares

Hi, thanks for reporting this.

I don't know if we mutate NonZero<usize> at all at the moment, but we probably should. And it looks like the existing mutation for NonZeroUsize is wrong in the way you say.

sourcefrog avatar Nov 10 '25 17:11 sourcefrog