From aa9cf07d56fac7044e6890d66759ab9903d352ef Mon Sep 17 00:00:00 2001 From: Grzegorz Date: Sun, 31 Mar 2019 14:10:17 +0200 Subject: [PATCH] redundant closure for functions restricted to FnDefs --- clippy_lints/src/eta_reduction.rs | 3 +++ tests/ui/eta.fixed | 5 +++++ tests/ui/eta.rs | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index 63abe47b4428..cb17ef18429a 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -65,6 +65,9 @@ fn check_closure(cx: &LateContext<'_, '_>, expr: &Expr) { if !(is_adjusted(cx, ex) || args.iter().any(|arg| is_adjusted(cx, arg))); let fn_ty = cx.tables.expr_ty(caller); + + if let ty::FnDef(_, _) = fn_ty.sty; + if !type_is_unsafe_function(cx, fn_ty); if compare_inputs(&mut iter_input_pats(decl, body), &mut args.into_iter()); diff --git a/tests/ui/eta.fixed b/tests/ui/eta.fixed index 7e487fe21679..6f9457a4a29d 100644 --- a/tests/ui/eta.fixed +++ b/tests/ui/eta.fixed @@ -133,3 +133,8 @@ fn divergent(_: u8) -> ! { fn generic(_: T) -> u8 { 0 } + +fn passes_fn_mut(mut x: Box) { + requires_fn_once(|| x()); +} +fn requires_fn_once(_: T) {} diff --git a/tests/ui/eta.rs b/tests/ui/eta.rs index a0d83c438251..11f142e17dfb 100644 --- a/tests/ui/eta.rs +++ b/tests/ui/eta.rs @@ -133,3 +133,8 @@ fn divergent(_: u8) -> ! { fn generic(_: T) -> u8 { 0 } + +fn passes_fn_mut(mut x: Box) { + requires_fn_once(|| x()); +} +fn requires_fn_once(_: T) {}