let Some(def) = cx.tcx.def_map.borrow().get(&decl.pat.id),
let hir::StmtExpr(ref if_, _) = expr.node,
let hir::ExprIf(ref cond, ref then, ref else_) = if_.node,
- {
- let mut v = UsedVisitor { cx: cx, id: def.def_id(), used: false };
- hir::intravisit::walk_expr(&mut v, cond);
- !v.used
- },
+ !used_in_expr(cx, def.def_id(), cond),
let Some(value) = check_assign(cx, def.def_id(), then),
+ !used_in_expr(cx, def.def_id(), value),
], {
let span = codemap::mk_sp(stmt.span.lo, if_.span.hi);
None
}
+
+fn used_in_expr(cx: &LateContext, id: hir::def_id::DefId, expr: &hir::Expr) -> bool {
+ let mut v = UsedVisitor {
+ cx: cx,
+ id: id,
+ used: false
+ };
+ hir::intravisit::walk_expr(&mut v, expr);
+ v.used
+}
#![deny(useless_let_if_seq)]
fn f() -> bool { true }
+fn g(x: i32) -> i32 { x + 1 }
+
+fn issue985() -> i32 {
+ let mut x = 42;
+ if f() {
+ x = g(x);
+ }
+
+ x
+}
+
+fn issue985_alt() -> i32 {
+ let mut x = 42;
+ if f() {
+ f();
+ } else {
+ x = g(x);
+ }
+
+ x
+}
fn issue975() -> String {
let mut udn = "dummy".to_string();
fn main() {
early_return();
issue975();
+ issue985();
+ issue985_alt();
let mut foo = 0;
//~^ ERROR `if _ { .. } else { .. }` is an expression