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

'impl trait' representation in mutant names can be wrong vs Rust source

Open sourcefrog opened this issue 1 year ago • 0 comments

For example from https://github.com/sourcefrog/conserve/blob/main/src/apath.rs


impl AsRef<str> for Apath {
    fn as_ref(&self) -> &str {
        &self.0
    }
}


impl From<Apath> for String {
    fn from(a: Apath) -> String {
        a.0
    }
}

impl<'a> From<&'a str> for Apath {
    fn from(s: &'a str) -> Apath {
        assert!(Apath::is_valid(s), "invalid apath: {s:?}");
        Apath(s.to_string())
    }
}

it's reported as

src/apath.rs:190:9: replace <impl AsRef for Apath>::as_ref -> &str with ""
src/apath.rs:138:9: replace <impl From for String>::from -> String with String::new()
src/apath.rs:138:9: replace <impl From for String>::from -> String with "xyzzy".into()
src/apath.rs:144:9: replace <impl From for Apath>::from -> Apath with Default::default()
src/apath.rs:151:9: replace <impl From for Apath>::from -> Apath with Default::default()

You can still basically see what it's talking about but it's a bit unclear.

A couple of options:

  1. Build the name by copying more of the AST
  2. Or, explicitly copy the type parameters.

In any case, add some tests for this.

sourcefrog avatar Apr 14 '24 17:04 sourcefrog