Fix clippy for let-else
This commit is contained in:
parent
960ea093ab
commit
04d7903304
2 changed files with 16 additions and 3 deletions
|
@ -316,8 +316,11 @@ impl<'a, 'b> SimilarNamesLocalVisitor<'a, 'b> {
|
||||||
|
|
||||||
impl<'a, 'tcx> Visitor<'tcx> for SimilarNamesLocalVisitor<'a, 'tcx> {
|
impl<'a, 'tcx> Visitor<'tcx> for SimilarNamesLocalVisitor<'a, 'tcx> {
|
||||||
fn visit_local(&mut self, local: &'tcx Local) {
|
fn visit_local(&mut self, local: &'tcx Local) {
|
||||||
if let Some(ref init) = local.init {
|
if let Some((init, els)) = &local.kind.init_else_opt() {
|
||||||
self.apply(|this| walk_expr(this, &**init));
|
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
|
// add the pattern after the expression because the bindings aren't available
|
||||||
// yet in the init
|
// yet in the init
|
||||||
|
|
|
@ -221,7 +221,7 @@ pub fn eq_stmt(l: &Stmt, r: &Stmt) -> bool {
|
||||||
(Local(l), Local(r)) => {
|
(Local(l), Local(r)) => {
|
||||||
eq_pat(&l.pat, &r.pat)
|
eq_pat(&l.pat, &r.pat)
|
||||||
&& both(&l.ty, &r.ty, |l, r| eq_ty(l, r))
|
&& 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))
|
&& over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r))
|
||||||
},
|
},
|
||||||
(Item(l), Item(r)) => eq_item(l, r, eq_item_kind),
|
(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 {
|
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)
|
eq_id(l.ident, r.ident)
|
||||||
&& over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r))
|
&& over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue