diff --git a/clippy_lints/src/unit_types/let_unit_value.rs b/clippy_lints/src/unit_types/let_unit_value.rs index e49b7120d058..6a7ffdaa8a4e 100644 --- a/clippy_lints/src/unit_types/let_unit_value.rs +++ b/clippy_lints/src/unit_types/let_unit_value.rs @@ -19,20 +19,23 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) { && !in_external_macro(cx.sess(), stmt.span) && cx.typeck_results().pat_ty(local.pat).is_unit() { - if local.ty.is_some() && expr_needs_inferred_result(cx, init) { - if !matches!(local.pat.kind, PatKind::Wild) { + if (local.ty.map_or(false, |ty| !matches!(ty.kind, TyKind::Infer)) + || matches!(local.pat.kind, PatKind::Tuple([], None))) + && expr_needs_inferred_result(cx, init) + { + if !matches!(local.pat.kind, PatKind::Wild | PatKind::Tuple([], None)) { span_lint_and_then( cx, LET_UNIT_VALUE, stmt.span, "this let-binding has unit value", |diag| { - diag.span_suggestion( - local.pat.span, - "use a wild (`_`) binding", - "_", - Applicability::MaybeIncorrect, // snippet - ); + diag.span_suggestion( + local.pat.span, + "use a wild (`_`) binding", + "_", + Applicability::MaybeIncorrect, // snippet + ); }, ); } diff --git a/tests/ui/let_unit.fixed b/tests/ui/let_unit.fixed index 2aadf5e182e0..c9e8a3aaf67a 100644 --- a/tests/ui/let_unit.fixed +++ b/tests/ui/let_unit.fixed @@ -162,4 +162,6 @@ fn _returns_generic() { let _: () = opt; } } + + let () = f(); } diff --git a/tests/ui/let_unit.rs b/tests/ui/let_unit.rs index 10e911c5e633..c3d43fd5f0a0 100644 --- a/tests/ui/let_unit.rs +++ b/tests/ui/let_unit.rs @@ -162,4 +162,6 @@ fn _returns_generic() { let _: () = opt; } } + + let () = f(); }