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

False positive for redundant_closure_call when called in a closure #5916

Closed
Systemcluster opened this issue Aug 17, 2020 · 2 comments · Fixed by #5920
Closed

False positive for redundant_closure_call when called in a closure #5916

Systemcluster opened this issue Aug 17, 2020 · 2 comments · Fixed by #5920
Labels
C-bug Category: Clippy is not doing the correct thing good-first-issue These issues are a good way to get started with Clippy

Comments

@Systemcluster
Copy link

Minimal example:

fn fun<T: 'static + FnMut()>(mut f: T) {
    f();
}

fn main() {
    let mut x;
    let create = || 2 * 2;
    x = create();

    fun(move || {
        println!("using x here {}", x);
        x = create();
        println!("to avoid non-relevant warnings {}", x);
    })
}

create is called in two spots, but on the first x = create(); a warning: closure called just once immediately after it was declared is emitted.

Interestingly, the warning is not emitted when any statement is between the definitian and the first usage of the closure:

let create = || 2 * 2;
println!("no warning emitted with this line");
x = create();

Meta

  • cargo clippy -V: clippy 0.0.212 (9b88e0a86 2020-08-15)
  • rustc -Vv:
    rustc 1.47.0-nightly (9b88e0a86 2020-08-15)
    binary: rustc
    commit-hash: 9b88e0a8667040452a94fda8548f0f5f0f801f90
    commit-date: 2020-08-15
    host: x86_64-pc-windows-msvc
    release: 1.47.0-nightly
    LLVM version: 10.0
    
@Systemcluster Systemcluster added the C-bug Category: Clippy is not doing the correct thing label Aug 17, 2020
@flip1995 flip1995 added the good-first-issue These issues are a good way to get started with Clippy label Aug 17, 2020
@flip1995
Copy link
Member

This lint is probably implemented with a visitor. The fix is easy: The nested_visit_map method should at least return NestedVisitorMap::OnlyBodies

@giraffate
Copy link
Contributor

I will prepare a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing good-first-issue These issues are a good way to get started with Clippy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants