Skip to content

Commit 5623e9e

Browse files
committed
Merge pull request #559 from mcarton/redundant_closure
Fix redundant_closure false positive
2 parents 4293c77 + 9d5e9cf commit 5623e9e

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/eta_reduction.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,16 @@ fn check_closure(cx: &LateContext, expr: &Expr) {
4545
// || {foo(); bar()}; can't be reduced here
4646
return;
4747
}
48+
4849
if let Some(ref ex) = blk.expr {
4950
if let ExprCall(ref caller, ref args) = ex.node {
5051
if args.len() != decl.inputs.len() {
5152
// Not the same number of arguments, there
5253
// is no way the closure is the same as the function
5354
return;
5455
}
55-
if args.iter().any(|arg| is_adjusted(cx, arg)) {
56-
// Are the arguments type-adjusted? Then we need the closure
56+
if is_adjusted(cx, ex) || args.iter().any(|arg| is_adjusted(cx, arg)) {
57+
// Are the expression or the arguments type-adjusted? Then we need the closure
5758
return;
5859
}
5960
let fn_ty = cx.tcx.expr_ty(caller);

tests/compile-fail/eta.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ fn main() {
2121
unsafe {
2222
Some(1u8).map(|a| unsafe_fn(a)); // unsafe fn
2323
}
24+
25+
// See #515
26+
let a: Option<Box<::std::ops::Deref<Target = [i32]>>> =
27+
Some(vec![1i32, 2]).map(|v| -> Box<::std::ops::Deref<Target = [i32]>> { Box::new(v) });
2428
}
2529

2630
fn meta<F>(f: F) where F: Fn(u8) {

0 commit comments

Comments
 (0)