-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 in redundant_closure when closure value's lifetime is constrained #4002
Comments
I believe this false positive is distinct from the other false positives so far reported against redundant_closure:
|
I'm surprised we're getting so many new false positives for (It's probably worth bisecting at some point!) |
@Manishearth It seems that majority of those problems are related to #3469. I covered the corner cases I found during implementation but it looks like there are more of them. |
Ah, I see. That makes sense. |
Relatedly, the same happens if the mutability of references is different. Repro: fn call<F: FnOnce(&mut String) -> String>(f: F) -> String {
f(&mut "Hello".to_owned())
}
fn main() {
call(|s| s.clone());
}
Removing the closure: fn call<F: FnOnce(&mut String) -> String>(f: F) -> String {
f(&mut "Hello".to_owned())
}
fn main() {
call(Clone::clone);
}
|
|
Clippy recommends
take(G::f)
:The original code compiles, while the code suggested by Clippy does not:
I believe the difference is that
|v| G::f(v)
is an ordinary 'static closure(Arg) -> ()
that captures nothing andG
does not appear in its type, whileG::f
is according to the compiler afn(Arg) {<G as Trait>::f}
in whichG
does appear. Due toG
appearing in its official type, the closure cannot be considered 'static unlessG
is 'static.Mentioning @dgreid who encountered this in Chrome OS.
clippy 0.0.212 (fbb3a47 2019-04-14)
The text was updated successfully, but these errors were encountered: