More uses of higher::if_block
This commit is contained in:
parent
69b1da4d82
commit
c9ed92ce20
@ -72,7 +72,7 @@ fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlockInIfCondition {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
if let ExprKind::If(check, then, _) = &expr.node {
|
||||
if let Some((check, then, _)) = higher::if_block(&expr) {
|
||||
if let ExprKind::Block(block, _) = &check.node {
|
||||
if block.rules == DefaultBlock {
|
||||
if block.stmts.is_empty() {
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::utils::{get_parent_expr, in_macro, snippet, span_lint_and_then, span_note_and_lint};
|
||||
use crate::utils::{get_parent_expr, higher, in_macro, snippet, span_lint_and_then, span_note_and_lint};
|
||||
use crate::utils::{SpanlessEq, SpanlessHash};
|
||||
use rustc::hir::*;
|
||||
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||
@ -109,13 +109,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyAndPaste {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
if !in_macro(expr.span) {
|
||||
// skip ifs directly in else, it will be checked in the parent if
|
||||
if let Some(&Expr {
|
||||
node: ExprKind::If(_, _, Some(ref else_expr)),
|
||||
..
|
||||
}) = get_parent_expr(cx, expr)
|
||||
{
|
||||
if else_expr.hir_id == expr.hir_id {
|
||||
return;
|
||||
if let Some(expr) = get_parent_expr(cx, expr) {
|
||||
if let Some((_, _, Some(ref else_expr))) = higher::if_block(&expr) {
|
||||
if else_expr.hir_id == expr.hir_id {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -236,7 +234,7 @@ fn lint_match_arms(cx: &LateContext<'_, '_>, expr: &Expr) {
|
||||
let mut conds = SmallVec::new();
|
||||
let mut blocks: SmallVec<[&Block; 1]> = SmallVec::new();
|
||||
|
||||
while let ExprKind::If(ref cond, ref then_expr, ref else_expr) = expr.node {
|
||||
while let Some((ref cond, ref then_expr, ref else_expr)) = higher::if_block(&expr) {
|
||||
conds.push(&**cond);
|
||||
if let ExprKind::Block(ref block, _) = then_expr.node {
|
||||
blocks.push(block);
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::utils::SpanlessEq;
|
||||
use crate::utils::{get_item_name, match_type, paths, snippet, span_lint_and_then, walk_ptrs_ty};
|
||||
use crate::utils::{get_item_name, higher, match_type, paths, snippet, span_lint_and_then, walk_ptrs_ty};
|
||||
use if_chain::if_chain;
|
||||
use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
|
||||
use rustc::hir::*;
|
||||
@ -41,7 +41,7 @@
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for HashMapPass {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
if let ExprKind::If(ref check, ref then_block, ref else_block) = expr.node {
|
||||
if let Some((ref check, ref then_block, ref else_block)) = higher::if_block(&expr) {
|
||||
if let ExprKind::Unary(UnOp::UnNot, ref check) = check.node {
|
||||
if let Some((ty, map, key)) = check_cond(cx, check) {
|
||||
// in case of `if !m.contains_key(&k) { m.insert(k, v); }`
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::utils::{snippet, span_lint_and_then};
|
||||
use crate::utils::{higher, snippet, span_lint_and_then};
|
||||
use if_chain::if_chain;
|
||||
use rustc::hir;
|
||||
use rustc::hir::def::Res;
|
||||
@ -63,7 +63,7 @@ fn check_block(&mut self, cx: &LateContext<'a, 'tcx>, block: &'tcx hir::Block) {
|
||||
if let hir::StmtKind::Local(ref local) = stmt.node;
|
||||
if let hir::PatKind::Binding(mode, canonical_id, ident, None) = local.pat.node;
|
||||
if let hir::StmtKind::Expr(ref if_) = expr.node;
|
||||
if let hir::ExprKind::If(ref cond, ref then, ref else_) = if_.node;
|
||||
if let Some((ref cond, ref then, ref else_)) = higher::if_block(&if_);
|
||||
if !used_in_expr(cx, canonical_id, cond);
|
||||
if let hir::ExprKind::Block(ref then, _) = then.node;
|
||||
if let Some(value) = check_assign(cx, canonical_id, &*then);
|
||||
|
Loading…
Reference in New Issue
Block a user