about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--clippy_lints/src/eta_reduction.rs3
-rw-r--r--tests/ui/eta.fixed11
-rw-r--r--tests/ui/eta.rs11
-rw-r--r--tests/ui/eta.stderr14
4 files changed, 37 insertions, 2 deletions
diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs
index cb17ef18429..60e2ab8b9b9 100644
--- a/clippy_lints/src/eta_reduction.rs
+++ b/clippy_lints/src/eta_reduction.rs
@@ -1,4 +1,5 @@
 use if_chain::if_chain;
+use matches::matches;
 use rustc::hir::*;
 use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass};
 use rustc::ty::{self, Ty};
@@ -66,7 +67,7 @@ fn check_closure(cx: &LateContext<'_, '_>, expr: &Expr) {
 
             let fn_ty = cx.tables.expr_ty(caller);
 
-            if let ty::FnDef(_, _) = fn_ty.sty;
+            if matches!(fn_ty.sty, ty::FnDef(_, _) | ty::FnPtr(_) | ty::Closure(_, _));
 
             if !type_is_unsafe_function(cx, fn_ty);
 
diff --git a/tests/ui/eta.fixed b/tests/ui/eta.fixed
index 6f9457a4a29..bae9b09c697 100644
--- a/tests/ui/eta.fixed
+++ b/tests/ui/eta.fixed
@@ -138,3 +138,14 @@ fn passes_fn_mut(mut x: Box<dyn FnMut()>) {
     requires_fn_once(|| x());
 }
 fn requires_fn_once<T: FnOnce()>(_: T) {}
+
+fn test_redundant_closure_with_function_pointer() {
+    type FnPtrType = fn(u8);
+    let foo_ptr: FnPtrType = foo;
+    let a = Some(1u8).map(foo_ptr);
+}
+
+fn test_redundant_closure_with_another_closure() {
+    let closure = |a| println!("{}", a);
+    let a = Some(1u8).map(closure);
+}
diff --git a/tests/ui/eta.rs b/tests/ui/eta.rs
index 11f142e17df..a23da73bde7 100644
--- a/tests/ui/eta.rs
+++ b/tests/ui/eta.rs
@@ -138,3 +138,14 @@ fn passes_fn_mut(mut x: Box<dyn FnMut()>) {
     requires_fn_once(|| x());
 }
 fn requires_fn_once<T: FnOnce()>(_: T) {}
+
+fn test_redundant_closure_with_function_pointer() {
+    type FnPtrType = fn(u8);
+    let foo_ptr: FnPtrType = foo;
+    let a = Some(1u8).map(|a| foo_ptr(a));
+}
+
+fn test_redundant_closure_with_another_closure() {
+    let closure = |a| println!("{}", a);
+    let a = Some(1u8).map(|a| closure(a));
+}
diff --git a/tests/ui/eta.stderr b/tests/ui/eta.stderr
index 77423694f81..eb55a251bcc 100644
--- a/tests/ui/eta.stderr
+++ b/tests/ui/eta.stderr
@@ -68,5 +68,17 @@ error: redundant closure found
 LL |     let e: std::vec::Vec<char> = vec!['a', 'b', 'c'].iter().map(|c| c.to_ascii_uppercase()).collect();
    |                                                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove closure as shown: `char::to_ascii_uppercase`
 
-error: aborting due to 11 previous errors
+error: redundant closure found
+  --> $DIR/eta.rs:145:27
+   |
+LL |     let a = Some(1u8).map(|a| foo_ptr(a));
+   |                           ^^^^^^^^^^^^^^ help: remove closure as shown: `foo_ptr`
+
+error: redundant closure found
+  --> $DIR/eta.rs:150:27
+   |
+LL |     let a = Some(1u8).map(|a| closure(a));
+   |                           ^^^^^^^^^^^^^^ help: remove closure as shown: `closure`
+
+error: aborting due to 13 previous errors