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

Don't mutate `T::default()` to `Default::default()`

Open kpreid opened this issue 1 year ago • 1 comments

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

kpreid avatar Sep 27 '24 18:09 kpreid

I think it can also avoid type inference ambiguities, but probably not in the places mutants is changing things.

mathstuf avatar Oct 29 '24 19:10 mathstuf