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

Don't generate a mutation for `.with_capacity`

Open sourcefrog opened this issue 1 year ago • 1 comments
trafficstars

Discussed in https://github.com/sourcefrog/cargo-mutants/discussions/314

Originally posted by pashadia March 21, 2024 Hi all,

New contributor here, first of all congratulations on a great project!

I've used cargo mutants on a fairly large codebase (12kloc). One of the things that appear regularly on my project is to preallocate memory for some data structures. For instance, we use things like let v = Vec::with_capacity(a+b);. Obviously, cargo-mutants is generating a mutation for the argument, into things like a-b or a*b. However, this won't break any tests, as it doesn't actually introduce a bug in functionality, only the memory allocation footprint may be different.

My proposal is to remove the generation of mutations for the .with_capacity parameter, for all the structs in std::collections, and perhaps not only. I would gladly attempt an implementation, if this proposal is well received.


  • [ ] Add config, option, for skip_calls: Vec<String>
  • [ ] Set this by default to with_capacity
  • [ ] Don't generate mutants inside them when walking the tree
  • [ ] Document in the manual
  • [ ] Test

sourcefrog avatar Mar 24 '24 17:03 sourcefrog

Maybe this is best done by adding a configuration for functions whose calls will not be mutated, and that could start with with_capacity.

sourcefrog avatar Apr 13 '24 19:04 sourcefrog