Skip to content

redundant_closure: FnOnce is not general enough #7983

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

Closed
jonhoo opened this issue Nov 17, 2021 · 2 comments
Closed

redundant_closure: FnOnce is not general enough #7983

jonhoo opened this issue Nov 17, 2021 · 2 comments
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 I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@jonhoo
Copy link
Contributor

jonhoo commented Nov 17, 2021

Lint name: redundant_closure

I tried this code:

fn main() {
    std::iter::once(String::new()).find(|s| check(s));
}

pub fn check<T: AsRef<str>>(_: T) -> bool {
    true
}

Clippy recommended I rewrite it to:

std::iter::once(String::new()).find(check);

I expected to see this happen: if I apply Clippy's suggestion, my code would compile.

Instead, this happened: applying Clippy's suggested edit causes the code to no longer compile, yielding:

error: implementation of `std::ops::FnOnce` is not general enough
 --> src/main.rs:2:36
  |
2 |     std::iter::once(String::new()).find(check);
  |                                    ^^^^ implementation of `std::ops::FnOnce` is not general enough
  |
  = note: `fn(&'2 std::string::String) -> bool {check::<&'2 std::string::String>}` must implement `std::ops::FnOnce<(&'1 std::string::String,)>`, for any lifetime `'1`...
  = note: ...but it actually implements `std::ops::FnOnce<(&'2 std::string::String,)>`, for some specific lifetime `'2`

FWIW, the actual function causing me this issue was cargo::util::restricted_names::is_glob_pattern.

Meta

Rust version (rustc -Vv):

rustc 1.56.1 (59eed8a2a 2021-11-01)
binary: rustc
commit-hash: 59eed8a2aac0230a8b53e89d4e99d55912ba6b35
commit-date: 2021-11-01
host: x86_64-apple-darwin
release: 1.56.1
LLVM version: 13.0.0
@jonhoo jonhoo 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 Nov 17, 2021
@jonhoo
Copy link
Contributor Author

jonhoo commented Nov 17, 2021

@rustbot label +I-suggestion-causes-error

@rustbot rustbot added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Nov 17, 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 I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

No branches or pull requests

4 participants