story
// some process managed by team a
fn caller1(...) {
String s;
level1Callee(&s);
}
// some process managed by team b
fn caller2(s: &str) {
level1Callee(s);
}
// library 1 by team c
fn level1Callee(iDontNeedOwnershipOrDoI: &str) {
level2Callee(iDontNeedOwnershipOrDoI.to_owned())
}
// library 1 by team d
fn level2Callee(iNeedStrongOwnershipBecauseIMutateTheStringAnyway: String) {
level3Callee(&iNeedStrongOwnershipBecauseIMutateTheStringAnyway)
}
This is roughly what happened in Chrome as I understand it (except multiple times because of independent libraries that didn't notice that they probably should have just made a copy to begin with). Let's pretend the codebase had been written originally in Rust. How does Rust avoid this problem from coming up? This didn't happen in Chrome because of ownership. It came up organically because of years of refactoring obfuscated things. For example, level2Callee started out not needing strong ownership but then started calling a library that did (refactoring a complex codebase is very hard & time consuming). Rinse & repeat after many years. Now maybe Rust tooling is better able to point out the unnecessary acquiring/dropping of the strings but that seems unlikely - the problem is statically very difficult to lint around.