-
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
redundant_closure suggests wrong fix when the function being called is not Copy #1608
Comments
This should be fixed by suggesting an & before the closure name in case it is not Copy |
That works for the code I posted above but doesn't work in my actual code. Here's a slightly bigger test case which doesn't work with This compiles but Clippy gives the same warning: fn take_while<F>(str: &str, mut f: F)
where F: FnMut(char) -> bool
{
let mut chars = str.chars();
while chars.clone().next().map_or(false, |ch| f(ch)) {
chars.next();
}
}
fn main() {
take_while("...!", |ch| ch == '.');
} With error[E0277]: the trait bound `F: std::ops::Fn<(char,)>` is not satisfied
--> src/main.rs:5:32
|
5 | while chars.clone().next().map_or(false, &f) {
| ^^^^^^ the trait `std::ops::Fn<(char,)>` is not implemented for `F`
|
= help: consider adding a `where F: std::ops::Fn<(char,)>` bound
= note: required because of the requirements on the impl of `std::ops::FnOnce<(char,)>` for `&F` With error[E0382]: use of moved value: `f`
--> src/main.rs:5:46
|
5 | while chars.clone().next().map_or(false, f) {
| ^ value moved here in previous iteration of loop
|
= note: move occurs because `f` has type `F`, which does not implement the `Copy` trait |
Right, in that case we need &mut |
Ahh, thanks! I tried a lot of things to make |
while
I also got the same issue with an non- (If needed I can provide the source code.) |
Code reduced from my actual project:
Clippy:
Clippy's suggestion doesn't compile:
The text was updated successfully, but these errors were encountered: