Open alphastrata opened 1 year ago
I ran into a similar issue.
reproducer:
fn reproducer() {
let mut list = vec![1, 2];
list = list.iter().filter(|i| list.len() == **i).cloned().collect();
println!("{:#?}", list);
}
clippy suggested:
fn reproducer_clippy_suggested() {
let mut list = vec![1, 2];
list.retain(|i| list.len() == **i); // original suggestion: wrong dereference level
//list.retain(|i| list.len() == *i); // (after deref correction) also, fails due to borrow
println!("{:#?}", list);
}
Two issues in the suggestion:
Clippy version: clippy 0.1.76 (07dca489 2024-02-04)
Summary
Just an incorrect suggestion? of a manual_retain when there's existing (perhaps non-trivial) borrows in the mix.
[rust playground minimal example] (https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=d8768d458b40ee2be9f055301ec61109)
Lint Name
manual_retain
Reproducer
I tried this code:
I saw this happen:
Which if you take the advice (see the commented out
fn clippy_refactor()
above, gives you:I expected to see this happen: No lint in this instance.
Version
Additional Labels
No response