Description
I was refactoring a code and bitten by the fact that join (http://doc.rust-lang.org/std/path/struct.Path.html#method.join) semantics changed from mutating &mut self
, to returning new instance.
My code used to do something like:
path.push(".dotfile");
and now I've changed it without much checking:
path.join(".dotfile");
which is a a bug, and a no-op.
This made me think: could rustc warn me about discarding the result of join
? When calling a function taking no mutable arguments, discarding the result is almost always a mistake, as it's effectively an no-op.
There are exceptions: some arguments can be of type with some form of interior-mutability, or modifying global data, but maybe this cases are distinct enough to catch most of them, eliminating some false positives. And even if some false positives can still happen, forcing user to explicitly discard a value, might still be worth it. This could be a custom lint or something.