From e18e0243ef6b9ddc280ebfdd55b79837b8d567a0 Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Sat, 19 Feb 2022 01:01:46 +0100 Subject: [PATCH] ash: Remove unnecessary trivial_casts and trivial_numeric_casts (#564) While making the code only marginally harder to read such casts can also introduce subtle bugs when used incorrectly, and are best omitted whenever unnecessary: Rust already coerces borrows into raw pointers when the types on both ends are clear, and even then there remain many casts that are identical to the source type. In addition these errors show up when using a local crate reference to `ash` in a workspace that uses "the `.cargo/config.toml` setup" from [EmbarkStudios/rust-ecosystem#68] to configure linter warnings project-wide instead of for all crates in that workspace individually. In our case aforementioned linter warnings are enabled on top of Embark's configuration, leading to a lot of these warnings in our build process. [EmbarkStudios/rust-ecosystem#68]: https://github.com/EmbarkStudios/rust-ecosystem/pull/68 --- ash-window/src/lib.rs | 6 +- ash/src/extensions/experimental/amd.rs | 13 +- .../extensions/khr/acceleration_structure.rs | 26 +- .../extensions/khr/ray_tracing_pipeline.rs | 8 +- ash/src/lib.rs | 11 +- ash/src/vk.rs | 5 +- ash/src/vk/definitions.rs | 382 +++++++++--------- ash/src/vk/macros.rs | 4 +- generator/src/lib.rs | 44 +- 9 files changed, 258 insertions(+), 241 deletions(-) diff --git a/ash-window/src/lib.rs b/ash-window/src/lib.rs index 1c74435..da0f27e 100644 --- a/ash-window/src/lib.rs +++ b/ash-window/src/lib.rs @@ -1,3 +1,5 @@ +#![warn(trivial_casts, trivial_numeric_casts)] + use ash::{extensions::khr, prelude::*, vk, Entry, Instance}; use raw_window_handle::{HasRawWindowHandle, RawWindowHandle}; use std::ffi::CStr; @@ -69,7 +71,7 @@ pub unsafe fn create_surface( ))] RawWindowHandle::Xcb(handle) => { let surface_desc = vk::XcbSurfaceCreateInfoKHR::builder() - .connection(handle.connection as *mut _) + .connection(handle.connection) .window(handle.window); let surface_fn = khr::XcbSurface::new(entry, instance); surface_fn.create_xcb_surface(&surface_desc, allocation_callbacks) @@ -78,7 +80,7 @@ pub unsafe fn create_surface( #[cfg(any(target_os = "android"))] RawWindowHandle::Android(handle) => { let surface_desc = - vk::AndroidSurfaceCreateInfoKHR::builder().window(handle.a_native_window as _); + vk::AndroidSurfaceCreateInfoKHR::builder().window(handle.a_native_window); let surface_fn = khr::AndroidSurface::new(entry, instance); surface_fn.create_android_surface(&surface_desc, allocation_callbacks) } diff --git a/ash/src/extensions/experimental/amd.rs b/ash/src/extensions/experimental/amd.rs index 818e984..35b4289 100644 --- a/ash/src/extensions/experimental/amd.rs +++ b/ash/src/extensions/experimental/amd.rs @@ -240,11 +240,16 @@ impl<'a> ::std::ops::Deref for PhysicalDeviceGpaPropertiesAmdBuilder<'a> { } } impl<'a> PhysicalDeviceGpaPropertiesAmdBuilder<'a> { - pub fn next(mut self, next: &'a mut T) -> PhysicalDeviceGpaPropertiesAmdBuilder<'a> + pub fn push_next(mut self, next: &'a mut T) -> PhysicalDeviceGpaPropertiesAmdBuilder<'a> where T: ExtendsPhysicalDeviceGpaPropertiesAmd, { - self.inner.p_next = next as *mut T as *mut c_void; + unsafe { + let next_ptr = <*const T>::cast(next); + let last_next = ptr_chain_iter(next).last().unwrap(); + (*last_next).p_next = self.inner.p_next as _; + self.inner.p_next = next_ptr; + } self } pub fn build(self) -> PhysicalDeviceGpaPropertiesAmd { @@ -694,10 +699,10 @@ impl<'a> PhysicalDeviceWaveLimitPropertiesAmdBuilder<'a> { T: ExtendsPhysicalDeviceWaveLimitPropertiesAmd, { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } diff --git a/ash/src/extensions/khr/acceleration_structure.rs b/ash/src/extensions/khr/acceleration_structure.rs index 2f24d06..419ad49 100644 --- a/ash/src/extensions/khr/acceleration_structure.rs +++ b/ash/src/extensions/khr/acceleration_structure.rs @@ -156,7 +156,7 @@ impl AccelerationStructure { info: &vk::CopyAccelerationStructureInfoKHR, ) -> VkResult<()> { self.fp - .copy_acceleration_structure_khr(self.handle, deferred_operation, info as *const _) + .copy_acceleration_structure_khr(self.handle, deferred_operation, info) .result() } @@ -167,11 +167,7 @@ impl AccelerationStructure { info: &vk::CopyAccelerationStructureToMemoryInfoKHR, ) -> VkResult<()> { self.fp - .copy_acceleration_structure_to_memory_khr( - self.handle, - deferred_operation, - info as *const _, - ) + .copy_acceleration_structure_to_memory_khr(self.handle, deferred_operation, info) .result() } @@ -182,11 +178,7 @@ impl AccelerationStructure { info: &vk::CopyMemoryToAccelerationStructureInfoKHR, ) -> VkResult<()> { self.fp - .copy_memory_to_acceleration_structure_khr( - self.handle, - deferred_operation, - info as *const _, - ) + .copy_memory_to_acceleration_structure_khr(self.handle, deferred_operation, info) .result() } @@ -228,7 +220,7 @@ impl AccelerationStructure { info: &vk::CopyAccelerationStructureToMemoryInfoKHR, ) { self.fp - .cmd_copy_acceleration_structure_to_memory_khr(command_buffer, info as *const _); + .cmd_copy_acceleration_structure_to_memory_khr(command_buffer, info); } /// @@ -238,7 +230,7 @@ impl AccelerationStructure { info: &vk::CopyMemoryToAccelerationStructureInfoKHR, ) { self.fp - .cmd_copy_memory_to_acceleration_structure_khr(command_buffer, info as *const _); + .cmd_copy_memory_to_acceleration_structure_khr(command_buffer, info); } /// @@ -247,7 +239,7 @@ impl AccelerationStructure { info: &vk::AccelerationStructureDeviceAddressInfoKHR, ) -> vk::DeviceAddress { self.fp - .get_acceleration_structure_device_address_khr(self.handle, info as *const _) + .get_acceleration_structure_device_address_khr(self.handle, info) } /// @@ -279,7 +271,7 @@ impl AccelerationStructure { self.fp.get_device_acceleration_structure_compatibility_khr( self.handle, version, - &mut compatibility as *mut _, + &mut compatibility, ); compatibility @@ -299,9 +291,9 @@ impl AccelerationStructure { self.fp.get_acceleration_structure_build_sizes_khr( self.handle, build_type, - build_info as *const _, + build_info, max_primitive_counts.as_ptr(), - &mut size_info as *mut _, + &mut size_info, ); size_info diff --git a/ash/src/extensions/khr/ray_tracing_pipeline.rs b/ash/src/extensions/khr/ray_tracing_pipeline.rs index 1eaafd2..6ff5405 100644 --- a/ash/src/extensions/khr/ray_tracing_pipeline.rs +++ b/ash/src/extensions/khr/ray_tracing_pipeline.rs @@ -46,10 +46,10 @@ impl RayTracingPipeline { ) { self.fp.cmd_trace_rays_khr( command_buffer, - raygen_shader_binding_tables as *const _, - miss_shader_binding_tables as *const _, - hit_shader_binding_tables as *const _, - callable_shader_binding_tables as *const _, + raygen_shader_binding_tables, + miss_shader_binding_tables, + hit_shader_binding_tables, + callable_shader_binding_tables, width, height, depth, diff --git a/ash/src/lib.rs b/ash/src/lib.rs index 8294d31..50c9d8f 100644 --- a/ash/src/lib.rs +++ b/ash/src/lib.rs @@ -1,4 +1,5 @@ #![deny(clippy::use_self)] +#![warn(trivial_casts, trivial_numeric_casts)] #![allow( clippy::too_many_arguments, clippy::missing_safety_doc, @@ -59,8 +60,7 @@ pub trait RawPtr { impl<'r, T> RawPtr for Option<&'r T> { fn as_raw_ptr(&self) -> *const T { match *self { - Some(inner) => inner as *const T, - + Some(inner) => inner, _ => ::std::ptr::null(), } } @@ -74,16 +74,15 @@ mod tests { let mut variable_pointers = vk::PhysicalDeviceVariablePointerFeatures::builder(); let mut corner = vk::PhysicalDeviceCornerSampledImageFeaturesNV::builder(); let chain = vec![ - &variable_pointers as *const _ as usize, - &corner as *const _ as usize, + <*mut _>::cast(&mut variable_pointers), + <*mut _>::cast(&mut corner), ]; let mut device_create_info = vk::DeviceCreateInfo::builder() .push_next(&mut corner) .push_next(&mut variable_pointers); - let chain2: Vec = unsafe { + let chain2: Vec<*mut vk::BaseOutStructure> = unsafe { vk::ptr_chain_iter(&mut device_create_info) .skip(1) - .map(|ptr| ptr as usize) .collect() }; assert_eq!(chain, chain2); diff --git a/ash/src/vk.rs b/ash/src/vk.rs index 32aedb2..611c5f3 100644 --- a/ash/src/vk.rs +++ b/ash/src/vk.rs @@ -29,18 +29,19 @@ pub use prelude::*; /// Native bindings from Vulkan headers, generated by bindgen #[allow(nonstandard_style)] #[allow(deref_nullptr)] +#[allow(trivial_casts, trivial_numeric_casts)] pub mod native; mod platform_types; pub use platform_types::*; /// Iterates through the pointer chain. Includes the item that is passed into the function. /// Stops at the last [`BaseOutStructure`] that has a null [`BaseOutStructure::p_next`] field. pub(crate) unsafe fn ptr_chain_iter(ptr: &mut T) -> impl Iterator { - let ptr: *mut BaseOutStructure = ptr as *mut T as _; + let ptr = <*mut T>::cast::(ptr); (0..).scan(ptr, |p_ptr, _| { if p_ptr.is_null() { return None; } - let n_ptr = (**p_ptr).p_next as *mut BaseOutStructure; + let n_ptr = (**p_ptr).p_next; let old = *p_ptr; *p_ptr = n_ptr; Some(old) diff --git a/ash/src/vk/definitions.rs b/ash/src/vk/definitions.rs index 8170006..dfbca15 100644 --- a/ash/src/vk/definitions.rs +++ b/ash/src/vk/definitions.rs @@ -1005,7 +1005,7 @@ impl fmt::Debug for PhysicalDeviceProperties { .field("device_id", &self.device_id) .field("device_type", &self.device_type) .field("device_name", &unsafe { - ::std::ffi::CStr::from_ptr(self.device_name.as_ptr() as *const c_char) + ::std::ffi::CStr::from_ptr(self.device_name.as_ptr()) }) .field("pipeline_cache_uuid", &self.pipeline_cache_uuid) .field("limits", &self.limits) @@ -1108,7 +1108,7 @@ impl fmt::Debug for ExtensionProperties { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fmt.debug_struct("ExtensionProperties") .field("extension_name", &unsafe { - ::std::ffi::CStr::from_ptr(self.extension_name.as_ptr() as *const c_char) + ::std::ffi::CStr::from_ptr(self.extension_name.as_ptr()) }) .field("spec_version", &self.spec_version) .finish() @@ -1176,12 +1176,12 @@ impl fmt::Debug for LayerProperties { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fmt.debug_struct("LayerProperties") .field("layer_name", &unsafe { - ::std::ffi::CStr::from_ptr(self.layer_name.as_ptr() as *const c_char) + ::std::ffi::CStr::from_ptr(self.layer_name.as_ptr()) }) .field("spec_version", &self.spec_version) .field("implementation_version", &self.implementation_version) .field("description", &unsafe { - ::std::ffi::CStr::from_ptr(self.description.as_ptr() as *const c_char) + ::std::ffi::CStr::from_ptr(self.description.as_ptr()) }) .finish() } @@ -1499,10 +1499,10 @@ impl<'a> DeviceQueueCreateInfoBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -1601,10 +1601,10 @@ impl<'a> DeviceCreateInfoBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -1694,10 +1694,10 @@ impl<'a> InstanceCreateInfoBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -1898,10 +1898,10 @@ impl<'a> MemoryAllocateInfoBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -2561,10 +2561,10 @@ impl<'a> WriteDescriptorSetBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -2747,10 +2747,10 @@ impl<'a> BufferCreateInfoBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -3260,10 +3260,10 @@ impl<'a> ImageMemoryBarrierBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -3398,10 +3398,10 @@ impl<'a> ImageCreateInfoBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -3560,10 +3560,10 @@ impl<'a> ImageViewCreateInfoBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -4032,10 +4032,10 @@ impl<'a> BindSparseInfoBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -4362,7 +4362,7 @@ impl<'a> ShaderModuleCreateInfoBuilder<'a> { } pub fn code(mut self, code: &'a [u32]) -> Self { self.inner.code_size = code.len() * 4; - self.inner.p_code = code.as_ptr() as *const u32; + self.inner.p_code = code.as_ptr(); self } #[doc = r" Prepends the given extension struct between the root and the first pointer. This"] @@ -4372,10 +4372,10 @@ impl<'a> ShaderModuleCreateInfoBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -4525,10 +4525,10 @@ impl<'a> DescriptorSetLayoutCreateInfoBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -4657,10 +4657,10 @@ impl<'a> DescriptorPoolCreateInfoBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -4735,10 +4735,10 @@ impl<'a> DescriptorSetAllocateInfoBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -4853,7 +4853,7 @@ impl<'a> SpecializationInfoBuilder<'a> { self } pub fn data(mut self, data: &'a [u8]) -> Self { - self.inner.data_size = data.len() as _; + self.inner.data_size = data.len(); self.inner.p_data = data.as_ptr() as *const c_void; self } @@ -4943,10 +4943,10 @@ impl<'a> PipelineShaderStageCreateInfoBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -5036,10 +5036,10 @@ impl<'a> ComputePipelineCreateInfoBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -5243,10 +5243,10 @@ impl<'a> PipelineVertexInputStateCreateInfoBuilder<'a> { next: &'a mut T, ) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -5387,10 +5387,10 @@ impl<'a> PipelineTessellationStateCreateInfoBuilder<'a> { next: &'a mut T, ) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -5482,10 +5482,10 @@ impl<'a> PipelineViewportStateCreateInfoBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -5614,10 +5614,10 @@ impl<'a> PipelineRasterizationStateCreateInfoBuilder<'a> { next: &'a mut T, ) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -5709,7 +5709,7 @@ impl<'a> PipelineMultisampleStateCreateInfoBuilder<'a> { self.inner.p_sample_mask = if sample_mask.is_empty() { std::ptr::null() } else { - sample_mask.as_ptr() as *const SampleMask + sample_mask.as_ptr() }; self } @@ -5731,10 +5731,10 @@ impl<'a> PipelineMultisampleStateCreateInfoBuilder<'a> { next: &'a mut T, ) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -5908,10 +5908,10 @@ impl<'a> PipelineColorBlendStateCreateInfoBuilder<'a> { next: &'a mut T, ) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -6335,10 +6335,10 @@ impl<'a> GraphicsPipelineCreateInfoBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -6401,7 +6401,7 @@ impl<'a> PipelineCacheCreateInfoBuilder<'a> { self } pub fn initial_data(mut self, initial_data: &'a [u8]) -> Self { - self.inner.initial_data_size = initial_data.len() as _; + self.inner.initial_data_size = initial_data.len(); self.inner.p_initial_data = initial_data.as_ptr() as *const c_void; self } @@ -6756,10 +6756,10 @@ impl<'a> SamplerCreateInfoBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -6981,10 +6981,10 @@ impl<'a> CommandBufferInheritanceInfoBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -7056,10 +7056,10 @@ impl<'a> CommandBufferBeginInfoBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -7159,10 +7159,10 @@ impl<'a> RenderPassBeginInfoBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -7693,10 +7693,10 @@ impl<'a> RenderPassCreateInfoBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -7816,10 +7816,10 @@ impl<'a> FenceCreateInfoBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -9130,10 +9130,10 @@ impl<'a> SemaphoreCreateInfoBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -9217,10 +9217,10 @@ impl<'a> QueryPoolCreateInfoBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -9319,10 +9319,10 @@ impl<'a> FramebufferCreateInfoBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -9691,10 +9691,10 @@ impl<'a> SubmitInfoBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -11159,10 +11159,10 @@ impl<'a> SwapchainCreateInfoKHRBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -11254,10 +11254,10 @@ impl<'a> PresentInfoKHRBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -11675,7 +11675,7 @@ impl<'a> DebugMarkerObjectTagInfoEXTBuilder<'a> { self } pub fn tag(mut self, tag: &'a [u8]) -> Self { - self.inner.tag_size = tag.len() as _; + self.inner.tag_size = tag.len(); self.inner.p_tag = tag.as_ptr() as *const c_void; self } @@ -13585,10 +13585,10 @@ impl<'a> PhysicalDeviceFeatures2Builder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*mut T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -13654,10 +13654,10 @@ impl<'a> PhysicalDeviceProperties2Builder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*mut T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -13723,10 +13723,10 @@ impl<'a> FormatProperties2Builder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*mut T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -13795,10 +13795,10 @@ impl<'a> ImageFormatProperties2Builder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*mut T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -13888,10 +13888,10 @@ impl<'a> PhysicalDeviceImageFormatInfo2Builder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -13960,10 +13960,10 @@ impl<'a> QueueFamilyProperties2Builder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*mut T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -14029,10 +14029,10 @@ impl<'a> PhysicalDeviceMemoryProperties2Builder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*mut T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -14311,10 +14311,10 @@ impl fmt::Debug for PhysicalDeviceDriverProperties { .field("p_next", &self.p_next) .field("driver_id", &self.driver_id) .field("driver_name", &unsafe { - ::std::ffi::CStr::from_ptr(self.driver_name.as_ptr() as *const c_char) + ::std::ffi::CStr::from_ptr(self.driver_name.as_ptr()) }) .field("driver_info", &unsafe { - ::std::ffi::CStr::from_ptr(self.driver_info.as_ptr() as *const c_char) + ::std::ffi::CStr::from_ptr(self.driver_info.as_ptr()) }) .field("conformance_version", &self.conformance_version) .finish() @@ -15916,10 +15916,10 @@ impl<'a> PhysicalDeviceExternalSemaphoreInfoBuilder<'a> { next: &'a mut T, ) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -17867,10 +17867,10 @@ impl<'a> BindBufferMemoryInfoBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -18007,10 +18007,10 @@ impl<'a> BindImageMemoryInfoBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -20397,10 +20397,10 @@ impl<'a> PhysicalDeviceSurfaceInfo2KHRBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -20466,10 +20466,10 @@ impl<'a> SurfaceCapabilities2KHRBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*mut T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -21256,10 +21256,10 @@ impl<'a> ImageMemoryRequirementsInfo2Builder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -21439,10 +21439,10 @@ impl<'a> MemoryRequirements2Builder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*mut T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -21969,10 +21969,10 @@ impl<'a> SamplerYcbcrConversionCreateInfoBuilder<'a> { next: &'a mut T, ) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -24097,7 +24097,7 @@ impl<'a> ValidationCacheCreateInfoEXTBuilder<'a> { self } pub fn initial_data(mut self, initial_data: &'a [u8]) -> Self { - self.inner.initial_data_size = initial_data.len() as _; + self.inner.initial_data_size = initial_data.len(); self.inner.p_initial_data = initial_data.as_ptr() as *const c_void; self } @@ -24398,10 +24398,10 @@ impl<'a> DescriptorSetLayoutSupportBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*mut T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -25487,7 +25487,7 @@ impl<'a> DebugUtilsObjectTagInfoEXTBuilder<'a> { self } pub fn tag(mut self, tag: &'a [u8]) -> Self { - self.inner.tag_size = tag.len() as _; + self.inner.tag_size = tag.len(); self.inner.p_tag = tag.as_ptr() as *const c_void; self } @@ -27480,10 +27480,10 @@ impl<'a> AttachmentDescription2Builder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -27561,10 +27561,10 @@ impl<'a> AttachmentReference2Builder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -27685,10 +27685,10 @@ impl<'a> SubpassDescription2Builder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -27796,10 +27796,10 @@ impl<'a> SubpassDependency2Builder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -27901,10 +27901,10 @@ impl<'a> RenderPassCreateInfo2Builder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -28018,10 +28018,10 @@ impl<'a> SubpassEndInfoBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -28842,10 +28842,10 @@ impl<'a> AndroidHardwareBufferPropertiesANDROIDBuilder<'a> { next: &'a mut T, ) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*mut T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -32079,10 +32079,10 @@ impl<'a> RayTracingPipelineCreateInfoNVBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -32214,10 +32214,10 @@ impl<'a> RayTracingPipelineCreateInfoKHRBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -37008,13 +37008,13 @@ impl fmt::Debug for PerformanceCounterDescriptionKHR { .field("p_next", &self.p_next) .field("flags", &self.flags) .field("name", &unsafe { - ::std::ffi::CStr::from_ptr(self.name.as_ptr() as *const c_char) + ::std::ffi::CStr::from_ptr(self.name.as_ptr()) }) .field("category", &unsafe { - ::std::ffi::CStr::from_ptr(self.category.as_ptr() as *const c_char) + ::std::ffi::CStr::from_ptr(self.category.as_ptr()) }) .field("description", &unsafe { - ::std::ffi::CStr::from_ptr(self.description.as_ptr() as *const c_char) + ::std::ffi::CStr::from_ptr(self.description.as_ptr()) }) .finish() } @@ -38748,10 +38748,10 @@ impl fmt::Debug for PipelineExecutablePropertiesKHR { .field("p_next", &self.p_next) .field("stages", &self.stages) .field("name", &unsafe { - ::std::ffi::CStr::from_ptr(self.name.as_ptr() as *const c_char) + ::std::ffi::CStr::from_ptr(self.name.as_ptr()) }) .field("description", &unsafe { - ::std::ffi::CStr::from_ptr(self.description.as_ptr() as *const c_char) + ::std::ffi::CStr::from_ptr(self.description.as_ptr()) }) .field("subgroup_size", &self.subgroup_size) .finish() @@ -38909,10 +38909,10 @@ impl fmt::Debug for PipelineExecutableStatisticKHR { .field("s_type", &self.s_type) .field("p_next", &self.p_next) .field("name", &unsafe { - ::std::ffi::CStr::from_ptr(self.name.as_ptr() as *const c_char) + ::std::ffi::CStr::from_ptr(self.name.as_ptr()) }) .field("description", &unsafe { - ::std::ffi::CStr::from_ptr(self.description.as_ptr() as *const c_char) + ::std::ffi::CStr::from_ptr(self.description.as_ptr()) }) .field("format", &self.format) .field("value", &"union") @@ -38998,10 +38998,10 @@ impl fmt::Debug for PipelineExecutableInternalRepresentationKHR { .field("s_type", &self.s_type) .field("p_next", &self.p_next) .field("name", &unsafe { - ::std::ffi::CStr::from_ptr(self.name.as_ptr() as *const c_char) + ::std::ffi::CStr::from_ptr(self.name.as_ptr()) }) .field("description", &unsafe { - ::std::ffi::CStr::from_ptr(self.description.as_ptr() as *const c_char) + ::std::ffi::CStr::from_ptr(self.description.as_ptr()) }) .field("is_text", &self.is_text) .field("data_size", &self.data_size) @@ -39060,7 +39060,7 @@ impl<'a> PipelineExecutableInternalRepresentationKHRBuilder<'a> { self } pub fn data(mut self, data: &'a mut [u8]) -> Self { - self.inner.data_size = data.len() as _; + self.inner.data_size = data.len(); self.inner.p_data = data.as_mut_ptr() as *mut c_void; self } @@ -40836,10 +40836,10 @@ impl fmt::Debug for PhysicalDeviceVulkan12Properties { .field("p_next", &self.p_next) .field("driver_id", &self.driver_id) .field("driver_name", &unsafe { - ::std::ffi::CStr::from_ptr(self.driver_name.as_ptr() as *const c_char) + ::std::ffi::CStr::from_ptr(self.driver_name.as_ptr()) }) .field("driver_info", &unsafe { - ::std::ffi::CStr::from_ptr(self.driver_info.as_ptr() as *const c_char) + ::std::ffi::CStr::from_ptr(self.driver_info.as_ptr()) }) .field("conformance_version", &self.conformance_version) .field( @@ -41644,17 +41644,17 @@ impl fmt::Debug for PhysicalDeviceToolPropertiesEXT { .field("s_type", &self.s_type) .field("p_next", &self.p_next) .field("name", &unsafe { - ::std::ffi::CStr::from_ptr(self.name.as_ptr() as *const c_char) + ::std::ffi::CStr::from_ptr(self.name.as_ptr()) }) .field("version", &unsafe { - ::std::ffi::CStr::from_ptr(self.version.as_ptr() as *const c_char) + ::std::ffi::CStr::from_ptr(self.version.as_ptr()) }) .field("purposes", &self.purposes) .field("description", &unsafe { - ::std::ffi::CStr::from_ptr(self.description.as_ptr() as *const c_char) + ::std::ffi::CStr::from_ptr(self.description.as_ptr()) }) .field("layer", &unsafe { - ::std::ffi::CStr::from_ptr(self.layer.as_ptr() as *const c_char) + ::std::ffi::CStr::from_ptr(self.layer.as_ptr()) }) .finish() } @@ -42196,10 +42196,10 @@ impl<'a> AccelerationStructureGeometryTrianglesDataKHRBuilder<'a> { next: &'a mut T, ) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -42718,10 +42718,10 @@ impl<'a> AccelerationStructureCreateInfoKHRBuilder<'a> { next: &'a mut T, ) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -42923,7 +42923,7 @@ impl<'a> ::std::ops::DerefMut for AccelerationStructureVersionInfoKHRBuilder<'a> } impl<'a> AccelerationStructureVersionInfoKHRBuilder<'a> { pub fn version_data(mut self, version_data: &'a [u8; 2 * UUID_SIZE]) -> Self { - self.inner.p_version_data = version_data as *const [u8; 2 * UUID_SIZE]; + self.inner.p_version_data = version_data; self } #[doc = r" Calling build will **discard** all the lifetime information. Only call this if"] @@ -44727,10 +44727,10 @@ impl<'a> ImageBlit2KHRBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -44826,10 +44826,10 @@ impl<'a> BufferImageCopy2KHRBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -47177,10 +47177,10 @@ impl<'a> ImageMemoryBarrier2KHRBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -47603,10 +47603,10 @@ impl<'a> SubmitInfo2KHRBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -48186,10 +48186,10 @@ impl<'a> VideoProfileKHRBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*mut T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -48312,10 +48312,10 @@ impl<'a> VideoCapabilitiesKHRBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*mut T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -48591,10 +48591,10 @@ impl<'a> VideoReferenceSlotKHRBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -48711,10 +48711,10 @@ impl<'a> VideoDecodeInfoKHRBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -49144,10 +49144,10 @@ impl<'a> VideoDecodeH264PictureInfoEXTBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -49844,10 +49844,10 @@ impl<'a> VideoSessionCreateInfoKHRBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -49925,10 +49925,10 @@ impl<'a> VideoSessionParametersCreateInfoKHRBuilder<'a> { next: &'a mut T, ) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -49997,10 +49997,10 @@ impl<'a> VideoSessionParametersUpdateInfoKHRBuilder<'a> { next: &'a mut T, ) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -50207,10 +50207,10 @@ impl<'a> VideoCodingControlInfoKHRBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -50339,10 +50339,10 @@ impl<'a> VideoEncodeInfoKHRBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -50431,10 +50431,10 @@ impl<'a> VideoEncodeRateControlInfoKHRBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -50538,10 +50538,10 @@ impl<'a> VideoEncodeRateControlLayerInfoKHRBuilder<'a> { next: &'a mut T, ) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -53094,7 +53094,7 @@ impl<'a> ::std::ops::DerefMut for CuModuleCreateInfoNVXBuilder<'a> { } impl<'a> CuModuleCreateInfoNVXBuilder<'a> { pub fn data(mut self, data: &'a [u8]) -> Self { - self.inner.data_size = data.len() as _; + self.inner.data_size = data.len(); self.inner.p_data = data.as_ptr() as *const c_void; self } @@ -53263,12 +53263,12 @@ impl<'a> CuLaunchInfoNVXBuilder<'a> { self } pub fn params(mut self, params: &'a [*const c_void]) -> Self { - self.inner.param_count = params.len() as _; + self.inner.param_count = params.len(); self.inner.p_params = params.as_ptr(); self } pub fn extras(mut self, extras: &'a [*const c_void]) -> Self { - self.inner.extra_count = extras.len() as _; + self.inner.extra_count = extras.len(); self.inner.p_extras = extras.as_ptr(); self } @@ -55536,10 +55536,10 @@ impl<'a> RenderingInfoKHRBuilder<'a> { #[doc = r" chain will look like `A -> D -> B -> C`."] pub fn push_next(mut self, next: &'a mut T) -> Self { unsafe { - let next_ptr = next as *mut T as *mut BaseOutStructure; + let next_ptr = <*const T>::cast(next); let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } diff --git a/ash/src/vk/macros.rs b/ash/src/vk/macros.rs index e87d143..e986be3 100644 --- a/ash/src/vk/macros.rs +++ b/ash/src/vk/macros.rs @@ -94,10 +94,10 @@ macro_rules! handle_nondispatchable { impl Handle for $name { const TYPE: ObjectType = ObjectType::$ty; fn as_raw(self) -> u64 { - self.0 as u64 + self.0 } fn from_raw(x: u64) -> Self { - Self(x as _) + Self(x) } } impl $name { diff --git a/generator/src/lib.rs b/generator/src/lib.rs index 69d97bd..d703e3f 100644 --- a/generator/src/lib.rs +++ b/generator/src/lib.rs @@ -1,4 +1,5 @@ #![recursion_limit = "256"] +#![warn(trivial_casts, trivial_numeric_casts)] use heck::{CamelCase, ShoutySnakeCase, SnakeCase}; use itertools::Itertools; @@ -1499,7 +1500,7 @@ pub fn derive_debug(_struct: &vkxml::Struct, union_types: &HashSet<&str>) -> Opt let debug_value = if is_static_array(field) && field.basetype == "char" { quote! { &unsafe { - ::std::ffi::CStr::from_ptr(self.#param_ident.as_ptr() as *const c_char) + ::std::ffi::CStr::from_ptr(self.#param_ident.as_ptr()) } } } else if param_str.contains("pfn") { @@ -1551,7 +1552,9 @@ pub fn derive_setters( _ => None, }); - let has_next = members.clone().any(|field| field.param_ident() == "p_next"); + let next_field = members + .clone() + .find(|field| field.param_ident() == "p_next"); let nofilter_count_members = [ "VkPipelineViewportStateCreateInfo.pViewports", @@ -1610,7 +1613,7 @@ pub fn derive_setters( return Some(quote!{ pub fn code(mut self, code: &'a [u32]) -> Self { self.inner.code_size = code.len() * 4; - self.inner.p_code = code.as_ptr() as *const u32; + self.inner.p_code = code.as_ptr(); self } }); @@ -1627,7 +1630,7 @@ pub fn derive_setters( self.inner.p_sample_mask = if sample_mask.is_empty() { std::ptr::null() } else { - sample_mask.as_ptr() as *const SampleMask + sample_mask.as_ptr() }; self } @@ -1681,15 +1684,23 @@ pub fn derive_setters( let array_size = field.c_size.as_ref().unwrap(); let c_size = convert_c_expression(array_size, &BTreeMap::new()); let inner_type = field.inner_type_tokens(); - let mutable = if field.is_const { quote!(const) } else { quote!(mut) }; slice_param_ty_tokens = quote!([#inner_type; #c_size]); - ptr = quote!(as *#mutable #slice_param_ty_tokens); + ptr = quote!(); quote!() } else { let array_size_ident = format_ident!("{}", array_size.to_snake_case().as_str()); - quote!(self.inner.#array_size_ident = #param_ident_short.len() as _;) + + let size_field = members.clone().find(|m| m.name.as_ref() == Some(array_size)).unwrap(); + + let cast = if size_field.basetype == "size_t" { + quote!() + }else{ + quote!(as _) + }; + + quote!(self.inner.#array_size_ident = #param_ident_short.len()#cast;) }; let mutable = if field.is_const { quote!() } else { quote!(mut) }; @@ -1731,10 +1742,17 @@ pub fn derive_setters( let extends_name = format_ident!("Extends{}", name); - let is_root_struct = has_next && root_structs.contains(&name); + // The `p_next` field should only be considered if this struct is also a root struct + let root_struct_next_field = next_field.filter(|_| root_structs.contains(&name)); // We only implement a next methods for root structs with a `pnext` field. - let next_function = if is_root_struct { + let next_function = if let Some(next_field) = root_struct_next_field { + assert_eq!(next_field.basetype, "void"); + let mutability = if next_field.is_const { + quote!(const) + } else { + quote!(mut) + }; quote! { /// Prepends the given extension struct between the root and the first pointer. This /// method only exists on structs that can be passed to a function directly. Only @@ -1742,8 +1760,8 @@ pub fn derive_setters( /// If the chain looks like `A -> B -> C`, and you call `builder.push_next(&mut D)`, then the /// chain will look like `A -> D -> B -> C`. pub fn push_next(mut self, next: &'a mut T) -> Self { - unsafe{ - let next_ptr = next as *mut T as *mut BaseOutStructure; + unsafe { + let next_ptr = <*#mutability T>::cast(next); // `next` here can contain a pointer chain. This means that we must correctly // attach he head to the root and the tail to the rest of the chain // For example: @@ -1755,7 +1773,7 @@ pub fn derive_setters( // next chain let last_next = ptr_chain_iter(next).last().unwrap(); (*last_next).p_next = self.inner.p_next as _; - self.inner.p_next = next_ptr as _; + self.inner.p_next = next_ptr; } self } @@ -1766,7 +1784,7 @@ pub fn derive_setters( // Root structs come with their own trait that structs that extend // this struct will implement - let next_trait = if is_root_struct { + let next_trait = if root_struct_next_field.is_some() { quote!(pub unsafe trait #extends_name {}) } else { quote!()