|
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}; |
2 | 2 | use crate::utils::{SpanlessEq, SpanlessHash}; |
3 | 3 | use rustc::hir::*; |
4 | 4 | use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; |
@@ -109,13 +109,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyAndPaste { |
109 | 109 | fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { |
110 | 110 | if !in_macro(expr.span) { |
111 | 111 | // 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 | + } |
119 | 117 | } |
120 | 118 | } |
121 | 119 |
|
@@ -236,7 +234,7 @@ fn if_sequence(mut expr: &Expr) -> (SmallVec<[&Expr; 1]>, SmallVec<[&Block; 1]>) |
236 | 234 | let mut conds = SmallVec::new(); |
237 | 235 | let mut blocks: SmallVec<[&Block; 1]> = SmallVec::new(); |
238 | 236 |
|
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) { |
240 | 238 | conds.push(&**cond); |
241 | 239 | if let ExprKind::Block(ref block, _) = then_expr.node { |
242 | 240 | blocks.push(block); |
|
0 commit comments