remove contains_continue functions
This commit is contained in:
parent
a013568f70
commit
533a50547f
@ -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<NodeId>) -> 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<NodeId>) -> 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<NodeId>) -> 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<NodeId>) -> 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<NodeId>) -> 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))
|
||||
|
Loading…
Reference in New Issue
Block a user