-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Conversation
clippy_lints/src/eta_reduction.rs
Outdated
@@ -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; |
There was a problem hiding this comment.
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
Does this also fix #1439? (No problem if it doesn't, just making sure) |
@phansch The lint does not trigger for the original example (#1439 (comment)). It does trigger for the "minimal repro" (#1439 (comment)) but the suggestion is correct in this case (there is no Box involved, just plain closure) so it seems that the answer is yes. |
@bors r+ thanks! |
📌 Commit 4f801a2 has been approved by |
Do not trigger redundant_closure for non-function types fixes #3898 Added a check for the entity being called in the closure body to be a FnDef. This way lint does not trigger for ADTs (Box) but I'm not sure if it's correct and not too restrictive. <!-- Thank you for making Clippy better! We're collecting our changelog from pull request descriptions. If your PR only updates to the latest nightly, you can leave the `changelog` entry as `none`. Otherwise, please write a short comment explaining your change. If your PR fixes an issue, you can add "fixes #issue_number" into this PR description. This way the issue will be automatically closed when your PR is merged. If you added a new lint, here's a checklist for things that will be checked during review or continuous integration. - [ ] Followed [lint naming conventions][lint_naming] - [ ] Added passing UI tests (including committed `.stderr` file) - [ ] `cargo test` passes locally - [ ] Executed `util/dev update_lints` - [ ] Added lint documentation - [ ] Run `cargo fmt` Note that you can skip the above if you are just opening a WIP PR in order to get feedback. Delete this line and everything above before opening your PR --> changelog: Fix false positive in `redundant_closure` pertaining to non-function types
☀️ Test successful - checks-travis, status-appveyor |
These two cases were fixed by rust-lang#4008. Closes rust-lang#1439 changelog: none
These two cases were fixed by rust-lang#4008. Closes rust-lang#1439 changelog: none
fixes #3898
Added a check for the entity being called in the closure body to be a FnDef. This way lint does not trigger for ADTs (Box) but I'm not sure if it's correct and not too restrictive.
changelog: Fix false positive in
redundant_closure
pertaining to non-function types