Fix src/needless_bool.rs by using ExprBlock(block) = then

This commit is contained in:
Enrico Schmitz 2017-03-31 23:46:08 +02:00 committed by Enrico Schmitz
parent 8297c19fcc
commit 8aef64dfe8
2 changed files with 6 additions and 2 deletions

View File

@ -69,9 +69,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq {
let hir::StmtExpr(ref if_, _) = expr.node,
let hir::ExprIf(ref cond, ref then, ref else_) = if_.node,
!used_in_expr(cx, def_id, cond),
!used_in_expr(cx, def_id, &*then),
let hir::ExprBlock(ref then) = then.node,
let Some(value) = check_assign(cx, def_id, &*then),
!used_in_expr(cx, def_id, value),
], {
let span = Span { lo: stmt.span.lo, hi: if_.span.hi, ctxt: NO_EXPANSION };

View File

@ -76,7 +76,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBool {
"this if-then-else expression returns a bool literal",
|db| { db.span_suggestion(e.span, "you can reduce it to", hint); });
};
match (fetch_bool_expr(&**then_block), fetch_bool_expr(else_expr)) {
if let ExprBlock(ref then_block) = then_block.node {
match (fetch_bool_block(then_block), fetch_bool_expr(else_expr)) {
(RetBool(true), RetBool(true)) |
(Bool(true), Bool(true)) => {
span_lint(cx,
@ -97,6 +98,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBool {
(Bool(false), Bool(true)) => reduce(false, true),
_ => (),
}
} else {
panic!("IfExpr 'then' node is not an ExprBlock");
}
}
}
}