Skip to content

Commit a73bf09

Browse files
committed
Clean up let_unit_value changes
1 parent baab58a commit a73bf09

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

clippy_lints/src/unit_types/let_unit_value.rs

+12-18
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, local: &'tcx LetStmt<'_>) {
8080
suggestions.push((local.span, format!("{snip};")));
8181
}
8282

83-
// Check if this is a binding pattern
83+
// If this is a binding pattern, we need to add suggestions to remove any usages
84+
// of the variable
8485
if let PatKind::Binding(_, binding_hir_id, ident, ..) = local.pat.kind {
8586
if let Some(body_id) = cx.enclosing_body.as_ref() {
8687
let body = cx.tcx.hir().body(*body_id);
@@ -94,29 +95,22 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, local: &'tcx LetStmt<'_>) {
9495
if has_usages {
9596
suggestions.extend(visitor.spans.into_iter().map(|span| (span, "()".to_string())));
9697
}
97-
98-
// Emit appropriate diagnostic based on whether there are usages
99-
if has_usages {
100-
diag.multipart_suggestion(
101-
"omit the `let` binding and replace variable usages with `()`",
102-
suggestions,
103-
Applicability::MachineApplicable,
104-
);
105-
} else {
106-
diag.multipart_suggestion(
107-
"omit the `let` binding",
108-
suggestions,
109-
Applicability::MachineApplicable,
110-
);
111-
}
11298
}
113-
} else {
114-
// Emit a simpler diagnostic if not a binding
99+
}
100+
101+
// Emit appropriate diagnostic based on whether there are usages of the let binding
102+
if suggestions.len() == 1 {
115103
diag.multipart_suggestion(
116104
"omit the `let` binding",
117105
suggestions,
118106
Applicability::MachineApplicable,
119107
);
108+
} else if suggestions.len() > 1 {
109+
diag.multipart_suggestion(
110+
"omit the `let` binding and replace variable usages with `()`",
111+
suggestions,
112+
Applicability::MachineApplicable,
113+
);
120114
}
121115
},
122116
);

0 commit comments

Comments
 (0)