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

Redundant closure gives invalid suggestion #7218

Closed
rcoh opened this issue May 13, 2021 · 1 comment
Closed

Redundant closure gives invalid suggestion #7218

rcoh opened this issue May 13, 2021 · 1 comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@rcoh
Copy link
Contributor

rcoh commented May 13, 2021

Lint name: redundant_closure

I tried this code:

use std::env::VarError;
fn main() {
    
    let _x: Box<dyn Fn(&str) -> Result<String, VarError> + Send + Sync> = 
        Box::new(|key|std::env::var(key));
        
        
    // does not compile:
    // let _x: Box<dyn Fn(&str) -> Result<String, VarError> + Send + Sync> = 
    //    Box::new(std::env::var);
}

I expected to see this happen: Clippy should not suggest redundant_closure, because of lifetime inference, the closure is required:

   Compiling playground v0.0.1 (/playground)
error: implementation of `FnOnce` is not general enough
  --> src/main.rs:10:9
   |
10 |         Box::new(std::env::var);
   |         ^^^^^^^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
   |
   = note: `fn(&'2 str) -> Result<String, VarError> {var::<&'2 str>}` must implement `FnOnce<(&'1 str,)>`, for any lifetime `'1`...
   = note: ...but it actually implements `FnOnce<(&'2 str,)>`, for some specific lifetime `'2`

Meta

  • cargo clippy -V: clippy 0.1.52 (9bc8c42b 2021-05-09) (also 0.1.54 on playground)
  • rustc -Vv:
rustc 1.52.1 (9bc8c42bb 2021-05-09)
binary: rustc
commit-hash: 9bc8c42bb2f19e745a63f3445f1ac248fb015e53
commit-date: 2021-05-09
host: x86_64-apple-darwin
release: 1.52.1
LLVM version: 12.0.0
@rcoh rcoh added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels May 13, 2021
@Jarcho
Copy link
Contributor

Jarcho commented Apr 11, 2022

This was fixed by #7661.

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 I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

No branches or pull requests

3 participants