mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-24 07:44:10 +00:00
Fix clippy for let-else
This commit is contained in:
parent
fd8b150959
commit
78bf4acc3a
@ -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
|
||||
|
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user