Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't mutate T::default() to Default::default() #418

Open
kpreid opened this issue Sep 27, 2024 · 1 comment
Open

Don't mutate T::default() to Default::default() #418

kpreid opened this issue Sep 27, 2024 · 1 comment
Labels
generate Patterns of mutation small

Comments

@kpreid
Copy link

kpreid commented Sep 27, 2024

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

@sourcefrog sourcefrog added generate Patterns of mutation small labels Sep 27, 2024
@mathstuf
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
generate Patterns of mutation small
Projects
None yet
Development

No branches or pull requests

3 participants