Fix yet another FP in `USELESS_LET_IF_SEQ`

The block expression before the assignment must be `None`.
This commit is contained in:
mcarton 2016-06-09 00:22:59 +02:00
parent c5affa2efc
commit ce2b96abe9
No known key found for this signature in database
GPG Key ID: 5E427C794CBA45E8
2 changed files with 10 additions and 0 deletions

View File

@ -150,6 +150,7 @@ impl<'a, 'tcx, 'v> hir::intravisit::Visitor<'v> for UsedVisitor<'a, 'tcx> {
fn check_assign<'e>(cx: &LateContext, decl: hir::def_id::DefId, block: &'e hir::Block) -> Option<&'e hir::Expr> {
if_let_chain! {[
block.expr.is_none(),
let Some(expr) = block.stmts.iter().last(),
let hir::StmtSemi(ref expr, _) = expr.node,
let hir::ExprAssign(ref var, ref value) = expr.node,

View File

@ -98,6 +98,15 @@ fn main() {
toto = 2;
}
// found in libcore, the inner if is not a statement but the block's expr
let mut ch = b'x';
if f() {
ch = b'*';
if f() {
ch = b'?';
}
}
// baz needs to be mut
let mut baz = 0;
//~^ ERROR `if _ { .. } else { .. }` is an expression