]> git.lizzy.rs Git - rust.git/blobdiff - clippy_utils/src/lib.rs
Auto merge of #7256 - xFrednet:7172-trick-cargos-caching-for-collection, r=flip1995
[rust.git] / clippy_utils / src / lib.rs
index 18b7e6cd4bcdc194f5980d6dd169dcc27d033acd..769836aaf18ed6c54c3773c5c4e052e8528f96c5 100644 (file)
@@ -667,7 +667,7 @@ pub fn method_chain_args<'a>(expr: &'a Expr<'_>, methods: &[&str]) -> Option<Vec
                     return None;
                 }
                 matched.push(args); // build up `matched` backwards
-                current = &args[0] // go to parent expression
+                current = &args[0]; // go to parent expression
             } else {
                 return None;
             }
@@ -1094,9 +1094,9 @@ fn are_refutable<'a, I: Iterator<Item = &'a Pat<'a>>>(cx: &LateContext<'_>, mut
 /// the function once on the given pattern.
 pub fn recurse_or_patterns<'tcx, F: FnMut(&'tcx Pat<'tcx>)>(pat: &'tcx Pat<'tcx>, mut f: F) {
     if let PatKind::Or(pats) = pat.kind {
-        pats.iter().copied().for_each(f)
+        pats.iter().copied().for_each(f);
     } else {
-        f(pat)
+        f(pat);
     }
 }
 
@@ -1572,8 +1572,10 @@ pub fn search_same<T, Hash, Eq>(exprs: &[T], hash: Hash, eq: Eq) -> Vec<(&T, &T)
     Hash: Fn(&T) -> u64,
     Eq: Fn(&T, &T) -> bool,
 {
-    if exprs.len() == 2 && eq(&exprs[0], &exprs[1]) {
-        return vec![(&exprs[0], &exprs[1])];
+    match exprs {
+        [a, b] if eq(a, b) => return vec![(a, b)],
+        _ if exprs.len() <= 2 => return vec![],
+        _ => {},
     }
 
     let mut match_expr_list: Vec<(&T, &T)> = Vec::new();