mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-03 20:23:59 +00:00
Fix src/needless_bool.rs by using ExprBlock(block) = then
This commit is contained in:
parent
8297c19fcc
commit
8aef64dfe8
@ -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 };
|
||||
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user