Fix clippy for let-else

This commit is contained in:
Cameron Steffen 2021-07-25 18:27:44 -05:00
parent fd8b150959
commit 78bf4acc3a
2 changed files with 16 additions and 3 deletions

View File

@ -316,8 +316,11 @@ impl<'a, 'b> SimilarNamesLocalVisitor<'a, 'b> {
impl<'a, 'tcx> Visitor<'tcx> for SimilarNamesLocalVisitor<'a, 'tcx> {
fn visit_local(&mut self, local: &'tcx Local) {
if let Some(ref init) = local.init {
self.apply(|this| walk_expr(this, &**init));
if let Some((init, els)) = &local.kind.init_else_opt() {
self.apply(|this| walk_expr(this, init));
if let Some(els) = els {
self.apply(|this| walk_block(this, els));
}
}
// add the pattern after the expression because the bindings aren't available
// yet in the init

View File

@ -221,7 +221,7 @@ pub fn eq_stmt(l: &Stmt, r: &Stmt) -> bool {
(Local(l), Local(r)) => {
eq_pat(&l.pat, &r.pat)
&& both(&l.ty, &r.ty, |l, r| eq_ty(l, r))
&& eq_expr_opt(&l.init, &r.init)
&& eq_local_kind(&l.kind, &r.kind)
&& over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r))
},
(Item(l), Item(r)) => eq_item(l, r, eq_item_kind),
@ -234,6 +234,16 @@ pub fn eq_stmt(l: &Stmt, r: &Stmt) -> bool {
}
}
pub fn eq_local_kind(l: &LocalKind, r: &LocalKind) -> bool {
use LocalKind::*;
match (l, r) {
(Decl, Decl) => true,
(Init(l), Init(r)) => eq_expr(l, r),
(InitElse(li, le), InitElse(ri, re)) => eq_expr(li, ri) && eq_block(le, re),
_ => false,
}
}
pub fn eq_item<K>(l: &Item<K>, r: &Item<K>, mut eq_kind: impl FnMut(&K, &K) -> bool) -> bool {
eq_id(l.ident, r.ident)
&& over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r))