Skip to content

New lint: let statement with no effect #5205

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

Open
CAD97 opened this issue Feb 20, 2020 · 2 comments
Open

New lint: let statement with no effect #5205

CAD97 opened this issue Feb 20, 2020 · 2 comments
Labels
A-lint Area: New lints L-unnecessary Lint: Warn about unnecessary code

Comments

@CAD97
Copy link
Contributor

CAD97 commented Feb 20, 2020

As featured in this Twitter poll.

A statement of the form let _ = <place> has no effect (modulo Deref coersion) as the place is not moved from. This should instead be omited (if all Deref coersion is pure) or otherwise written to be more clear on intent (explicitly calling side-effectful Deref).

50% of people had the wrong intuition of behavior here, so this definitely would help avoid potentially misleading code.

@mati865
Copy link
Member

mati865 commented Feb 20, 2020

let _ = expr is also used to mute must_use lint.

@CAD97
Copy link
Contributor Author

CAD97 commented Feb 20, 2020

let _ = $expr is perfectly fine for an expr that has an effect (e.g. calls a method). It's specifically "path expressions" that are problematic, as they lead to a no-op (modulo deref coersions) statement.

@flip1995 flip1995 added L-unnecessary Lint: Warn about unnecessary code A-lint Area: New lints labels Feb 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints L-unnecessary Lint: Warn about unnecessary code
Projects
None yet
Development

No branches or pull requests

3 participants