From d5acdc0e7be4ec1bc765086dfd521aaf10120ebc Mon Sep 17 00:00:00 2001 From: Oleksandr Kozachuk Date: Tue, 21 Apr 2026 17:00:21 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20Rust=201.95=20clippy=20=E2=80=94=20match?= =?UTF-8?q?=20guards=20+=20map=5For?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rust 1.95 promoted collapsible_match and map_unwrap_or; CI runs -D warnings so they break the build. Collapse nested `if`s into match guards across codegen/optimizer/export, and swap map().unwrap_or(..) for map_or / is_ok_and. --- crates/core/src/codegen.rs | 46 ++++++++++++++++----------------- crates/core/src/export.rs | 6 ++--- crates/core/src/optimizer.rs | 30 ++++++++++----------- crates/core/src/outer.rs | 3 +-- crates/core/tests/comparison.rs | 3 +-- 5 files changed, 40 insertions(+), 48 deletions(-) diff --git a/crates/core/src/codegen.rs b/crates/core/src/codegen.rs index e2b444f..46d26cc 100644 --- a/crates/core/src/codegen.rs +++ b/crates/core/src/codegen.rs @@ -2012,14 +2012,12 @@ fn emit_promoted_op(f: &mut Function, op: &IrOp, sim: &mut StackSim) { // Outside loops, RFetch shouldn't appear in promoted code } - IrOp::LoopJ => { - if sim.loop_index_stack.len() >= 2 { - let (outer_index, _) = sim.loop_index_stack[sim.loop_index_stack.len() - 2]; - let result = sim.alloc(); - f.instruction(&Instruction::LocalGet(outer_index)); - f.instruction(&Instruction::LocalSet(result)); - sim.push(result); - } + IrOp::LoopJ if sim.loop_index_stack.len() >= 2 => { + let (outer_index, _) = sim.loop_index_stack[sim.loop_index_stack.len() - 2]; + let result = sim.alloc(); + f.instruction(&Instruction::LocalGet(outer_index)); + f.instruction(&Instruction::LocalSet(result)); + sim.push(result); } IrOp::Exit => { @@ -2147,15 +2145,15 @@ fn needs_f64_locals(ops: &[IrOp]) -> bool { return true; } } - IrOp::DoLoop { body, .. } | IrOp::BeginUntil { body } | IrOp::BeginAgain { body } => { - if needs_f64_locals(body) { - return true; - } + IrOp::DoLoop { body, .. } | IrOp::BeginUntil { body } | IrOp::BeginAgain { body } + if needs_f64_locals(body) => + { + return true; } - IrOp::BeginWhileRepeat { test, body } => { - if needs_f64_locals(test) || needs_f64_locals(body) { - return true; - } + IrOp::BeginWhileRepeat { test, body } + if needs_f64_locals(test) || needs_f64_locals(body) => + { + return true; } IrOp::BeginDoubleWhileRepeat { outer_test, @@ -2209,15 +2207,15 @@ fn body_needs_return_stack(ops: &[IrOp]) -> bool { return true; } } - IrOp::DoLoop { body, .. } | IrOp::BeginUntil { body } | IrOp::BeginAgain { body } => { - if body_needs_return_stack(body) { - return true; - } + IrOp::DoLoop { body, .. } | IrOp::BeginUntil { body } | IrOp::BeginAgain { body } + if body_needs_return_stack(body) => + { + return true; } - IrOp::BeginWhileRepeat { test, body } => { - if body_needs_return_stack(test) || body_needs_return_stack(body) { - return true; - } + IrOp::BeginWhileRepeat { test, body } + if body_needs_return_stack(test) || body_needs_return_stack(body) => + { + return true; } IrOp::BeginDoubleWhileRepeat { outer_test, diff --git a/crates/core/src/export.rs b/crates/core/src/export.rs index 1329532..d18a28a 100644 --- a/crates/core/src/export.rs +++ b/crates/core/src/export.rs @@ -131,10 +131,8 @@ pub fn export_module( fn collect_external_calls(ops: &[IrOp], ir_ids: &HashSet, host_ids: &mut HashSet) { for op in ops { match op { - IrOp::Call(id) | IrOp::TailCall(id) => { - if !ir_ids.contains(id) { - host_ids.insert(*id); - } + IrOp::Call(id) | IrOp::TailCall(id) if !ir_ids.contains(id) => { + host_ids.insert(*id); } IrOp::If { then_body, diff --git a/crates/core/src/optimizer.rs b/crates/core/src/optimizer.rs index 59c13a2..291d420 100644 --- a/crates/core/src/optimizer.rs +++ b/crates/core/src/optimizer.rs @@ -591,15 +591,15 @@ fn contains_call_to(ops: &[IrOp], target: WordId) -> bool { return true; } } - IrOp::DoLoop { body, .. } | IrOp::BeginUntil { body } | IrOp::BeginAgain { body } => { - if contains_call_to(body, target) { - return true; - } + IrOp::DoLoop { body, .. } | IrOp::BeginUntil { body } | IrOp::BeginAgain { body } + if contains_call_to(body, target) => + { + return true; } - IrOp::BeginWhileRepeat { test, body } => { - if contains_call_to(test, target) || contains_call_to(body, target) { - return true; - } + IrOp::BeginWhileRepeat { test, body } + if contains_call_to(test, target) || contains_call_to(body, target) => + { + return true; } IrOp::BeginDoubleWhileRepeat { outer_test, @@ -651,15 +651,13 @@ fn contains_exit(ops: &[IrOp]) -> bool { return true; } } - IrOp::DoLoop { body, .. } | IrOp::BeginUntil { body } | IrOp::BeginAgain { body } => { - if contains_exit(body) { - return true; - } + IrOp::DoLoop { body, .. } | IrOp::BeginUntil { body } | IrOp::BeginAgain { body } + if contains_exit(body) => + { + return true; } - IrOp::BeginWhileRepeat { test, body } => { - if contains_exit(test) || contains_exit(body) { - return true; - } + IrOp::BeginWhileRepeat { test, body } if contains_exit(test) || contains_exit(body) => { + return true; } _ => {} } diff --git a/crates/core/src/outer.rs b/crates/core/src/outer.rs index b2c1be3..71b7a35 100644 --- a/crates/core/src/outer.rs +++ b/crates/core/src/outer.rs @@ -397,8 +397,7 @@ impl ForthVM { use std::time::{SystemTime, UNIX_EPOCH}; let seed = SystemTime::now() .duration_since(UNIX_EPOCH) - .map(|d| d.as_nanos() as u64) - .unwrap_or(0xDEAD_BEEF_CAFE_BABE); + .map_or(0xDEAD_BEEF_CAFE_BABE, |d| d.as_nanos() as u64); Arc::new(Mutex::new(if seed == 0 { 0xDEAD_BEEF_CAFE_BABE } else { diff --git a/crates/core/tests/comparison.rs b/crates/core/tests/comparison.rs index 97b11da..df7b76d 100644 --- a/crates/core/tests/comparison.rs +++ b/crates/core/tests/comparison.rs @@ -26,8 +26,7 @@ fn probe_gforth(candidate: &str) -> bool { .arg("-e") .arg("bye") .output() - .map(|o| o.status.success()) - .unwrap_or(false) + .is_ok_and(|o| o.status.success()) } fn find_gforth() -> Option<&'static str> {