Skip to content

Commit 2872b7e

Browse files
committed
Allow let () = .. as type inference for let_unit_value
1 parent 196174d commit 2872b7e

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

clippy_lints/src/unit_types/let_unit_value.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,23 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, local: &'tcx Local<'_>) {
1818
&& !in_external_macro(cx.sess(), local.span)
1919
&& cx.typeck_results().pat_ty(local.pat).is_unit()
2020
{
21-
if local.ty.is_some() && expr_needs_inferred_result(cx, init) {
22-
if !matches!(local.pat.kind, PatKind::Wild) {
21+
if (local.ty.map_or(false, |ty| !matches!(ty.kind, TyKind::Infer))
22+
|| matches!(local.pat.kind, PatKind::Tuple([], None)))
23+
&& expr_needs_inferred_result(cx, init)
24+
{
25+
if !matches!(local.pat.kind, PatKind::Wild | PatKind::Tuple([], None)) {
2326
span_lint_and_then(
2427
cx,
2528
LET_UNIT_VALUE,
2629
local.span,
2730
"this let-binding has unit value",
2831
|diag| {
29-
diag.span_suggestion(
30-
local.pat.span,
31-
"use a wild (`_`) binding",
32-
"_",
33-
Applicability::MaybeIncorrect, // snippet
34-
);
32+
diag.span_suggestion(
33+
local.pat.span,
34+
"use a wild (`_`) binding",
35+
"_",
36+
Applicability::MaybeIncorrect, // snippet
37+
);
3538
},
3639
);
3740
}

tests/ui/let_unit.fixed

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ fn _returns_generic() {
163163
let _: () = opt;
164164
}
165165
}
166+
167+
let () = f();
166168
}
167169

168170
fn attributes() {

tests/ui/let_unit.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ fn _returns_generic() {
163163
let _: () = opt;
164164
}
165165
}
166+
167+
let () = f();
166168
}
167169

168170
fn attributes() {

0 commit comments

Comments
 (0)