From 6b3ae06031d7f407605121c9d4570cd7431daffa Mon Sep 17 00:00:00 2001 From: Serkyo Date: Mon, 13 Jul 2026 00:39:49 +0200 Subject: [PATCH] chore(renderer): add reasons to expect attributes --- crates/renderer/src/device.rs | 5 ++++- crates/renderer/src/lib.rs | 5 ++++- crates/renderer/src/mesh.rs | 5 ++++- crates/renderer/src/pipeline.rs | 5 ++++- crates/renderer/src/renderer.rs | 24 ++++++++++++++++++------ 5 files changed, 34 insertions(+), 10 deletions(-) diff --git a/crates/renderer/src/device.rs b/crates/renderer/src/device.rs index 84fb199..a4d43d8 100644 --- a/crates/renderer/src/device.rs +++ b/crates/renderer/src/device.rs @@ -67,7 +67,10 @@ pub fn find_graphics_queue_family( let props = unsafe { instance.get_physical_device_queue_family_properties(physical_device) }; for (index, prop) in props.iter().enumerate() { - #[expect(clippy::expect_used)] + #[expect( + clippy::expect_used, + reason = "a physical device's queue-family count never approaches u32::MAX" + )] let index = u32::try_from(index).expect("Queue family index exceeds u32 range"); let graphics = prop.queue_flags.contains(vk::QueueFlags::GRAPHICS); let present = unsafe { diff --git a/crates/renderer/src/lib.rs b/crates/renderer/src/lib.rs index 7f21a07..e9d5442 100644 --- a/crates/renderer/src/lib.rs +++ b/crates/renderer/src/lib.rs @@ -96,7 +96,10 @@ impl Renderer { let command_pool = unsafe { device.create_command_pool(&pool_create_info, None)? }; // 9. Command Buffers - #[expect(clippy::expect_used)] + #[expect( + clippy::expect_used, + reason = "MAX_FRAMES_IN_FLIGHT is a small compile-time constant" + )] let alloc_info = vk::CommandBufferAllocateInfo::default() .command_pool(command_pool) .level(vk::CommandBufferLevel::PRIMARY) diff --git a/crates/renderer/src/mesh.rs b/crates/renderer/src/mesh.rs index 048f7b8..6117cea 100644 --- a/crates/renderer/src/mesh.rs +++ b/crates/renderer/src/mesh.rs @@ -24,7 +24,10 @@ impl Vertex { /// /// # Panics /// Panics if the size of the vertex structure exceeds the maximum value of a 32-bit unsigned integer. - #[expect(clippy::expect_used)] + #[expect( + clippy::expect_used, + reason = "the vertex struct size is far below u32::MAX" + )] pub fn get_binding_description() -> ash::vk::VertexInputBindingDescription { ash::vk::VertexInputBindingDescription::default() .binding(0) diff --git a/crates/renderer/src/pipeline.rs b/crates/renderer/src/pipeline.rs index dbfa789..4668ab5 100644 --- a/crates/renderer/src/pipeline.rs +++ b/crates/renderer/src/pipeline.rs @@ -29,7 +29,10 @@ pub fn create_shader_module( /// This layout defines any push constants or descriptor sets (textures/UBOs) accessed by the shaders during execution. pub fn create_pipeline_layout(device: &Device) -> Result { // A single push constant range is defined for the MVP matrix, allowing it to be updated for every draw call with high efficiency. - #[expect(clippy::expect_used)] + #[expect( + clippy::expect_used, + reason = "size_of::() is 64 bytes, well within u32 range" + )] let push_constant_range = vk::PushConstantRange::default() .stage_flags(vk::ShaderStageFlags::VERTEX) .offset(0) diff --git a/crates/renderer/src/renderer.rs b/crates/renderer/src/renderer.rs index b357a92..b8bf83e 100644 --- a/crates/renderer/src/renderer.rs +++ b/crates/renderer/src/renderer.rs @@ -17,14 +17,17 @@ pub struct Renderer { /// The debug messenger for validation layer output. pub(crate) debug_messenger: vk::DebugUtilsMessengerEXT, /// Handle to the selected physical device (GPU). - #[expect(dead_code)] + #[expect(dead_code, reason = "retained for later device-capability queries")] pub(crate) physical_device: vk::PhysicalDevice, /// The logical Vulkan device. pub(crate) device: Device, /// The queue used for graphics operations. pub(crate) graphics_queue: vk::Queue, /// Index of the graphics queue family. - #[expect(dead_code)] + #[expect( + dead_code, + reason = "retained for later queue-family-dependent operations" + )] pub(crate) graphics_queue_index: u32, /// Surface extension loader. pub(crate) surface_loader: khr::surface::Instance, @@ -37,7 +40,7 @@ pub struct Renderer { /// Images acquired from the swapchain. pub(crate) swapchain_images: Vec, /// The pixel format of the swapchain images. - #[expect(dead_code)] + #[expect(dead_code, reason = "retained for later swapchain recreation")] pub(crate) swapchain_format: vk::Format, /// The dimensions of the swapchain images. pub(crate) swapchain_extent: vk::Extent2D, @@ -262,7 +265,10 @@ impl Renderer { self.graphics_pipeline, ); - #[expect(clippy::cast_precision_loss)] + #[expect( + clippy::cast_precision_loss, + reason = "swapchain extents are within f32's exact-integer range" + )] let viewport = vk::Viewport { x: 0.0, y: 0.0, @@ -287,7 +293,10 @@ impl Renderer { let aspect = f64::from(self.swapchain_extent.width) / f64::from(self.swapchain_extent.height); - #[expect(clippy::cast_possible_truncation)] + #[expect( + clippy::cast_possible_truncation, + reason = "the aspect ratio is a small value; f32 precision is sufficient" + )] let projection = glam::camera::rh::proj::vulkan::perspective( 45.0_f32.to_radians(), aspect as f32, @@ -351,7 +360,10 @@ impl Renderer { /// /// # Errors /// Returns a `RendererError` if new Vulkan buffers cannot be allocated or created. - #[expect(clippy::cast_possible_truncation)] + #[expect( + clippy::cast_possible_truncation, + reason = "a chunk mesh's index count never approaches u32::MAX" + )] pub fn update_mesh( &mut self, vertices: &[Vertex],