Merge pull request #559 from mcarton/redundant_closure

Fix redundant_closure false positive
This commit is contained in:
llogiq 2016-01-18 19:33:42 +01:00
commit 5623e9e601
2 changed files with 7 additions and 2 deletions

View file

@ -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);

View file

@ -21,6 +21,10 @@ fn main() {
unsafe {
Some(1u8).map(|a| unsafe_fn(a)); // unsafe fn
}
// See #515
let a: Option<Box<::std::ops::Deref<Target = [i32]>>> =
Some(vec![1i32, 2]).map(|v| -> Box<::std::ops::Deref<Target = [i32]>> { Box::new(v) });
}
fn meta<F>(f: F) where F: Fn(u8) {