From 61cf41f088e4b569b495c5322fececc33ed46582 Mon Sep 17 00:00:00 2001 From: bQUARKz Date: Thu, 8 Oct 2026 08:41:20 +0100 Subject: [PATCH] fix: resolve Clippy warnings across all workspace targets --- .../prometeu-bytecode/tests/registry_v1.rs | 3 +- .../prometeu-drivers/src/frame_composer.rs | 4 +-- .../console/prometeu-drivers/src/hardware.rs | 4 +-- .../src/services/vm_runtime/tests.rs | 4 +-- .../src/services/vm_runtime/tick.rs | 12 ++++---- crates/console/prometeu-vm/src/builtins.rs | 28 ++++++++--------- crates/console/prometeu-vm/src/heap.rs | 12 ++++---- .../src/registry_verifier/tests.rs | 16 ++++------ .../src/registry_verifier/types.rs | 30 +++++++++---------- .../src/registry_verifier/types/tests.rs | 3 +- .../prometeu-vm/src/virtual_machine.rs | 18 ++++++----- .../src/virtual_machine/typed_tests.rs | 2 +- .../src/automation/wire.rs | 2 +- .../host/prometeu-host-headless/src/host.rs | 6 ++-- .../tests/deterministic_control.rs | 10 +++---- 15 files changed, 72 insertions(+), 82 deletions(-) diff --git a/crates/console/prometeu-bytecode/tests/registry_v1.rs b/crates/console/prometeu-bytecode/tests/registry_v1.rs index 0186d90..b0e8af1 100644 --- a/crates/console/prometeu-bytecode/tests/registry_v1.rs +++ b/crates/console/prometeu-bytecode/tests/registry_v1.rs @@ -164,8 +164,7 @@ fn owned_payload_refusal_rolls_back_all_ownership_and_preserves_prior_budget() { assert_eq!(b.used(LoadResource::RegistryBytes), 3); assert_eq!(b.used(LoadResource::Types), 0); assert_eq!(b.used(LoadResource::ConstantEntries), 0); - let mut limits = LoadLimits::default(); - limits.temporary_bytes = 1; + let limits = LoadLimits { temporary_bytes: 1, ..Default::default() }; let mut b = LoadBudget::new(limits); assert_eq!( OwnedPbx::parse(&bytes, &mut b).unwrap_err().resource, diff --git a/crates/console/prometeu-drivers/src/frame_composer.rs b/crates/console/prometeu-drivers/src/frame_composer.rs index 11abbc6..f8bcb7c 100644 --- a/crates/console/prometeu-drivers/src/frame_composer.rs +++ b/crates/console/prometeu-drivers/src/frame_composer.rs @@ -560,9 +560,7 @@ mod tests { let mut bank = GlyphBank::with_palette_count(tile_size, size, size, palette_id as usize + 1); bank.palette_mut(palette_id).unwrap()[1] = color; - for pixel in &mut bank.pixel_indices { - *pixel = 1; - } + bank.pixel_indices.fill(1); bank } diff --git a/crates/console/prometeu-drivers/src/hardware.rs b/crates/console/prometeu-drivers/src/hardware.rs index bb37559..539f92d 100644 --- a/crates/console/prometeu-drivers/src/hardware.rs +++ b/crates/console/prometeu-drivers/src/hardware.rs @@ -266,9 +266,7 @@ mod tests { fn make_glyph_bank() -> GlyphBank { let mut bank = GlyphBank::new(TileSize::Size8, 8, 8); bank.palette_mut(0).unwrap()[1] = Color::RED; - for pixel in &mut bank.pixel_indices { - *pixel = 1; - } + bank.pixel_indices.fill(1); bank } diff --git a/crates/console/prometeu-system/src/services/vm_runtime/tests.rs b/crates/console/prometeu-system/src/services/vm_runtime/tests.rs index e23abe6..7c854d6 100644 --- a/crates/console/prometeu-system/src/services/vm_runtime/tests.rs +++ b/crates/console/prometeu-system/src/services/vm_runtime/tests.rs @@ -151,9 +151,7 @@ fn runtime_test_glyph_bank(tile_size: TileSize, palette_id: u8, color: Color) -> let size = tile_size as usize; let mut bank = GlyphBank::with_palette_count(tile_size, size, size, palette_id as usize + 1); bank.palette_mut(palette_id).unwrap()[1] = color; - for pixel in &mut bank.pixel_indices { - *pixel = 1; - } + bank.pixel_indices.fill(1); bank } diff --git a/crates/console/prometeu-system/src/services/vm_runtime/tick.rs b/crates/console/prometeu-system/src/services/vm_runtime/tick.rs index e4e5b29..d08fa55 100644 --- a/crates/console/prometeu-system/src/services/vm_runtime/tick.rs +++ b/crates/console/prometeu-system/src/services/vm_runtime/tick.rs @@ -76,12 +76,12 @@ impl VirtualMachineRuntime { vm: &mut VirtualMachine, platform: &mut dyn RuntimePlatform, ) -> Option { - if vm.call_stack_is_empty() { - if let Err(error) = vm.prepare_boot_call() { - let report = CrashReport::VmInit { error }; - self.last_crash_report = Some(report.clone()); - return Some(report); - } + if vm.call_stack_is_empty() + && let Err(error) = vm.prepare_boot_call() + { + let report = CrashReport::VmInit { error }; + self.last_crash_report = Some(report.clone()); + return Some(report); } let step_result = { let mut ctx = HostContext::new_platform(Some(platform)); diff --git a/crates/console/prometeu-vm/src/builtins.rs b/crates/console/prometeu-vm/src/builtins.rs index 2fd457c..aaedadb 100644 --- a/crates/console/prometeu-vm/src/builtins.rs +++ b/crates/console/prometeu-vm/src/builtins.rs @@ -1036,6 +1036,20 @@ fn color_transparent( color_const(Color::TRANSPARENT) } +/// Loader-side lookup charges each catalogue record before examining it. +pub(crate) fn metered_lookup_intrinsic( + id: u32, + budget: &mut prometeu_bytecode::load_limits::LoadBudget, +) -> Result, prometeu_bytecode::load_limits::LoadFailure> { + for meta in INTRINSICS.iter().chain(crate::input_intrinsics::INPUT_INTRINSICS.iter()) { + budget.work(1)?; + if meta.id == id { + return Ok(Some(meta)); + } + } + Ok(None) +} + #[cfg(test)] mod tests { use super::*; @@ -1196,17 +1210,3 @@ mod tests { assert_eq!(pixel.field("color").map(|field| field.start_slot), Some(2)); } } - -/// Loader-side lookup charges each catalogue record before examining it. -pub(crate) fn metered_lookup_intrinsic( - id: u32, - budget: &mut prometeu_bytecode::load_limits::LoadBudget, -) -> Result, prometeu_bytecode::load_limits::LoadFailure> { - for meta in INTRINSICS.iter().chain(crate::input_intrinsics::INPUT_INTRINSICS.iter()) { - budget.work(1)?; - if meta.id == id { - return Ok(Some(meta)); - } - } - Ok(None) -} diff --git a/crates/console/prometeu-vm/src/heap.rs b/crates/console/prometeu-vm/src/heap.rs index b55477d..8e295cb 100644 --- a/crates/console/prometeu-vm/src/heap.rs +++ b/crates/console/prometeu-vm/src/heap.rs @@ -380,12 +380,12 @@ impl Heap { } fn enqueue_mark(&mut self, r: HeapRef, stack: &mut BudgetVec) { - if let Some(header) = self.header_mut(r) { - if !header.is_marked() { - // Each live object enters at most once; reserve(len()) bounds the entire traversal. - header.set_marked(true); - stack.push(r).expect("mark worklist reserved for every live object"); - } + if let Some(header) = self.header_mut(r) + && !header.is_marked() + { + // Each live object enters at most once; reserve(len()) bounds the entire traversal. + header.set_marked(true); + stack.push(r).expect("mark worklist reserved for every live object"); } } diff --git a/crates/console/prometeu-vm/src/registry_verifier/tests.rs b/crates/console/prometeu-vm/src/registry_verifier/tests.rs index e5e3204..6ced2bb 100644 --- a/crates/console/prometeu-vm/src/registry_verifier/tests.rs +++ b/crates/console/prometeu-vm/src/registry_verifier/tests.rs @@ -193,8 +193,8 @@ fn stack_analysis_refunds_all_state_buffers_and_preserves_prior_ownership() { b.charge(Q::RegistryBytes, 11).unwrap(); validate_registry_stacks(&code, &r, 1, &mut b).unwrap(); assert_eq!((b.used(Q::TemporaryBytes), b.used(Q::RegistryBytes)), (7, 11)); - let mut limits = LoadLimits::default(); - limits.temporary_bytes = 32; // Decode maps fit; CFG/state/work buffers cannot all fit. + // Decode maps fit; CFG/state/work buffers cannot all fit. + let limits = LoadLimits { temporary_bytes: 32, ..Default::default() }; let mut b = LoadBudget::new(limits); b.charge(Q::TemporaryBytes, 7).unwrap(); let e = validate_registry_stacks(&code, &r, 1, &mut b).unwrap_err(); @@ -214,8 +214,7 @@ fn stack_analysis_straight_line_storage_is_bounded_by_blocks_not_instruction_fra &code, vec![FunctionDecl { local_slots: 300, max_stack_slots: 0, ..function(&code) }], ); - let mut limits = LoadLimits::default(); - limits.temporary_bytes = 41_000; + let limits = LoadLimits { temporary_bytes: 41_000, ..Default::default() }; let mut b = LoadBudget::new(limits); validate_registry_stacks(&code, &r, 1, &mut b).unwrap(); assert_eq!(b.used(Q::TemporaryBytes), 0); @@ -336,8 +335,7 @@ fn stack_analysis_charges_work_for_loop_reprocessing_and_refunds_on_exhaustion() ); let mut b = LoadBudget::new(Default::default()); validate_registry_stacks(&code, &r, 1, &mut b).unwrap(); - let mut limits = LoadLimits::default(); - limits.work = b.used(Q::Work) - 1; + let limits = LoadLimits { work: b.used(Q::Work) - 1, ..Default::default() }; let mut limited = LoadBudget::new(limits); limited.charge(Q::TemporaryBytes, 7).unwrap(); let e = validate_registry_stacks(&code, &r, 1, &mut limited).unwrap_err(); @@ -433,8 +431,7 @@ fn local_bounds_use_derived_parameter_widths_and_u32_local_counts() { let e = check(&bad, &r).unwrap_err(); assert_eq!((e.reason, e.member), (R::LocalSlot, Some(slot))); } - let mut limits = LoadLimits::default(); - limits.frame_slots = 74; + let limits = LoadLimits { frame_slots: 74, ..Default::default() }; let mut budget = LoadBudget::new(limits); let e = validate_registry_instructions(&code, &r, 1, &mut budget).unwrap_err(); assert_eq!(e.reason, R::FrameSlots); // 2 parameters + 69 locals + 4 temporaries = 75. @@ -506,8 +503,7 @@ fn scratch_is_refunded_per_function_and_preserves_prior_load_ownership() { FunctionDecl { code_offset: 2, code_len: 2, ..function(&code) }, ], ); - let mut limits = LoadLimits::default(); - limits.temporary_bytes = 8; + let limits = LoadLimits { temporary_bytes: 8, ..Default::default() }; let mut budget = LoadBudget::new(limits); budget.charge(Q::TemporaryBytes, 5).unwrap(); budget.charge(Q::RegistryBytes, 10).unwrap(); diff --git a/crates/console/prometeu-vm/src/registry_verifier/types.rs b/crates/console/prometeu-vm/src/registry_verifier/types.rs index 650f9f9..cac99e3 100644 --- a/crates/console/prometeu-vm/src/registry_verifier/types.rs +++ b/crates/console/prometeu-vm/src/registry_verifier/types.rs @@ -227,12 +227,12 @@ fn invalidate( } budget.work(working.len() * 2)?; for fact in working { - if let Fact::Group { ty, part, origin: other } = *fact { - if origin == other { - let carrier = component(registry, ty, part, budget)?; - budget.work(1)?; - *fact = if carrier == ANY { Fact::Unknown } else { Fact::Carrier(carrier) }; - } + if let Fact::Group { ty, part, origin: other } = *fact + && origin == other + { + let carrier = component(registry, ty, part, budget)?; + budget.work(1)?; + *fact = if carrier == ANY { Fact::Unknown } else { Fact::Carrier(carrier) }; } } Ok(()) @@ -514,11 +514,11 @@ fn abi_mask(abi: AbiType) -> u8 { fn invalidate_dynamic(values: &mut [Fact], origin: u64, budget: &mut LoadBudget) -> Result<(), E> { budget.work(values.len() * 2)?; for value in values { - if let Fact::Dynamic { part, origin: other } = *value { - if origin == other { - budget.work(1)?; - *value = if part == 0 { Fact::Carrier(I64 | NULL) } else { Fact::Unknown }; - } + if let Fact::Dynamic { part, origin: other } = *value + && origin == other + { + budget.work(1)?; + *value = if part == 0 { Fact::Carrier(I64 | NULL) } else { Fact::Unknown }; } } Ok(()) @@ -586,10 +586,10 @@ fn check_group( let color = matches!(kind, TypeKind::Builtin(B::COLOR | B::PIXEL)); if color { budget.work(1)?; - if let Fact::Int64(value) = values[width - 1] { - if u32::try_from(value).is_err() { - return Err(mismatch(width - 1).reference(IdDomain::Type, ty.0)); - } + if let Fact::Int64(value) = values[width - 1] + && u32::try_from(value).is_err() + { + return Err(mismatch(width - 1).reference(IdDomain::Type, ty.0)); } } Ok(()) diff --git a/crates/console/prometeu-vm/src/registry_verifier/types/tests.rs b/crates/console/prometeu-vm/src/registry_verifier/types/tests.rs index 777d059..f96c7cf 100644 --- a/crates/console/prometeu-vm/src/registry_verifier/types/tests.rs +++ b/crates/console/prometeu-vm/src/registry_verifier/types/tests.rs @@ -295,8 +295,7 @@ fn type_analysis_is_metered_and_releases_scratch_on_success_and_failure() { let mut full = LoadBudget::new(Default::default()); validate_registry_types(&code, &r, &[], &mut full).unwrap(); assert_eq!(full.used(Q::TemporaryBytes), 0); - let mut limits = LoadLimits::default(); - limits.work = full.used(Q::Work) - 1; + let limits = LoadLimits { work: full.used(Q::Work) - 1, ..Default::default() }; let mut limited = LoadBudget::new(limits); limited.charge(Q::TemporaryBytes, 7).unwrap(); let e = validate_registry_types(&code, &r, &[], &mut limited).unwrap_err(); diff --git a/crates/console/prometeu-vm/src/virtual_machine.rs b/crates/console/prometeu-vm/src/virtual_machine.rs index c60dafa..0ab0321 100644 --- a/crates/console/prometeu-vm/src/virtual_machine.rs +++ b/crates/console/prometeu-vm/src/virtual_machine.rs @@ -153,15 +153,17 @@ impl VirtualMachine { let mut owners = [None, None]; for value in &values { if let Value::String(content) = value { - if let Some(image) = &self.validated_image { - if owners[0].is_none() && image.retains_string(content) { - owners[0] = Some(image.string_retention()); - } + if let Some(image) = &self.validated_image + && owners[0].is_none() + && image.retains_string(content) + { + owners[0] = Some(image.string_retention()); } - if let Some(strings) = &self.strings { - if owners[1].is_none() && strings.retains(content) { - owners[1] = Some(strings.retention()); - } + if let Some(strings) = &self.strings + && owners[1].is_none() + && strings.retains(content) + { + owners[1] = Some(strings.retention()); } } } diff --git a/crates/console/prometeu-vm/src/virtual_machine/typed_tests.rs b/crates/console/prometeu-vm/src/virtual_machine/typed_tests.rs index b0239e2..0322838 100644 --- a/crates/console/prometeu-vm/src/virtual_machine/typed_tests.rs +++ b/crates/console/prometeu-vm/src/virtual_machine/typed_tests.rs @@ -151,7 +151,7 @@ fn decoded_dynamic_scalar_string_reference_and_null_paths_have_exact_attempt_cos (13, Value::Null), ] { let mut pack = dynamic_vm(OpCode::DynPack, ty, 1, 2, RuntimeLimits::default()); - load_globals_and_step(&mut pack, &[value.clone()]).unwrap(); + load_globals_and_step(&mut pack, std::slice::from_ref(&value)).unwrap(); assert_eq!(pack.operand_stack.as_slice(), &[Value::Int64(ty.into()), value.clone()]); let pair = pack.operand_stack.as_slice(); let mut unpack = dynamic_vm(OpCode::DynUnpack, ty, 2, 1, RuntimeLimits::default()); diff --git a/crates/host/prometeu-host-headless/src/automation/wire.rs b/crates/host/prometeu-host-headless/src/automation/wire.rs index d6df215..14873f1 100644 --- a/crates/host/prometeu-host-headless/src/automation/wire.rs +++ b/crates/host/prometeu-host-headless/src/automation/wire.rs @@ -233,7 +233,7 @@ pub(super) fn host_error(error: HostError) -> WireError { let (code, details) = match &error { HostError::AlreadyBooted => ("already_booted", json!({})), HostError::BootFailed { reason, report } => { - ("boot_failed", json!({"reason":reason,"fault":report.as_ref().map(fault)})) + ("boot_failed", json!({"reason":reason,"fault":report.as_deref().map(fault)})) } HostError::InvalidState { operation, status } => { ("invalid_state", json!({"operation":operation,"status":status_name(*status)})) diff --git a/crates/host/prometeu-host-headless/src/host.rs b/crates/host/prometeu-host-headless/src/host.rs index 0d09e24..5141df7 100644 --- a/crates/host/prometeu-host-headless/src/host.rs +++ b/crates/host/prometeu-host-headless/src/host.rs @@ -65,7 +65,7 @@ pub struct AdvanceFramesOutcome { #[derive(Debug, Clone, PartialEq, Eq)] pub enum HostError { AlreadyBooted, - BootFailed { reason: String, report: Option }, + BootFailed { reason: String, report: Option> }, InvalidState { operation: &'static str, status: HostExecutionStatus }, FrameAdvanceWatchdogExpired { host_tick_limit: usize }, FrameNotPublished { previous: Option }, @@ -152,7 +152,7 @@ impl HeadlessHost { .as_ref() .map(CrashReport::summary) .unwrap_or_else(|| "cartridge crashed during boot".to_string()); - return Err(HostError::BootFailed { reason, report }); + return Err(HostError::BootFailed { reason, report: report.map(Box::new) }); } if matches!(self.firmware.state, FirmwareState::HubHome(_)) { return Err(HostError::BootFailed { @@ -168,7 +168,7 @@ impl HeadlessHost { } else { Err(HostError::BootFailed { reason: "boot did not reach the game".to_string(), - report: self.get_fault(), + report: self.get_fault().map(Box::new), }) } } diff --git a/crates/host/prometeu-host-headless/tests/deterministic_control.rs b/crates/host/prometeu-host-headless/tests/deterministic_control.rs index 320d946..3144563 100644 --- a/crates/host/prometeu-host-headless/tests/deterministic_control.rs +++ b/crates/host/prometeu-host-headless/tests/deterministic_control.rs @@ -330,12 +330,12 @@ fn vm_init_failure_is_returned_as_structured_boot_failure() { let mut host = HeadlessHost::new(); let error = host.boot(&dir).expect_err("invalid PBX must fail boot"); - assert!(matches!( - error, - HostError::BootFailed { report: Some(CrashReport::VmInit { .. }), .. } - )); + let HostError::BootFailed { report: Some(report), .. } = error else { + panic!("expected structured boot failure: {error:?}"); + }; + assert!(matches!(report.as_ref(), CrashReport::VmInit { .. })); assert_eq!(host.get_state().status, HostExecutionStatus::Faulted); - assert!(matches!(host.get_fault(), Some(CrashReport::VmInit { .. }))); + assert_eq!(host.get_fault().as_ref(), Some(report.as_ref())); } #[test]