cargo-mutants
cargo-mutants copied to clipboard
Don't generate a mutation for `.with_capacity`
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
Maybe this is best done by adding a configuration for functions whose calls will not be mutated, and that could start with with_capacity.