From 526afb987bf43f33741c812464416d709300ccce Mon Sep 17 00:00:00 2001
From: Vincent Lafeychine <vincent.lafeychine@proton.me>
Date: Tue, 30 Apr 2024 01:05:44 +0200
Subject: [PATCH] clippy: Fix flat_map_option

---
 rr_frontend/.cargo/config.toml                        |  1 -
 .../translation/src/environment/polonius_info.rs      | 11 ++++++-----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/rr_frontend/.cargo/config.toml b/rr_frontend/.cargo/config.toml
index 2ce07d42..007836ff 100644
--- a/rr_frontend/.cargo/config.toml
+++ b/rr_frontend/.cargo/config.toml
@@ -32,7 +32,6 @@ rustflags = [
     "-Aclippy::string_lit_as_bytes",
 
     # clippy::pedantic
-    "-Aclippy::flat_map_option",
     "-Aclippy::from_iter_instead_of_collect",
     "-Aclippy::if_not_else",
     "-Aclippy::inefficient_to_string",
diff --git a/rr_frontend/translation/src/environment/polonius_info.rs b/rr_frontend/translation/src/environment/polonius_info.rs
index 96d1d48d..cb363658 100644
--- a/rr_frontend/translation/src/environment/polonius_info.rs
+++ b/rr_frontend/translation/src/environment/polonius_info.rs
@@ -371,7 +371,7 @@ fn get_borrowed_places<'a, 'tcx: 'a>(
 
                 mir::Rvalue::Aggregate(_, ref operands) => Ok(operands
                     .iter()
-                    .flat_map(|operand| match *operand {
+                    .filter_map(|operand| match *operand {
                         mir::Operand::Copy(ref place) | mir::Operand::Move(ref place) => Some(place),
                         mir::Operand::Constant(_) => None,
                     })
@@ -1250,17 +1250,17 @@ impl<'a, 'tcx: 'a> PoloniusInfo<'a, 'tcx> {
     ) -> Result<Vec<(facts::Loan, mir::BasicBlock)>, PoloniusInfoError> {
         let pairs: Vec<_> = loans
             .iter()
-            .flat_map(|loan| {
-                let loan_location = if let Some(location) = self.loan_position.get(loan) {
-                    location
-                } else {
+            .filter_map(|loan| {
+                let Some(loan_location) = self.loan_position.get(loan) else {
                     // FIXME (Vytautas): This is likely to be wrong.
                     debug!("ERROR: not found for loan: {:?}", loan);
                     return None;
                 };
+
                 self.loops.get_loop_head(loan_location.block).map(|loop_head| (*loan, loop_head))
             })
             .collect();
+
         for (loan1, loop1) in &pairs {
             let location1 = self.loan_position[loan1];
             for (loan2, loop2) in &pairs {
@@ -1270,6 +1270,7 @@ impl<'a, 'tcx: 'a> PoloniusInfo<'a, 'tcx> {
                 }
             }
         }
+
         Ok(pairs)
     }
 
-- 
GitLab