diff --git a/clippy_lints/src/let_if_seq.rs b/clippy_lints/src/let_if_seq.rs index a85cb52f2dc6..2f98d10dee0b 100644 --- a/clippy_lints/src/let_if_seq.rs +++ b/clippy_lints/src/let_if_seq.rs @@ -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, diff --git a/tests/compile-fail/let_if_seq.rs b/tests/compile-fail/let_if_seq.rs index 0b086faf077d..b49e5a261223 100644 --- a/tests/compile-fail/let_if_seq.rs +++ b/tests/compile-fail/let_if_seq.rs @@ -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