6 use rustc_hir::{Expr, Stmt};
7 use rustc_lint::{LateContext, LateLintPass};
8 use rustc_session::{declare_lint_pass, declare_tool_lint};
10 declare_clippy_lint! {
12 /// Checks for binding a unit value.
14 /// ### Why is this bad?
15 /// A unit value cannot usefully be used anywhere. So
16 /// binding one is kind of pointless.
26 "creating a `let` binding to a value of unit type, which usually can't be used afterwards"
29 declare_clippy_lint! {
31 /// Checks for comparisons to unit. This includes all binary
32 /// comparisons (like `==` and `<`) and asserts.
34 /// ### Why is this bad?
35 /// Unit is always equal to itself, and thus is just a
36 /// clumsily written constant. Mostly this happens when someone accidentally
37 /// adds semicolons at the end of the operands.
68 /// assert_eq!({ foo(); }, { bar(); });
70 /// will always succeed
73 "comparing unit values"
76 declare_clippy_lint! {
78 /// Checks for passing a unit value as an argument to a function without using a
79 /// unit literal (`()`).
81 /// ### Why is this bad?
82 /// This is likely the result of an accidental semicolon.
93 "passing unit to a function"
96 declare_lint_pass!(UnitTypes => [LET_UNIT_VALUE, UNIT_CMP, UNIT_ARG]);
98 impl LateLintPass<'_> for UnitTypes {
99 fn check_stmt(&mut self, cx: &LateContext<'_>, stmt: &Stmt<'_>) {
100 let_unit_value::check(cx, stmt);
103 fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
104 unit_cmp::check(cx, expr);
105 unit_arg::check(cx, expr);