Skip to content

Commit aa9cf07

Browse files
author
Grzegorz
committed
redundant closure for functions restricted to FnDefs
1 parent 0d9ef39 commit aa9cf07

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

clippy_lints/src/eta_reduction.rs

+3
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ fn check_closure(cx: &LateContext<'_, '_>, expr: &Expr) {
6565
if !(is_adjusted(cx, ex) || args.iter().any(|arg| is_adjusted(cx, arg)));
6666

6767
let fn_ty = cx.tables.expr_ty(caller);
68+
69+
if let ty::FnDef(_, _) = fn_ty.sty;
70+
6871
if !type_is_unsafe_function(cx, fn_ty);
6972

7073
if compare_inputs(&mut iter_input_pats(decl, body), &mut args.into_iter());

tests/ui/eta.fixed

+5
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,8 @@ fn divergent(_: u8) -> ! {
133133
fn generic<T>(_: T) -> u8 {
134134
0
135135
}
136+
137+
fn passes_fn_mut(mut x: Box<dyn FnMut()>) {
138+
requires_fn_once(|| x());
139+
}
140+
fn requires_fn_once<T: FnOnce()>(_: T) {}

tests/ui/eta.rs

+5
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,8 @@ fn divergent(_: u8) -> ! {
133133
fn generic<T>(_: T) -> u8 {
134134
0
135135
}
136+
137+
fn passes_fn_mut(mut x: Box<dyn FnMut()>) {
138+
requires_fn_once(|| x());
139+
}
140+
fn requires_fn_once<T: FnOnce()>(_: T) {}

0 commit comments

Comments
 (0)