From 533a50547f9868ed8a278b80f2504b5ddf65dfb5 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Sun, 8 Oct 2017 17:24:32 -0500 Subject: [PATCH] remove contains_continue functions --- clippy_lints/src/loops.rs | 71 --------------------------------------- 1 file changed, 71 deletions(-) diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 8d2a2f8fac6..0844b1b1608 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -489,77 +489,6 @@ fn never_loop(block: &Block, id: NodeId) -> bool { !contains_continue_block(block, Some(id)) && loop_exit_block(block, &mut vec![id]) } -fn contains_continue_block(block: &Block, dest: Option) -> bool { - block.stmts.iter().any(|e| contains_continue_stmt(e, dest)) || - block.expr.as_ref().map_or( - false, - |e| contains_continue_expr(e, dest), - ) -} - -fn contains_continue_stmt(stmt: &Stmt, dest: Option) -> bool { - match stmt.node { - StmtSemi(ref e, _) | - StmtExpr(ref e, _) => contains_continue_expr(e, dest), - StmtDecl(ref d, _) => contains_continue_decl(d, dest), - } -} - -fn contains_continue_decl(decl: &Decl, dest: Option) -> bool { - match decl.node { - DeclLocal(ref local) => { - local.init.as_ref().map_or( - false, - |e| contains_continue_expr(e, dest), - ) - }, - _ => false, - } -} - -fn contains_continue_expr(expr: &Expr, dest: Option) -> bool { - match expr.node { - ExprRet(Some(ref e)) | - ExprBox(ref e) | - ExprUnary(_, ref e) | - ExprCast(ref e, _) | - ExprType(ref e, _) | - ExprField(ref e, _) | - ExprTupField(ref e, _) | - ExprAddrOf(_, ref e) | - ExprRepeat(ref e, _) => contains_continue_expr(e, dest), - ExprArray(ref es) | - ExprMethodCall(_, _, ref es) | - ExprTup(ref es) => es.iter().any(|e| contains_continue_expr(e, dest)), - ExprCall(ref e, ref es) => { - contains_continue_expr(e, dest) || es.iter().any(|e| contains_continue_expr(e, dest)) - }, - ExprBinary(_, ref e1, ref e2) | - ExprAssign(ref e1, ref e2) | - ExprAssignOp(_, ref e1, ref e2) | - ExprIndex(ref e1, ref e2) => [e1, e2].iter().any(|e| contains_continue_expr(e, dest)), - ExprIf(ref e, ref e2, ref e3) => { - [e, e2].iter().chain(e3.as_ref().iter()).any(|e| { - contains_continue_expr(e, dest) - }) - }, - ExprWhile(ref e, ref b, _) => contains_continue_expr(e, dest) || contains_continue_block(b, dest), - ExprMatch(ref e, ref arms, _) => { - contains_continue_expr(e, dest) || arms.iter().any(|a| contains_continue_expr(&a.body, dest)) - }, - ExprBlock(ref block) | - ExprLoop(ref block, ..) => contains_continue_block(block, dest), - ExprStruct(_, _, ref base) => { - base.as_ref().map_or( - false, - |e| contains_continue_expr(e, dest), - ) - }, - ExprAgain(d) => dest.map_or(true, |dest| d.target_id.opt_id().map_or(false, |id| id == dest)), - _ => false, - } -} - fn loop_exit_block(block: &Block, loops: &mut Vec) -> bool { block.stmts.iter().take_while(|s| !contains_continue_stmt(s, None)).any(|s| loop_exit_stmt(s, loops)) || block.expr.as_ref().map_or(false, |e| loop_exit_expr(e, loops))