Fix an invalid suggestion in needless_collect test

This commit is contained in:
Takayuki Nakata 2020-10-21 22:33:41 +09:00
parent 9c9aa2db52
commit 3ce820bf83
2 changed files with 9 additions and 2 deletions

View File

@ -3001,7 +3001,14 @@ fn get_iter_method(&self, cx: &LateContext<'_>) -> String {
IterFunctionKind::IntoIter => String::new(),
IterFunctionKind::Len => String::from(".count()"),
IterFunctionKind::IsEmpty => String::from(".next().is_none()"),
IterFunctionKind::Contains(span) => format!(".any(|x| x == {})", snippet(cx, *span, "..")),
IterFunctionKind::Contains(span) => {
let s = snippet(cx, *span, "..");
if let Some(stripped) = s.strip_prefix('&') {
format!(".any(|x| x == {})", stripped)
} else {
format!(".any(|x| x == *{})", s)
}
},
}
}
fn get_suggestion_text(&self) -> &'static str {

View File

@ -48,7 +48,7 @@ LL | | indirect_contains.contains(&&5);
help: Check if the original Iterator contains an element instead of collecting then checking
|
LL |
LL | sample.iter().any(|x| x == &&5);
LL | sample.iter().any(|x| x == &5);
|
error: aborting due to 4 previous errors