cargo-mutants
cargo-mutants copied to clipboard
Support skipping mutation of constants
I find that too often there are no-op mutations on constants:
const HARD_CAP_FLAGS: u32 =
JOB_OBJECT_CPU_RATE_CONTROL_ENABLE.0 | JOB_OBJECT_CPU_RATE_CONTROL_HARD_CAP.0;
The | gets replaced by ^ which changes nothing when combining flags, so is not very useful.
Unfortunately, adding the mutants::skip attribute here seems to do nothing. I understand from the documentation this is only supported on functions.
It would be helpful to support for this attribute on such constants, so I would not have to work around such mutations in other ways.
It’s possible for associated constants to contain nontrivial logic for which test coverage is as meaningful as for a function:
pub struct Foo<const N: usize> {}
impl<const N: usize> Foo<N> {
pub const VALUE: usize = if N == 0 { 0 } else { N - 1 };
}
But that’s all the more reason they should be both mutated and skippable.