]> git.lizzy.rs Git - rust.git/commitdiff
Use find_map instead of find() + map()
authorEduardo Broto <ebroto@tutanota.com>
Sun, 24 May 2020 19:17:54 +0000 (21:17 +0200)
committerEduardo Broto <ebroto@tutanota.com>
Mon, 25 May 2020 18:00:08 +0000 (20:00 +0200)
clippy_lints/src/multiple_crate_versions.rs

index b24ec897ef5ad3682f2e4b04777f689c1da42e52..b6770804e180118736898314e6f94615d67a93ec 100644 (file)
@@ -37,7 +37,6 @@
 declare_lint_pass!(MultipleCrateVersions => [MULTIPLE_CRATE_VERSIONS]);
 
 impl LateLintPass<'_, '_> for MultipleCrateVersions {
-    #[allow(clippy::find_map)]
     fn check_crate(&mut self, cx: &LateContext<'_, '_>, _: &Crate<'_>) {
         if !run_lints(cx, &[MULTIPLE_CRATE_VERSIONS], CRATE_HIR_ID) {
             return;
@@ -56,7 +55,9 @@ fn check_crate(&mut self, cx: &LateContext<'_, '_>, _: &Crate<'_>) {
 
         if_chain! {
             if let Some(resolve) = &metadata.resolve;
-            if let Some(local_id) = packages.iter().find(|p| p.name == *local_name).map(|p| &p.id);
+            if let Some(local_id) = packages
+                .iter()
+                .find_map(|p| if p.name == *local_name { Some(&p.id) } else { None });
             then {
                 for (name, group) in &packages.iter().group_by(|p| p.name.clone()) {
                     let group: Vec<&Package> = group.collect();