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.
24 #[clippy::version = "pre 1.29.0"]
27 "creating a `let` binding to a value of unit type, which usually can't be used afterwards"
30 declare_clippy_lint! {
32 /// Checks for comparisons to unit. This includes all binary
33 /// comparisons (like `==` and `<`) and asserts.
35 /// ### Why is this bad?
36 /// Unit is always equal to itself, and thus is just a
37 /// clumsily written constant. Mostly this happens when someone accidentally
38 /// adds semicolons at the end of the operands.
69 /// assert_eq!({ foo(); }, { bar(); });
71 /// will always succeed
72 #[clippy::version = "pre 1.29.0"]
75 "comparing unit values"
78 declare_clippy_lint! {
80 /// Checks for passing a unit value as an argument to a function without using a
81 /// unit literal (`()`).
83 /// ### Why is this bad?
84 /// This is likely the result of an accidental semicolon.
93 #[clippy::version = "pre 1.29.0"]
96 "passing unit to a function"
99 declare_lint_pass!(UnitTypes => [LET_UNIT_VALUE, UNIT_CMP, UNIT_ARG]);
101 impl LateLintPass<'_> for UnitTypes {
102 fn check_stmt(&mut self, cx: &LateContext<'_>, stmt: &Stmt<'_>) {
103 let_unit_value::check(cx, stmt);
106 fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
107 unit_cmp::check(cx, expr);
108 unit_arg::check(cx, expr);