diff options
| author | Takayuki Nakata <f.seasons017@gmail.com> | 2020-10-21 22:33:41 +0900 |
|---|---|---|
| committer | Takayuki Nakata <f.seasons017@gmail.com> | 2020-10-25 23:58:14 +0900 |
| commit | 3ce820bf83657879493aa7b107634f1951e7c219 (patch) | |
| tree | 1ce030fbdddd70f1bf0a0853a4c7be01873b0fa7 | |
| parent | 9c9aa2db52dd4d031cb55412771fdba57b52e2c0 (diff) | |
| download | rust-3ce820bf83657879493aa7b107634f1951e7c219.tar.gz rust-3ce820bf83657879493aa7b107634f1951e7c219.zip | |
Fix an invalid suggestion in `needless_collect` test
| -rw-r--r-- | clippy_lints/src/loops.rs | 9 | ||||
| -rw-r--r-- | tests/ui/needless_collect_indirect.stderr | 2 |
2 files changed, 9 insertions, 2 deletions
diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 23ca35fffaa..c3f75f283f4 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -3001,7 +3001,14 @@ impl IterFunction { 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 { diff --git a/tests/ui/needless_collect_indirect.stderr b/tests/ui/needless_collect_indirect.stderr index 0c1e61d7496..7b8e227f304 100644 --- a/tests/ui/needless_collect_indirect.stderr +++ b/tests/ui/needless_collect_indirect.stderr @@ -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 |
