Warn about potential no-op (result of non-mutating function being discarded). #1110
Labels
T-compiler
Relevant to the compiler team, which will review and decide on the RFC.
T-lang
Relevant to the language team, which will review and decide on the RFC.
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:
and now I've changed it without much checking:
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.
The text was updated successfully, but these errors were encountered: