Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 3ce820b

Browse files
committed
Fix an invalid suggestion in needless_collect test
1 parent 9c9aa2d commit 3ce820b

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

clippy_lints/src/loops.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3001,7 +3001,14 @@ impl IterFunction {
30013001
IterFunctionKind::IntoIter => String::new(),
30023002
IterFunctionKind::Len => String::from(".count()"),
30033003
IterFunctionKind::IsEmpty => String::from(".next().is_none()"),
3004-
IterFunctionKind::Contains(span) => format!(".any(|x| x == {})", snippet(cx, *span, "..")),
3004+
IterFunctionKind::Contains(span) => {
3005+
let s = snippet(cx, *span, "..");
3006+
if let Some(stripped) = s.strip_prefix('&') {
3007+
format!(".any(|x| x == {})", stripped)
3008+
} else {
3009+
format!(".any(|x| x == *{})", s)
3010+
}
3011+
},
30053012
}
30063013
}
30073014
fn get_suggestion_text(&self) -> &'static str {

tests/ui/needless_collect_indirect.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ LL | | indirect_contains.contains(&&5);
4848
help: Check if the original Iterator contains an element instead of collecting then checking
4949
|
5050
LL |
51-
LL | sample.iter().any(|x| x == &&5);
51+
LL | sample.iter().any(|x| x == &5);
5252
|
5353

5454
error: aborting due to 4 previous errors

0 commit comments

Comments
 (0)