Skip to content

Commit 814c7ad

Browse files
committed
More uses of higher::if_block
1 parent d168b45 commit 814c7ad

File tree

4 files changed

+12
-14
lines changed

4 files changed

+12
-14
lines changed

clippy_lints/src/block_in_if_condition.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const COMPLEX_BLOCK_MESSAGE: &str = "in an 'if' condition, avoid complex blocks
7272

7373
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlockInIfCondition {
7474
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
75-
if let ExprKind::If(check, then, _) = &expr.node {
75+
if let Some((check, then, _)) = higher::if_block(&expr) {
7676
if let ExprKind::Block(block, _) = &check.node {
7777
if block.rules == DefaultBlock {
7878
if block.stmts.is_empty() {

clippy_lints/src/copies.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::{get_parent_expr, in_macro, snippet, span_lint_and_then, span_note_and_lint};
1+
use crate::utils::{get_parent_expr, higher, in_macro, snippet, span_lint_and_then, span_note_and_lint};
22
use crate::utils::{SpanlessEq, SpanlessHash};
33
use rustc::hir::*;
44
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
@@ -109,13 +109,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyAndPaste {
109109
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
110110
if !in_macro(expr.span) {
111111
// skip ifs directly in else, it will be checked in the parent if
112-
if let Some(&Expr {
113-
node: ExprKind::If(_, _, Some(ref else_expr)),
114-
..
115-
}) = get_parent_expr(cx, expr)
116-
{
117-
if else_expr.hir_id == expr.hir_id {
118-
return;
112+
if let Some(expr) = get_parent_expr(cx, expr) {
113+
if let Some((_, _, Some(ref else_expr))) = higher::if_block(&expr) {
114+
if else_expr.hir_id == expr.hir_id {
115+
return;
116+
}
119117
}
120118
}
121119

@@ -236,7 +234,7 @@ fn if_sequence(mut expr: &Expr) -> (SmallVec<[&Expr; 1]>, SmallVec<[&Block; 1]>)
236234
let mut conds = SmallVec::new();
237235
let mut blocks: SmallVec<[&Block; 1]> = SmallVec::new();
238236

239-
while let ExprKind::If(ref cond, ref then_expr, ref else_expr) = expr.node {
237+
while let Some((ref cond, ref then_expr, ref else_expr)) = higher::if_block(&expr) {
240238
conds.push(&**cond);
241239
if let ExprKind::Block(ref block, _) = then_expr.node {
242240
blocks.push(block);

clippy_lints/src/entry.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::utils::SpanlessEq;
2-
use crate::utils::{get_item_name, match_type, paths, snippet, span_lint_and_then, walk_ptrs_ty};
2+
use crate::utils::{higher, get_item_name, match_type, paths, snippet, span_lint_and_then, walk_ptrs_ty};
33
use if_chain::if_chain;
44
use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
55
use rustc::hir::*;
@@ -41,7 +41,7 @@ declare_lint_pass!(HashMapPass => [MAP_ENTRY]);
4141

4242
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for HashMapPass {
4343
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
44-
if let ExprKind::If(ref check, ref then_block, ref else_block) = expr.node {
44+
if let Some((ref check, ref then_block, ref else_block)) = higher::if_block(&expr) {
4545
if let ExprKind::Unary(UnOp::UnNot, ref check) = check.node {
4646
if let Some((ty, map, key)) = check_cond(cx, check) {
4747
// in case of `if !m.contains_key(&k) { m.insert(k, v); }`

clippy_lints/src/let_if_seq.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::{snippet, span_lint_and_then};
1+
use crate::utils::{higher, snippet, span_lint_and_then};
22
use if_chain::if_chain;
33
use rustc::hir;
44
use rustc::hir::def::Res;
@@ -63,7 +63,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq {
6363
if let hir::StmtKind::Local(ref local) = stmt.node;
6464
if let hir::PatKind::Binding(mode, canonical_id, ident, None) = local.pat.node;
6565
if let hir::StmtKind::Expr(ref if_) = expr.node;
66-
if let hir::ExprKind::If(ref cond, ref then, ref else_) = if_.node;
66+
if let Some((ref cond, ref then, ref else_)) = higher::if_block(&if_);
6767
if !used_in_expr(cx, canonical_id, cond);
6868
if let hir::ExprKind::Block(ref then, _) = then.node;
6969
if let Some(value) = check_assign(cx, canonical_id, &*then);

0 commit comments

Comments
 (0)