From 1f78f4e3dd301dc058930680633cca5e00c605db Mon Sep 17 00:00:00 2001 From: Vincent Lafeychine <vincent.lafeychine@proton.me> Date: Wed, 1 May 2024 01:08:32 +0200 Subject: [PATCH] clippy: Fix map_unwrap_or --- rr_frontend/.cargo/config.toml | 1 - .../translation/src/environment/loops.rs | 31 +++++++++---------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/rr_frontend/.cargo/config.toml b/rr_frontend/.cargo/config.toml index 30ba7b68..79a81c59 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::map_unwrap_or", "-Aclippy::match_same_arms", "-Aclippy::must_use_candidate", "-Aclippy::needless_continue", diff --git a/rr_frontend/translation/src/environment/loops.rs b/rr_frontend/translation/src/environment/loops.rs index 05185204..4af62bf5 100644 --- a/rr_frontend/translation/src/environment/loops.rs +++ b/rr_frontend/translation/src/environment/loops.rs @@ -268,8 +268,7 @@ impl ProcedureLoops { enclosing_loop_heads .get(&bb) .and_then(|heads| heads.last()) - .map(|bb_head| loop_head_depths[bb_head]) - .unwrap_or(0) + .map_or(0, |bb_head| loop_head_depths[bb_head]) }; let ordered_blocks = order_basic_blocks(mir, real_edges, &back_edges, &get_loop_depth); @@ -395,7 +394,7 @@ impl ProcedureLoops { /// Get the loop-depth of a block (zero if it's not in a loop). pub fn get_loop_depth(&self, bbi: BasicBlockIndex) -> usize { - self.get_loop_head(bbi).map(|x| self.get_loop_head_depth(x)).unwrap_or(0) + self.get_loop_head(bbi).map_or(0, |x| self.get_loop_head_depth(x)) } /// Get the (topologically ordered) body of a loop, given a loop head @@ -406,19 +405,19 @@ impl ProcedureLoops { /// Does this edge exit a loop? pub fn is_out_edge(&self, from: BasicBlockIndex, to: BasicBlockIndex) -> bool { - if let Some(from_loop_head) = self.get_loop_head(from) { - if let Some(to_loop_head) = self.get_loop_head(to) { - if from_loop_head == to_loop_head || to == to_loop_head { - false - } else { - !self.enclosing_loop_heads[&to].contains(&from_loop_head) - } - } else { - true - } - } else { - false - } + let Some(from_loop_head) = self.get_loop_head(from) else { + return false; + }; + + let Some(to_loop_head) = self.get_loop_head(to) else { + return true; + }; + + if from_loop_head == to_loop_head || to == to_loop_head { + return false; + }; + + !self.enclosing_loop_heads[&to].contains(&from_loop_head) } /// Check if ``block`` is inside a given loop. -- GitLab