Rustup to ea0dc92972 II
This commit is contained in:
parent
3c4af49662
commit
55b78ae478
2 changed files with 16 additions and 23 deletions
|
|
@ -72,8 +72,8 @@ fn check_if(cx: &EarlyContext, expr: &ast::Expr) {
|
|||
fn check_collapsible_maybe_if_let(cx: &EarlyContext, else_: &ast::Expr) {
|
||||
if_let_chain! {[
|
||||
let ast::ExprKind::Block(ref block) = else_.node,
|
||||
block.stmts.is_empty(),
|
||||
let Some(ref else_) = block.expr,
|
||||
let Some(ref else_) = expr_block(block),
|
||||
!in_macro(cx, else_.span),
|
||||
], {
|
||||
match else_.node {
|
||||
ast::ExprKind::If(..) | ast::ExprKind::IfLet(..) => {
|
||||
|
|
@ -96,7 +96,7 @@ fn check_collapsible_no_if_let(
|
|||
then: &ast::Block,
|
||||
) {
|
||||
if_let_chain! {[
|
||||
let Some(inner) = single_stmt_of_block(then),
|
||||
let Some(inner) = expr_block(then),
|
||||
let ast::ExprKind::If(ref check_inner, ref content, None) = inner.node,
|
||||
], {
|
||||
if expr.span.expn_id != inner.span.expn_id {
|
||||
|
|
@ -128,28 +128,16 @@ fn check_to_string(cx: &EarlyContext, e: &ast::Expr) -> Cow<'static, str> {
|
|||
}
|
||||
}
|
||||
|
||||
fn single_stmt_of_block(block: &ast::Block) -> Option<&ast::Expr> {
|
||||
if block.stmts.len() == 1 && block.expr.is_none() {
|
||||
if let ast::StmtKind::Expr(ref expr, _) = block.stmts[0].node {
|
||||
single_stmt_of_expr(expr)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else if block.stmts.is_empty() {
|
||||
if let Some(ref p) = block.expr {
|
||||
Some(p)
|
||||
} else {
|
||||
None
|
||||
/// If the block contains only one expression, returns it.
|
||||
fn expr_block(block: &ast::Block) -> Option<&ast::Expr> {
|
||||
let mut it = block.stmts.iter();
|
||||
|
||||
if let (Some(stmt), None) = (it.next(), it.next()) {
|
||||
match stmt.node {
|
||||
ast::StmtKind::Expr(ref expr) | ast::StmtKind::Semi(ref expr) => Some(expr),
|
||||
_ => None,
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn single_stmt_of_expr(expr: &ast::Expr) -> Option<&ast::Expr> {
|
||||
if let ast::ExprKind::Block(ref block) = expr.node {
|
||||
single_stmt_of_block(block)
|
||||
} else {
|
||||
Some(expr)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue