]> git.lizzy.rs Git - rust.git/commitdiff
Fix an invalid suggestion in `needless_collect` test
authorTakayuki Nakata <f.seasons017@gmail.com>
Wed, 21 Oct 2020 13:33:41 +0000 (22:33 +0900)
committerTakayuki Nakata <f.seasons017@gmail.com>
Sun, 25 Oct 2020 14:58:14 +0000 (23:58 +0900)
clippy_lints/src/loops.rs
tests/ui/needless_collect_indirect.stderr

index 23ca35fffaaf1850ca753dd6f0aa1667be987bec..c3f75f283f498494b27fd76d1c71c56fdd5a4cd3 100644 (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 {
index 0c1e61d749661c5fb4a00652e75f6165407d08a8..7b8e227f304c1b4a64ed4f77f7fe3ce7f4ee2a0e 100644 (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