Skip to content

Lint for superfluous let/match #11088

Closed
Closed
@glaebhoerl

Description

@glaebhoerl

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions