]> git.lizzy.rs Git - rust.git/commitdiff
Fix yet another FP in `USELESS_LET_IF_SEQ`
authormcarton <cartonmartin+git@gmail.com>
Wed, 8 Jun 2016 22:22:59 +0000 (00:22 +0200)
committermcarton <cartonmartin+git@gmail.com>
Thu, 9 Jun 2016 21:33:38 +0000 (23:33 +0200)
The block expression before the assignment must be `None`.

clippy_lints/src/let_if_seq.rs
tests/compile-fail/let_if_seq.rs

index a85cb52f2dc6e0d4687750474fb0ca879710c2e9..2f98d10dee0bb68c07c02e6f8852b563c23a7201 100644 (file)
@@ -150,6 +150,7 @@ fn visit_expr(&mut self, expr: &'v hir::Expr) {
 
 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,
index 0b086faf077d45ed565f96baa8a616e87f3b5116..b49e5a2612239bb08cb7eb609c7af2b8d54e186b 100644 (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