mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-12-03 18:09:42 +00:00
Auto merge of #96863 - SparrowLii:let, r=michaelwoerister
use `hir::Let` in `hir::Guard::IfLet` This PR fixes the FIXME about using `hir::Let` in `hir::Guard::IfLet`
This commit is contained in:
commit
01421e0cbd
5 changed files with 14 additions and 12 deletions
|
@ -5,7 +5,7 @@ use clippy_utils::{is_lang_ctor, is_unit_expr, path_to_local, peel_blocks_with_s
|
|||
use if_chain::if_chain;
|
||||
use rustc_errors::MultiSpan;
|
||||
use rustc_hir::LangItem::OptionNone;
|
||||
use rustc_hir::{Arm, Expr, Guard, HirId, Pat, PatKind};
|
||||
use rustc_hir::{Arm, Expr, Guard, HirId, Let, Pat, PatKind};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||
use rustc_span::Span;
|
||||
|
@ -109,7 +109,7 @@ fn check_arm<'tcx>(
|
|||
(Some(a), Some(b)) => SpanlessEq::new(cx).eq_expr(a, b),
|
||||
};
|
||||
// the binding must not be used in the if guard
|
||||
if outer_guard.map_or(true, |(Guard::If(e) | Guard::IfLet(_, e))| !is_local_used(cx, *e, binding_id));
|
||||
if outer_guard.map_or(true, |(Guard::If(e) | Guard::IfLet(Let { init: e, .. }))| !is_local_used(cx, *e, binding_id));
|
||||
// ...or anywhere in the inner expression
|
||||
if match inner {
|
||||
IfLetOrMatch::IfLet(_, _, body, els) => {
|
||||
|
|
|
@ -11,7 +11,7 @@ use rustc_errors::Applicability;
|
|||
use rustc_hir::{
|
||||
hir_id::HirIdSet,
|
||||
intravisit::{walk_expr, Visitor},
|
||||
Block, Expr, ExprKind, Guard, HirId, Pat, Stmt, StmtKind, UnOp,
|
||||
Block, Expr, ExprKind, Guard, HirId, Let, Pat, Stmt, StmtKind, UnOp,
|
||||
};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||
|
@ -478,7 +478,7 @@ impl<'tcx> Visitor<'tcx> for InsertSearcher<'_, 'tcx> {
|
|||
let mut is_map_used = self.is_map_used;
|
||||
for arm in arms {
|
||||
self.visit_pat(arm.pat);
|
||||
if let Some(Guard::If(guard) | Guard::IfLet(_, guard)) = arm.guard {
|
||||
if let Some(Guard::If(guard) | Guard::IfLet(&Let { init: guard, .. })) = arm.guard {
|
||||
self.visit_non_tail_expr(guard);
|
||||
}
|
||||
is_map_used |= self.visit_cond_arm(arm.body);
|
||||
|
|
|
@ -596,7 +596,7 @@ impl<'tcx> SideEffectVisit<'tcx> {
|
|||
let mut vars = std::mem::take(&mut self.ret_vars);
|
||||
let _ = arm.guard.as_ref().map(|guard| {
|
||||
self.visit_expr(match guard {
|
||||
Guard::If(expr) | Guard::IfLet(_, expr) => expr,
|
||||
Guard::If(expr) | Guard::IfLet(Let { init: expr, .. }) => expr,
|
||||
});
|
||||
vars.append(&mut self.ret_vars);
|
||||
});
|
||||
|
|
|
@ -315,11 +315,11 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
|
|||
out!("if let Some(Guard::If({expr})) = {arm}.guard;");
|
||||
self.expr(expr);
|
||||
},
|
||||
Some(hir::Guard::IfLet(pat, expr)) => {
|
||||
bind!(self, pat, expr);
|
||||
out!("if let Some(Guard::IfLet({pat}, {expr}) = {arm}.guard;");
|
||||
self.pat(pat);
|
||||
self.expr(expr);
|
||||
Some(hir::Guard::IfLet(let_expr)) => {
|
||||
bind!(self, let_expr);
|
||||
out!("if let Some(Guard::IfLet({let_expr}) = {arm}.guard;");
|
||||
self.pat(field!(let_expr.pat));
|
||||
self.expr(field!(let_expr.init));
|
||||
},
|
||||
}
|
||||
self.expr(field!(arm.body));
|
||||
|
|
|
@ -301,7 +301,9 @@ impl HirEqInterExpr<'_, '_, '_> {
|
|||
fn eq_guard(&mut self, left: &Guard<'_>, right: &Guard<'_>) -> bool {
|
||||
match (left, right) {
|
||||
(Guard::If(l), Guard::If(r)) => self.eq_expr(l, r),
|
||||
(Guard::IfLet(lp, le), Guard::IfLet(rp, re)) => self.eq_pat(lp, rp) && self.eq_expr(le, re),
|
||||
(Guard::IfLet(l), Guard::IfLet(r)) => {
|
||||
self.eq_pat(l.pat, r.pat) && both(&l.ty, &r.ty, |l, r| self.eq_ty(l, r)) && self.eq_expr(l.init, r.init)
|
||||
},
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
@ -894,7 +896,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
|
|||
|
||||
pub fn hash_guard(&mut self, g: &Guard<'_>) {
|
||||
match g {
|
||||
Guard::If(expr) | Guard::IfLet(_, expr) => {
|
||||
Guard::If(expr) | Guard::IfLet(Let { init: expr, .. }) => {
|
||||
self.hash_expr(expr);
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue