Skip to content

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

Closed
@dpc

Description

@dpc

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-compilerRelevant to the compiler team, which will review and decide on the RFC.T-langRelevant to the language team, which will review and decide on the RFC.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions