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

clippy::redundant_closure false positive: laziness #4187

Closed
projedi opened this issue Jun 9, 2019 · 1 comment · Fixed by #4190
Closed

clippy::redundant_closure false positive: laziness #4187

projedi opened this issue Jun 9, 2019 · 1 comment · Fixed by #4190
Labels
good-first-issue These issues are a good way to get started with Clippy L-suggestion Lint: Improving, adding or fixing lint suggestions

Comments

@projedi
Copy link
Contributor

projedi commented Jun 9, 2019

Clippy warns me about redundant closure:

warning: redundant closure found
   --> src/parser_lib.rs:291:14
    |
291 |     Box::new(move |s| pf()(s))
    |              ^^^^^^^^^^^^^^^^ help: remove closure as shown: `pf()`
    |
    = note: #[warn(clippy::redundant_closure)] on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure

But the suggested transformation changes semantics: the original code executes pf only when the closure is executed; the suggested code executes pf immediately.

> cargo clippy -V
clippy 0.0.212 (265318db 2019-05-17)
@llogiq
Copy link
Contributor

llogiq commented Jun 9, 2019

We should check if the path expr is indeed a Path. Should be simple enough.

@flip1995 flip1995 added L-suggestion Lint: Improving, adding or fixing lint suggestions good-first-issue These issues are a good way to get started with Clippy labels Jun 9, 2019
llogiq added a commit that referenced this issue Jun 10, 2019
bors added a commit that referenced this issue Jun 10, 2019
Fixing eta with respect to lazy evaluation.

This fixes #4187

changelog: `redundant_closure`: stop linting on expressions returning a function, which is then directly used by the closure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good-first-issue These issues are a good way to get started with Clippy L-suggestion Lint: Improving, adding or fixing lint suggestions
Projects
None yet
3 participants