Closed
Description
We should have a "use unit value" lint that checks for:
()
being assigned to a variable()
being passed to a function
where the origin of the ()
is basically a semicolonless block
An example of an early pass is https://github.com/rust-lang-nursery/rust-clippy/blob/master/clippy_lints/src/precedence.rs
What we want is an early pass (runs on the AST before typechecking) with a check_expr
and check_stmt
that look for:
and then run a is_unit_expr
check on their contents (the initializer for assignment/let, and each of the arguments for calls)
is_unit_expr
will:
- if it's a
Block
, return true if the last statement is not anExpr
statement - if it's an if expr that has an else block, return true if both the if and else blocks have a non-expr final statement
- We can do something similar for match exprs if we wish.
- return false otherwise
We can also have it recurse, where if the last statement is a StmtKind::Expr
, then recurse down and check if that expr evaluates to unit.
Then, if any of the is_unit_expr
calls evaluates to true, throw the lint.
@zmanian is working on this