]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/clippy_lints/src/methods/unit_hash.rs
Rollup merge of #105623 - compiler-errors:generator-type-size-fix, r=Nilstrieb
[rust.git] / src / tools / clippy / clippy_lints / src / methods / unit_hash.rs
1 use clippy_utils::diagnostics::span_lint_and_then;
2 use clippy_utils::is_trait_method;
3 use clippy_utils::source::snippet;
4 use rustc_errors::Applicability;
5 use rustc_hir::Expr;
6 use rustc_lint::LateContext;
7 use rustc_span::sym;
8
9 use super::UNIT_HASH;
10
11 pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, recv: &'tcx Expr<'_>, arg: &'tcx Expr<'_>) {
12     if is_trait_method(cx, expr, sym::Hash) && cx.typeck_results().expr_ty(recv).is_unit() {
13         span_lint_and_then(
14             cx,
15             UNIT_HASH,
16             expr.span,
17             "this call to `hash` on the unit type will do nothing",
18             |diag| {
19                 diag.span_suggestion(
20                     expr.span,
21                     "remove the call to `hash` or consider using",
22                     format!("0_u8.hash({})", snippet(cx, arg.span, ".."),),
23                     Applicability::MaybeIncorrect,
24                 );
25                 diag.note("the implementation of `Hash` for `()` is a no-op");
26             },
27         );
28     }
29 }