Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn about potential no-op (result of non-mutating function being discarded). #1110

Closed
dpc opened this issue May 8, 2015 · 3 comments
Closed
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.

Comments

@dpc
Copy link

dpc commented May 8, 2015

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.

@dpc
Copy link
Author

dpc commented May 8, 2015

@eddyb : Just as discussed on IRC, I've wrote it down. Thanks!

@nrc nrc added T-lang Relevant to the language team, which will review and decide on the RFC. T-compiler Relevant to the compiler team, which will review and decide on the RFC. labels Aug 30, 2016
@varkor
Copy link
Member

varkor commented May 23, 2018

This is now facilitated through rust-lang/rust#43302.

@Centril
Copy link
Contributor

Centril commented Oct 7, 2018

And therefore we can close the issue.

@Centril Centril closed this as completed Oct 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.
Projects
None yet
Development

No branches or pull requests

4 participants