cargo-mutants
cargo-mutants copied to clipboard
Don't mutate `T::default()` to `Default::default()`
#[derive(Debug, Default, PartialEq)]
pub struct Foo {
whatever: i32,
}
pub fn foo() -> Foo {
Foo::default()
}
#[test]
fn t() {
assert_eq!(foo(), Foo { whatever: 0 });
}
This program generates a false positive, that is, a mutant that does the same thing as the original program and therefore cannot be caught by testing.
MISSED src/lib.rs:7:5: replace foo -> Foo with Default::default() in 0.5s build + 0.2s test
Default::default() is just another way of spelling Foo::default() (except in cases of name shadowing by an inherent impl or a different trait). I think it would be good if cargo-mutants didn't do this, since it is a common case in some kinds of code.
I think it can also avoid type inference ambiguities, but probably not in the places mutants is changing things.