Skip to content

Commit edab094

Browse files
committed
Fix an invalid suggestion in needless_collect test
1 parent 85959be commit edab094

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
@@ -2920,7 +2920,14 @@ impl IterFunction {
29202920
IterFunctionKind::IntoIter => String::new(),
29212921
IterFunctionKind::Len => String::from(".count()"),
29222922
IterFunctionKind::IsEmpty => String::from(".next().is_none()"),
2923-
IterFunctionKind::Contains(span) => format!(".any(|x| x == {})", snippet(cx, *span, "..")),
2923+
IterFunctionKind::Contains(span) => {
2924+
let s = snippet(cx, *span, "..");
2925+
if let Some(stripped) = s.strip_prefix('&') {
2926+
format!(".any(|x| x == {})", stripped)
2927+
} else {
2928+
format!(".any(|x| x == *{})", s)
2929+
}
2930+
},
29242931
}
29252932
}
29262933
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)