-
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 for unnecessary_filter_map #4433
Comments
Sorry for the duplications - I have no clue how this happened! |
It was probably due to the problems GitHub had earlier today, no worries! |
Here is another example from my code, just to add some test-case diversity (yeah it's ugly, refactor tips are very welcome :p) // "drain_filter"
self.pending_requests = self.pending_requests.drain(..)
.filter_map(|pending| {
if pending.expires <= now {
return None; // Expired, remove
}
if pending.group_id == group_id {
// Matched - reuse strings and remove
node.send_response(pending.reply_to, pending.token, Value::Null)
.on_error_warn();
None
} else {
// Keep waiting
Some(pending)
}
})
.collect(); |
Another sample point of an enumartion extraction
|
I just ran into this issue as well. The lint needs to check that all uses in the closure body can be by shared reference. Another reduced test case: pub struct S(u8);
impl S {
pub fn consume(self) {
println!("yum");
}
}
pub fn filter_owned() -> impl Iterator<Item = S> {
(0..10)
.map(|i| S(i))
.filter_map(|s| {
if s.0 & 1 == 0 {
s.consume();
None
} else {
Some(s)
}
})
} If this lint can't be fixed, then I'd like to see Clippy default to |
These are good opportunities to thank the Clippy maintainers. That we're willing to put up with a quirk every so often is a testament to Clippy's profound usefulness! |
@smoelius Yeah, Clippy is an amazing tool — I only expect so much of it because I know how good its developers are. 🙂 |
cargo clippy -V
clippy 0.0.212 (e3cb40e 2019-06-25)
A warning is produced from
The code splits moves some items from one collection into a second. If I'd use filter, as recommended, then I would have to clone the
se
s, and discard the original instances.The text was updated successfully, but these errors were encountered: