Skip to content

Commit 78bf4ac

Browse files
committed
Fix clippy for let-else
1 parent fd8b150 commit 78bf4ac

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

clippy_lints/src/non_expressive_names.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,11 @@ impl<'a, 'b> SimilarNamesLocalVisitor<'a, 'b> {
316316

317317
impl<'a, 'tcx> Visitor<'tcx> for SimilarNamesLocalVisitor<'a, 'tcx> {
318318
fn visit_local(&mut self, local: &'tcx Local) {
319-
if let Some(ref init) = local.init {
320-
self.apply(|this| walk_expr(this, &**init));
319+
if let Some((init, els)) = &local.kind.init_else_opt() {
320+
self.apply(|this| walk_expr(this, init));
321+
if let Some(els) = els {
322+
self.apply(|this| walk_block(this, els));
323+
}
321324
}
322325
// add the pattern after the expression because the bindings aren't available
323326
// yet in the init

clippy_utils/src/ast_utils.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ pub fn eq_stmt(l: &Stmt, r: &Stmt) -> bool {
221221
(Local(l), Local(r)) => {
222222
eq_pat(&l.pat, &r.pat)
223223
&& both(&l.ty, &r.ty, |l, r| eq_ty(l, r))
224-
&& eq_expr_opt(&l.init, &r.init)
224+
&& eq_local_kind(&l.kind, &r.kind)
225225
&& over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r))
226226
},
227227
(Item(l), Item(r)) => eq_item(l, r, eq_item_kind),
@@ -234,6 +234,16 @@ pub fn eq_stmt(l: &Stmt, r: &Stmt) -> bool {
234234
}
235235
}
236236

237+
pub fn eq_local_kind(l: &LocalKind, r: &LocalKind) -> bool {
238+
use LocalKind::*;
239+
match (l, r) {
240+
(Decl, Decl) => true,
241+
(Init(l), Init(r)) => eq_expr(l, r),
242+
(InitElse(li, le), InitElse(ri, re)) => eq_expr(li, ri) && eq_block(le, re),
243+
_ => false,
244+
}
245+
}
246+
237247
pub fn eq_item<K>(l: &Item<K>, r: &Item<K>, mut eq_kind: impl FnMut(&K, &K) -> bool) -> bool {
238248
eq_id(l.ident, r.ident)
239249
&& over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r))

0 commit comments

Comments
 (0)