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! {
11 /// **What it does:** Checks for binding a unit value.
13 /// **Why is this bad?** A unit value cannot usefully be used anywhere. So
14 /// binding one is kind of pointless.
16 /// **Known problems:** None.
26 "creating a `let` binding to a value of unit type, which usually can't be used afterwards"
29 declare_clippy_lint! {
30 /// **What it does:** Checks for comparisons to unit. This includes all binary
31 /// comparisons (like `==` and `<`) and asserts.
33 /// **Why is this bad?** Unit is always equal to itself, and thus is just a
34 /// clumsily written constant. Mostly this happens when someone accidentally
35 /// adds semicolons at the end of the operands.
37 /// **Known problems:** None.
68 /// assert_eq!({ foo(); }, { bar(); });
70 /// will always succeed
73 "comparing unit values"
76 declare_clippy_lint! {
77 /// **What it does:** Checks for passing a unit value as an argument to a function without using a
78 /// unit literal (`()`).
80 /// **Why is this bad?** This is likely the result of an accidental semicolon.
82 /// **Known problems:** None.
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);