fix: Rust 1.95 clippy — match guards + map_or
CI / check (push) Has been cancelled

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.
This commit is contained in:
2026-04-21 17:00:21 +02:00
parent e95c8ba791
commit 28f7d98fcd
5 changed files with 40 additions and 48 deletions
+13 -15
View File
@@ -2012,15 +2012,13 @@ fn emit_promoted_op(f: &mut Function, op: &IrOp, sim: &mut StackSim) {
// Outside loops, RFetch shouldn't appear in promoted code // Outside loops, RFetch shouldn't appear in promoted code
} }
IrOp::LoopJ => { IrOp::LoopJ if sim.loop_index_stack.len() >= 2 => {
if sim.loop_index_stack.len() >= 2 {
let (outer_index, _) = sim.loop_index_stack[sim.loop_index_stack.len() - 2]; let (outer_index, _) = sim.loop_index_stack[sim.loop_index_stack.len() - 2];
let result = sim.alloc(); let result = sim.alloc();
f.instruction(&Instruction::LocalGet(outer_index)); f.instruction(&Instruction::LocalGet(outer_index));
f.instruction(&Instruction::LocalSet(result)); f.instruction(&Instruction::LocalSet(result));
sim.push(result); sim.push(result);
} }
}
IrOp::Exit => { IrOp::Exit => {
// Write remaining promoted locals back to memory stack, then return // Write remaining promoted locals back to memory stack, then return
@@ -2147,16 +2145,16 @@ fn needs_f64_locals(ops: &[IrOp]) -> bool {
return true; return true;
} }
} }
IrOp::DoLoop { body, .. } | IrOp::BeginUntil { body } | IrOp::BeginAgain { body } => { IrOp::DoLoop { body, .. } | IrOp::BeginUntil { body } | IrOp::BeginAgain { body }
if needs_f64_locals(body) { if needs_f64_locals(body) =>
{
return true; return true;
} }
} IrOp::BeginWhileRepeat { test, body }
IrOp::BeginWhileRepeat { test, body } => { if needs_f64_locals(test) || needs_f64_locals(body) =>
if needs_f64_locals(test) || needs_f64_locals(body) { {
return true; return true;
} }
}
IrOp::BeginDoubleWhileRepeat { IrOp::BeginDoubleWhileRepeat {
outer_test, outer_test,
inner_test, inner_test,
@@ -2209,16 +2207,16 @@ fn body_needs_return_stack(ops: &[IrOp]) -> bool {
return true; return true;
} }
} }
IrOp::DoLoop { body, .. } | IrOp::BeginUntil { body } | IrOp::BeginAgain { body } => { IrOp::DoLoop { body, .. } | IrOp::BeginUntil { body } | IrOp::BeginAgain { body }
if body_needs_return_stack(body) { if body_needs_return_stack(body) =>
{
return true; return true;
} }
} IrOp::BeginWhileRepeat { test, body }
IrOp::BeginWhileRepeat { test, body } => { if body_needs_return_stack(test) || body_needs_return_stack(body) =>
if body_needs_return_stack(test) || body_needs_return_stack(body) { {
return true; return true;
} }
}
IrOp::BeginDoubleWhileRepeat { IrOp::BeginDoubleWhileRepeat {
outer_test, outer_test,
inner_test, inner_test,
+1 -3
View File
@@ -131,11 +131,9 @@ pub fn export_module(
fn collect_external_calls(ops: &[IrOp], ir_ids: &HashSet<WordId>, host_ids: &mut HashSet<WordId>) { fn collect_external_calls(ops: &[IrOp], ir_ids: &HashSet<WordId>, host_ids: &mut HashSet<WordId>) {
for op in ops { for op in ops {
match op { match op {
IrOp::Call(id) | IrOp::TailCall(id) => { IrOp::Call(id) | IrOp::TailCall(id) if !ir_ids.contains(id) => {
if !ir_ids.contains(id) {
host_ids.insert(*id); host_ids.insert(*id);
} }
}
IrOp::If { IrOp::If {
then_body, then_body,
else_body, else_body,
+10 -12
View File
@@ -591,16 +591,16 @@ fn contains_call_to(ops: &[IrOp], target: WordId) -> bool {
return true; return true;
} }
} }
IrOp::DoLoop { body, .. } | IrOp::BeginUntil { body } | IrOp::BeginAgain { body } => { IrOp::DoLoop { body, .. } | IrOp::BeginUntil { body } | IrOp::BeginAgain { body }
if contains_call_to(body, target) { if contains_call_to(body, target) =>
{
return true; return true;
} }
} IrOp::BeginWhileRepeat { test, body }
IrOp::BeginWhileRepeat { test, body } => { if contains_call_to(test, target) || contains_call_to(body, target) =>
if contains_call_to(test, target) || contains_call_to(body, target) { {
return true; return true;
} }
}
IrOp::BeginDoubleWhileRepeat { IrOp::BeginDoubleWhileRepeat {
outer_test, outer_test,
inner_test, inner_test,
@@ -651,16 +651,14 @@ fn contains_exit(ops: &[IrOp]) -> bool {
return true; return true;
} }
} }
IrOp::DoLoop { body, .. } | IrOp::BeginUntil { body } | IrOp::BeginAgain { body } => { IrOp::DoLoop { body, .. } | IrOp::BeginUntil { body } | IrOp::BeginAgain { body }
if contains_exit(body) { if contains_exit(body) =>
{
return true; return true;
} }
} IrOp::BeginWhileRepeat { test, body } if contains_exit(test) || contains_exit(body) => {
IrOp::BeginWhileRepeat { test, body } => {
if contains_exit(test) || contains_exit(body) {
return true; return true;
} }
}
_ => {} _ => {}
} }
} }
+1 -2
View File
@@ -397,8 +397,7 @@ impl<R: Runtime> ForthVM<R> {
use std::time::{SystemTime, UNIX_EPOCH}; use std::time::{SystemTime, UNIX_EPOCH};
let seed = SystemTime::now() let seed = SystemTime::now()
.duration_since(UNIX_EPOCH) .duration_since(UNIX_EPOCH)
.map(|d| d.as_nanos() as u64) .map_or(0xDEAD_BEEF_CAFE_BABE, |d| d.as_nanos() as u64);
.unwrap_or(0xDEAD_BEEF_CAFE_BABE);
Arc::new(Mutex::new(if seed == 0 { Arc::new(Mutex::new(if seed == 0 {
0xDEAD_BEEF_CAFE_BABE 0xDEAD_BEEF_CAFE_BABE
} else { } else {
+1 -2
View File
@@ -26,8 +26,7 @@ fn probe_gforth(candidate: &str) -> bool {
.arg("-e") .arg("-e")
.arg("bye") .arg("bye")
.output() .output()
.map(|o| o.status.success()) .is_ok_and(|o| o.status.success())
.unwrap_or(false)
} }
fn find_gforth() -> Option<&'static str> { fn find_gforth() -> Option<&'static str> {