@@ -80,7 +80,8 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, local: &'tcx LetStmt<'_>) {
80
80
suggestions. push ( ( local. span , format ! ( "{snip};" ) ) ) ;
81
81
}
82
82
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
84
85
if let PatKind :: Binding ( _, binding_hir_id, ident, ..) = local. pat . kind {
85
86
if let Some ( body_id) = cx. enclosing_body . as_ref ( ) {
86
87
let body = cx. tcx . hir ( ) . body ( * body_id) ;
@@ -94,29 +95,22 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, local: &'tcx LetStmt<'_>) {
94
95
if has_usages {
95
96
suggestions. extend ( visitor. spans . into_iter ( ) . map ( |span| ( span, "()" . to_string ( ) ) ) ) ;
96
97
}
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
- }
112
98
}
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 {
115
103
diag. multipart_suggestion (
116
104
"omit the `let` binding" ,
117
105
suggestions,
118
106
Applicability :: MachineApplicable ,
119
107
) ;
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
+ ) ;
120
114
}
121
115
} ,
122
116
) ;
0 commit comments