From 9d5e9cfd97e69ddef1e25562ecd4d351e655ae17 Mon Sep 17 00:00:00 2001 From: mcarton Date: Mon, 18 Jan 2016 19:28:06 +0100 Subject: [PATCH] Fix redundant_closure false positive --- src/eta_reduction.rs | 5 +++-- tests/compile-fail/eta.rs | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/eta_reduction.rs b/src/eta_reduction.rs index 46c458c6bcb6..fcc1a6893b26 100644 --- a/src/eta_reduction.rs +++ b/src/eta_reduction.rs @@ -45,6 +45,7 @@ fn check_closure(cx: &LateContext, expr: &Expr) { // || {foo(); bar()}; can't be reduced here return; } + if let Some(ref ex) = blk.expr { if let ExprCall(ref caller, ref args) = ex.node { if args.len() != decl.inputs.len() { @@ -52,8 +53,8 @@ fn check_closure(cx: &LateContext, expr: &Expr) { // is no way the closure is the same as the function return; } - if args.iter().any(|arg| is_adjusted(cx, arg)) { - // Are the arguments type-adjusted? Then we need the closure + if is_adjusted(cx, ex) || args.iter().any(|arg| is_adjusted(cx, arg)) { + // Are the expression or the arguments type-adjusted? Then we need the closure return; } let fn_ty = cx.tcx.expr_ty(caller); diff --git a/tests/compile-fail/eta.rs b/tests/compile-fail/eta.rs index a51d116d9cc8..1ffca9ac5ceb 100644 --- a/tests/compile-fail/eta.rs +++ b/tests/compile-fail/eta.rs @@ -21,6 +21,10 @@ fn main() { unsafe { Some(1u8).map(|a| unsafe_fn(a)); // unsafe fn } + + // See #515 + let a: Option>> = + Some(vec![1i32, 2]).map(|v| -> Box<::std::ops::Deref> { Box::new(v) }); } fn meta(f: F) where F: Fn(u8) {