Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not trigger redundant_closure for non-function types #4008

Merged
merged 2 commits into from
Apr 25, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions clippy_lints/src/eta_reduction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should include FnPtr and Closure.

Use matches! if it works here, otherwise you can move this check below to the then block as a match


if !type_is_unsafe_function(cx, fn_ty);

if compare_inputs(&mut iter_input_pats(decl, body), &mut args.into_iter());
Expand Down
5 changes: 5 additions & 0 deletions tests/ui/eta.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,8 @@ fn divergent(_: u8) -> ! {
fn generic<T>(_: T) -> u8 {
0
}

fn passes_fn_mut(mut x: Box<dyn FnMut()>) {
requires_fn_once(|| x());
}
fn requires_fn_once<T: FnOnce()>(_: T) {}
5 changes: 5 additions & 0 deletions tests/ui/eta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,8 @@ fn divergent(_: u8) -> ! {
fn generic<T>(_: T) -> u8 {
0
}

fn passes_fn_mut(mut x: Box<dyn FnMut()>) {
requires_fn_once(|| x());
}
fn requires_fn_once<T: FnOnce()>(_: T) {}