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

Lint for superfluous let/match #11088

Closed
glaebhoerl opened this issue Dec 20, 2013 · 7 comments
Closed

Lint for superfluous let/match #11088

glaebhoerl opened this issue Dec 20, 2013 · 7 comments
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut.

Comments

@glaebhoerl
Copy link
Contributor

Following the conversation in #10488, now that let _ = $foo; will be equivalent to just $foo;, we should have a lint to protect against people writing it, because anyone who does is likely doing so based on mistaken assumptions (i.e. that it does anything at all).

Going further, we should flag any let or match whose meaning is equivalent to just its inner/RHS expression.

My thinking w.r.t. the precise criteria is that we should flag a lint [what's the right verbage here?] unless either of the following are true:

  • it's a match with more than one arm, in which case it's presumably doing a branch (if not, there are other lints for that)
  • the pattern recursively contains a PatIdent (one which is actually an identifier and not a nullary enum) at any point, in which case the following code presumably uses the binding (if not, again there's another lint for that)

My question is whether this list should also include the presence of PatBox, PatUniq, and/or PatRegion. With the new semantics for _, will e.g. let ~_ = foo; "do anything", such as move out of foo?

As far as I can tell the change in _ semantics hasn't happened yet, but I'm thinking the lint could go in either before or after, with the potential difference that if it goes in before, the lint message should perhaps be in future tense.

@pnkfelix
Copy link
Member

Yes, this should probably wait until #10488 is actually implemented.

@pnkfelix
Copy link
Member

(and that is an interesting question about what the semantics of let ~_ = <expr>; should be. Not immediately obvious to me.)

@glaebhoerl
Copy link
Contributor Author

Currently let ~ref x = foo; is allowed and does not move out of foo, so I suspect that let ~_ = ... would also be a no-op.

@glaebhoerl
Copy link
Contributor Author

I just noticed this is in tension with #2974.

glaebhoerl added a commit to glaebhoerl/rust that referenced this issue Dec 23, 2013
…lly do anything (irrefutable, no bindings).

Will be useful once the semantics of _ in patterns changes to "ignore" instead of "drop" (rust-lang#10488).

Closes rust-lang#11088.
@steveklabnik
Copy link
Member

Triage bump: nothing has changed.

@steveklabnik steveklabnik added the A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. label Jan 23, 2015
@tbu-
Copy link
Contributor

tbu- commented Dec 2, 2015

I believe this shouldn't be linted as described, let _ = expr; silences the unused result lint.

@steveklabnik
Copy link
Member

Yup, this seems really bad. Since I'm the only one who's commented since 2013, I'm going to give this a close. A lot of the semantics here have changed since then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants