about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAndré Luis Leal Cardoso Junior <andrehjr@gmail.com>2019-04-28 15:19:05 -0300
committerAndré Luis Leal Cardoso Junior <andrehjr@gmail.com>2019-04-30 16:45:32 -0300
commite428862c955a149ae16d9bb3e56b5087819a122f (patch)
treee14ce89a3e2cd7afeaf8344cb77fef6fbbc94508
parentb411391f8e350a18c08151d270521e44e6417659 (diff)
downloadrust-e428862c955a149ae16d9bb3e56b5087819a122f.tar.gz
rust-e428862c955a149ae16d9bb3e56b5087819a122f.zip
Update find(p).map(p) occurrences to use find_map(p)
-rw-r--r--clippy_lints/src/shadow.rs4
-rw-r--r--clippy_lints/src/utils/attrs.rs14
-rw-r--r--tests/compile-test.rs11
3 files changed, 20 insertions, 9 deletions
diff --git a/clippy_lints/src/shadow.rs b/clippy_lints/src/shadow.rs
index e43b591a9cd..63d75be1da2 100644
--- a/clippy_lints/src/shadow.rs
+++ b/clippy_lints/src/shadow.rs
@@ -186,7 +186,9 @@ fn check_pat<'a, 'tcx>(
                 if let ExprKind::Struct(_, ref efields, _) = init_struct.node {
                     for field in pfields {
                         let name = field.node.ident.name;
-                        let efield = efields.iter().find(|f| f.ident.name == name).map(|f| &*f.expr);
+                        let efield = efields
+                            .iter()
+                            .find_map(|f| if f.ident.name == name { Some(&*f.expr) } else { None });
                         check_pat(cx, &field.node.pat, efield, span, bindings);
                     }
                 } else {
diff --git a/clippy_lints/src/utils/attrs.rs b/clippy_lints/src/utils/attrs.rs
index fbd36ba71de..bec8d53714e 100644
--- a/clippy_lints/src/utils/attrs.rs
+++ b/clippy_lints/src/utils/attrs.rs
@@ -58,10 +58,16 @@ pub fn get_attr<'a>(
     attrs.iter().filter(move |attr| {
         let attr_segments = &attr.path.segments;
         if attr_segments.len() == 2 && attr_segments[0].ident.to_string() == "clippy" {
-            if let Some(deprecation_status) = BUILTIN_ATTRIBUTES
-                .iter()
-                .find(|(builtin_name, _)| *builtin_name == attr_segments[1].ident.to_string())
-                .map(|(_, deprecation_status)| deprecation_status)
+            if let Some(deprecation_status) =
+                BUILTIN_ATTRIBUTES
+                    .iter()
+                    .find_map(|(builtin_name, deprecation_status)| {
+                        if *builtin_name == attr_segments[1].ident.to_string() {
+                            Some(deprecation_status)
+                        } else {
+                            None
+                        }
+                    })
             {
                 let mut db = sess.struct_span_err(attr_segments[1].ident.span, "Usage of deprecated attribute");
                 match deprecation_status {
diff --git a/tests/compile-test.rs b/tests/compile-test.rs
index 65561b7fbd7..663e55d8ea2 100644
--- a/tests/compile-test.rs
+++ b/tests/compile-test.rs
@@ -61,10 +61,13 @@ fn config(mode: &str, dir: PathBuf) -> compiletest::Config {
             let name = path.file_name()?.to_string_lossy();
             // NOTE: This only handles a single dep
             // https://github.com/laumann/compiletest-rs/issues/101
-            needs_disambiguation
-                .iter()
-                .find(|dep| name.starts_with(&format!("lib{}-", dep)))
-                .map(|dep| format!("--extern {}={}", dep, path.display()))
+            needs_disambiguation.iter().find_map(|dep| {
+                if name.starts_with(&format!("lib{}-", dep)) {
+                    Some(format!("--extern {}={}", dep, path.display()))
+                } else {
+                    None
+                }
+            })
         })
         .collect::<Vec<_>>();