about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--clippy_lints/src/unit_types/let_unit_value.rs19
-rw-r--r--tests/ui/let_unit.fixed2
-rw-r--r--tests/ui/let_unit.rs2
3 files changed, 15 insertions, 8 deletions
diff --git a/clippy_lints/src/unit_types/let_unit_value.rs b/clippy_lints/src/unit_types/let_unit_value.rs
index c98f9e01a8d..aec028d5c48 100644
--- a/clippy_lints/src/unit_types/let_unit_value.rs
+++ b/clippy_lints/src/unit_types/let_unit_value.rs
@@ -18,20 +18,23 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, local: &'tcx Local<'_>) {
         && !in_external_macro(cx.sess(), local.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,
                     local.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 3d2a9635d75..6343cff0f7f 100644
--- a/tests/ui/let_unit.fixed
+++ b/tests/ui/let_unit.fixed
@@ -163,6 +163,8 @@ fn _returns_generic() {
             let _: () = opt;
         }
     }
+
+    let () = f();
 }
 
 fn attributes() {
diff --git a/tests/ui/let_unit.rs b/tests/ui/let_unit.rs
index 625927f76f1..c9bb2849f5c 100644
--- a/tests/ui/let_unit.rs
+++ b/tests/ui/let_unit.rs
@@ -163,6 +163,8 @@ fn _returns_generic() {
             let _: () = opt;
         }
     }
+
+    let () = f();
 }
 
 fn attributes() {