Skip to content

Commit bb0e9d4

Browse files
committed
remove if_chain invocation
1 parent cebf2b4 commit bb0e9d4

File tree

1 file changed

+44
-46
lines changed

1 file changed

+44
-46
lines changed

clippy_lints/src/unit_types/let_unit_value.rs

Lines changed: 44 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -18,63 +18,61 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, local: &'tcx Local<'_>) {
1818
return;
1919
}
2020

21-
if_chain! {
22-
if let Some(init) = local.init;
23-
if !local.pat.span.from_expansion();
24-
if !in_external_macro(cx.sess(), local.span);
25-
if cx.typeck_results().pat_ty(local.pat).is_unit();
26-
then {
27-
// skip `let awa = ()`
28-
if let ExprKind::Tup(elements) = init.kind && elements.is_empty() {
29-
return;
30-
}
21+
if let Some(init) = local.init
22+
&& !local.pat.span.from_expansion()
23+
&& !in_external_macro(cx.sess(), local.span)
24+
&& cx.typeck_results().pat_ty(local.pat).is_unit()
25+
{
26+
// skip `let awa = ()`
27+
if let ExprKind::Tup(elements) = init.kind && elements.is_empty() {
28+
return;
29+
}
3130

32-
if (local.ty.map_or(false, |ty| !matches!(ty.kind, TyKind::Infer))
33-
|| matches!(local.pat.kind, PatKind::Tuple([], ddpos) if ddpos.as_opt_usize().is_none()))
34-
&& expr_needs_inferred_result(cx, init)
31+
if (local.ty.map_or(false, |ty| !matches!(ty.kind, TyKind::Infer))
32+
|| matches!(local.pat.kind, PatKind::Tuple([], ddpos) if ddpos.as_opt_usize().is_none()))
33+
&& expr_needs_inferred_result(cx, init)
34+
{
35+
if !matches!(local.pat.kind, PatKind::Wild)
36+
&& !matches!(local.pat.kind, PatKind::Tuple([], ddpos) if ddpos.as_opt_usize().is_none())
3537
{
36-
if !matches!(local.pat.kind, PatKind::Wild)
37-
&& !matches!(local.pat.kind, PatKind::Tuple([], ddpos) if ddpos.as_opt_usize().is_none())
38-
{
39-
span_lint_and_then(
40-
cx,
41-
LET_UNIT_VALUE,
42-
local.span,
43-
"this let-binding has unit value",
44-
|diag| {
45-
diag.span_suggestion(
46-
local.pat.span,
47-
"use a wild (`_`) binding",
48-
"_",
49-
Applicability::MaybeIncorrect, // snippet
50-
);
51-
},
52-
);
53-
}
54-
} else {
55-
if let ExprKind::Match(_, _, MatchSource::AwaitDesugar) = init.kind {
56-
return
57-
}
58-
5938
span_lint_and_then(
6039
cx,
6140
LET_UNIT_VALUE,
6241
local.span,
6342
"this let-binding has unit value",
6443
|diag| {
65-
if let Some(expr) = &local.init {
66-
let mut app = Applicability::MachineApplicable;
67-
let snip = snippet_with_context(cx, expr.span, local.span.ctxt(), "()", &mut app).0;
68-
diag.span_suggestion(
69-
local.span,
70-
"omit the `let` binding",
71-
format!("{snip};"),
72-
app,
73-
);
74-
}
44+
diag.span_suggestion(
45+
local.pat.span,
46+
"use a wild (`_`) binding",
47+
"_",
48+
Applicability::MaybeIncorrect, // snippet
49+
);
7550
},
7651
);
7752
}
53+
} else {
54+
if let ExprKind::Match(_, _, MatchSource::AwaitDesugar) = init.kind {
55+
return
56+
}
57+
58+
span_lint_and_then(
59+
cx,
60+
LET_UNIT_VALUE,
61+
local.span,
62+
"this let-binding has unit value",
63+
|diag| {
64+
if let Some(expr) = &local.init {
65+
let mut app = Applicability::MachineApplicable;
66+
let snip = snippet_with_context(cx, expr.span, local.span.ctxt(), "()", &mut app).0;
67+
diag.span_suggestion(
68+
local.span,
69+
"omit the `let` binding",
70+
format!("{snip};"),
71+
app,
72+
);
73+
}
74+
},
75+
);
7876
}
7977
}
8078
}

0 commit comments

Comments
 (0)