From 8859310be2be25d9b98ba52120c4279c0c1a62d5 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Fri, 17 Nov 2023 21:59:56 +0100 Subject: [PATCH] Add more lints (#4598) --- wgpu/src/backend/direct.rs | 64 ++++++++-------- wgpu/src/backend/web.rs | 58 +++++++------- wgpu/src/context.rs | 150 ++++++++++++++++++------------------ wgpu/src/lib.rs | 153 +++++++++++++++++++------------------ wgpu/src/util/belt.rs | 2 +- wgpu/src/util/device.rs | 6 +- wgpu/src/util/init.rs | 4 +- wgpu/src/util/mod.rs | 6 +- 8 files changed, 223 insertions(+), 220 deletions(-) diff --git a/wgpu/src/backend/direct.rs b/wgpu/src/backend/direct.rs index c99190baf7..5deb2030b7 100644 --- a/wgpu/src/backend/direct.rs +++ b/wgpu/src/backend/direct.rs @@ -101,7 +101,7 @@ impl Context { &self, adapter: &wgc::id::AdapterId, hal_device: hal::OpenDevice, - desc: &crate::DeviceDescriptor, + desc: &crate::DeviceDescriptor<'_>, trace_dir: Option<&std::path::Path>, ) -> Result<(Device, Queue), crate::RequestDeviceError> { let global = &self.0; @@ -134,7 +134,7 @@ impl Context { &self, hal_texture: A::Texture, device: &Device, - desc: &TextureDescriptor, + desc: &TextureDescriptor<'_>, ) -> Texture { let descriptor = desc.map_label_and_view_formats(|l| l.map(Borrowed), |v| v.to_vec()); let global = &self.0; @@ -159,7 +159,7 @@ impl Context { &self, hal_buffer: A::Buffer, device: &Device, - desc: &BufferDescriptor, + desc: &BufferDescriptor<'_>, ) -> (wgc::id::BufferId, Buffer) { let global = &self.0; let (id, error) = unsafe { @@ -308,7 +308,7 @@ impl Context { sink_mutex: &Mutex, cause: impl Error + WasmNotSendSync + 'static, label_key: &'static str, - label: Label, + label: Label<'_>, string: &'static str, ) { let error = wgc::error::ContextError { @@ -375,14 +375,14 @@ impl Context { } } -fn map_buffer_copy_view(view: crate::ImageCopyBuffer) -> wgc::command::ImageCopyBuffer { +fn map_buffer_copy_view(view: crate::ImageCopyBuffer<'_>) -> wgc::command::ImageCopyBuffer { wgc::command::ImageCopyBuffer { buffer: view.buffer.id.into(), layout: view.layout, } } -fn map_texture_copy_view(view: crate::ImageCopyTexture) -> wgc::command::ImageCopyTexture { +fn map_texture_copy_view(view: crate::ImageCopyTexture<'_>) -> wgc::command::ImageCopyTexture { wgc::command::ImageCopyTexture { texture: view.texture.id.into(), mip_level: view.mip_level, @@ -396,7 +396,7 @@ fn map_texture_copy_view(view: crate::ImageCopyTexture) -> wgc::command::ImageCo allow(unused) )] fn map_texture_tagged_copy_view( - view: crate::ImageCopyTextureTagged, + view: crate::ImageCopyTextureTagged<'_>, ) -> wgc::command::ImageCopyTextureTagged { wgc::command::ImageCopyTextureTagged { texture: view.texture.id.into(), @@ -610,7 +610,7 @@ impl crate::Context for Context { fn instance_request_adapter( &self, - options: &crate::RequestAdapterOptions, + options: &crate::RequestAdapterOptions<'_, '_>, ) -> Self::RequestAdapterFuture { let id = self.0.request_adapter( &wgc::instance::RequestAdapterOptions { @@ -627,7 +627,7 @@ impl crate::Context for Context { &self, adapter: &Self::AdapterId, _adapter_data: &Self::AdapterData, - desc: &crate::DeviceDescriptor, + desc: &crate::DeviceDescriptor<'_>, trace_dir: Option<&std::path::Path>, ) -> Self::RequestDeviceFuture { let global = &self.0; @@ -890,7 +890,7 @@ impl crate::Context for Context { &self, device: &Self::DeviceId, device_data: &Self::DeviceData, - desc: ShaderModuleDescriptor, + desc: ShaderModuleDescriptor<'_>, shader_bound_checks: wgt::ShaderBoundChecks, ) -> (Self::ShaderModuleId, Self::ShaderModuleData) { let global = &self.0; @@ -952,7 +952,7 @@ impl crate::Context for Context { &self, device: &Self::DeviceId, device_data: &Self::DeviceData, - desc: &ShaderModuleDescriptorSpirV, + desc: &ShaderModuleDescriptorSpirV<'_>, ) -> (Self::ShaderModuleId, Self::ShaderModuleData) { let global = &self.0; let descriptor = wgc::pipeline::ShaderModuleDescriptor { @@ -980,7 +980,7 @@ impl crate::Context for Context { &self, device: &Self::DeviceId, device_data: &Self::DeviceData, - desc: &BindGroupLayoutDescriptor, + desc: &BindGroupLayoutDescriptor<'_>, ) -> (Self::BindGroupLayoutId, Self::BindGroupLayoutData) { let global = &self.0; let descriptor = wgc::binding_model::BindGroupLayoutDescriptor { @@ -1005,7 +1005,7 @@ impl crate::Context for Context { &self, device: &Self::DeviceId, device_data: &Self::DeviceData, - desc: &BindGroupDescriptor, + desc: &BindGroupDescriptor<'_>, ) -> (Self::BindGroupId, Self::BindGroupData) { use wgc::binding_model as bm; @@ -1120,7 +1120,7 @@ impl crate::Context for Context { &self, device: &Self::DeviceId, device_data: &Self::DeviceData, - desc: &PipelineLayoutDescriptor, + desc: &PipelineLayoutDescriptor<'_>, ) -> (Self::PipelineLayoutId, Self::PipelineLayoutData) { // Limit is always less or equal to hal::MAX_BIND_GROUPS, so this is always right // Guards following ArrayVec @@ -1163,7 +1163,7 @@ impl crate::Context for Context { &self, device: &Self::DeviceId, device_data: &Self::DeviceData, - desc: &RenderPipelineDescriptor, + desc: &RenderPipelineDescriptor<'_>, ) -> (Self::RenderPipelineId, Self::RenderPipelineData) { use wgc::pipeline as pipe; @@ -1234,7 +1234,7 @@ impl crate::Context for Context { &self, device: &Self::DeviceId, device_data: &Self::DeviceData, - desc: &ComputePipelineDescriptor, + desc: &ComputePipelineDescriptor<'_>, ) -> (Self::ComputePipelineId, Self::ComputePipelineData) { use wgc::pipeline as pipe; @@ -1312,7 +1312,7 @@ impl crate::Context for Context { &self, device: &Self::DeviceId, device_data: &Self::DeviceData, - desc: &TextureDescriptor, + desc: &TextureDescriptor<'_>, ) -> (Self::TextureId, Self::TextureData) { let wgt_desc = desc.map_label_and_view_formats(|l| l.map(Borrowed), |v| v.to_vec()); let global = &self.0; @@ -1342,7 +1342,7 @@ impl crate::Context for Context { &self, device: &Self::DeviceId, device_data: &Self::DeviceData, - desc: &SamplerDescriptor, + desc: &SamplerDescriptor<'_>, ) -> (Self::SamplerId, Self::SamplerData) { let descriptor = wgc::resource::SamplerDescriptor { label: desc.label.map(Borrowed), @@ -1382,7 +1382,7 @@ impl crate::Context for Context { &self, device: &Self::DeviceId, device_data: &Self::DeviceData, - desc: &wgt::QuerySetDescriptor, - desc: &DeviceDescriptor, + desc: &DeviceDescriptor<'_>, trace_path: Option<&std::path::Path>, ) -> Result<(Device, Queue), RequestDeviceError> { let context = Arc::clone(&self.context); @@ -2363,7 +2363,7 @@ impl Adapter { } /// Returns whether this adapter may present to the passed surface. - pub fn is_surface_supported(&self, surface: &Surface) -> bool { + pub fn is_surface_supported(&self, surface: &Surface<'_>) -> bool { DynContext::adapter_is_surface_supported( &*self.context, &self.id, @@ -2467,7 +2467,7 @@ impl Device { } /// Creates a shader module from either SPIR-V or WGSL source code. - pub fn create_shader_module(&self, desc: ShaderModuleDescriptor) -> ShaderModule { + pub fn create_shader_module(&self, desc: ShaderModuleDescriptor<'_>) -> ShaderModule { let (id, data) = DynContext::device_create_shader_module( &*self.context, &self.id, @@ -2494,7 +2494,7 @@ impl Device { /// This has no effect on web. pub unsafe fn create_shader_module_unchecked( &self, - desc: ShaderModuleDescriptor, + desc: ShaderModuleDescriptor<'_>, ) -> ShaderModule { let (id, data) = DynContext::device_create_shader_module( &*self.context, @@ -2520,7 +2520,7 @@ impl Device { /// See also [`include_spirv_raw!`] and [`util::make_spirv_raw`]. pub unsafe fn create_shader_module_spirv( &self, - desc: &ShaderModuleDescriptorSpirV, + desc: &ShaderModuleDescriptorSpirV<'_>, ) -> ShaderModule { let (id, data) = unsafe { DynContext::device_create_shader_module_spirv( @@ -2538,7 +2538,7 @@ impl Device { } /// Creates an empty [`CommandEncoder`]. - pub fn create_command_encoder(&self, desc: &CommandEncoderDescriptor) -> CommandEncoder { + pub fn create_command_encoder(&self, desc: &CommandEncoderDescriptor<'_>) -> CommandEncoder { let (id, data) = DynContext::device_create_command_encoder( &*self.context, &self.id, @@ -2555,8 +2555,8 @@ impl Device { /// Creates an empty [`RenderBundleEncoder`]. pub fn create_render_bundle_encoder( &self, - desc: &RenderBundleEncoderDescriptor, - ) -> RenderBundleEncoder { + desc: &RenderBundleEncoderDescriptor<'_>, + ) -> RenderBundleEncoder<'_> { let (id, data) = DynContext::device_create_render_bundle_encoder( &*self.context, &self.id, @@ -2573,7 +2573,7 @@ impl Device { } /// Creates a new [`BindGroup`]. - pub fn create_bind_group(&self, desc: &BindGroupDescriptor) -> BindGroup { + pub fn create_bind_group(&self, desc: &BindGroupDescriptor<'_>) -> BindGroup { let (id, data) = DynContext::device_create_bind_group( &*self.context, &self.id, @@ -2588,7 +2588,10 @@ impl Device { } /// Creates a [`BindGroupLayout`]. - pub fn create_bind_group_layout(&self, desc: &BindGroupLayoutDescriptor) -> BindGroupLayout { + pub fn create_bind_group_layout( + &self, + desc: &BindGroupLayoutDescriptor<'_>, + ) -> BindGroupLayout { let (id, data) = DynContext::device_create_bind_group_layout( &*self.context, &self.id, @@ -2603,7 +2606,7 @@ impl Device { } /// Creates a [`PipelineLayout`]. - pub fn create_pipeline_layout(&self, desc: &PipelineLayoutDescriptor) -> PipelineLayout { + pub fn create_pipeline_layout(&self, desc: &PipelineLayoutDescriptor<'_>) -> PipelineLayout { let (id, data) = DynContext::device_create_pipeline_layout( &*self.context, &self.id, @@ -2618,7 +2621,7 @@ impl Device { } /// Creates a [`RenderPipeline`]. - pub fn create_render_pipeline(&self, desc: &RenderPipelineDescriptor) -> RenderPipeline { + pub fn create_render_pipeline(&self, desc: &RenderPipelineDescriptor<'_>) -> RenderPipeline { let (id, data) = DynContext::device_create_render_pipeline( &*self.context, &self.id, @@ -2633,7 +2636,7 @@ impl Device { } /// Creates a [`ComputePipeline`]. - pub fn create_compute_pipeline(&self, desc: &ComputePipelineDescriptor) -> ComputePipeline { + pub fn create_compute_pipeline(&self, desc: &ComputePipelineDescriptor<'_>) -> ComputePipeline { let (id, data) = DynContext::device_create_compute_pipeline( &*self.context, &self.id, @@ -2648,7 +2651,7 @@ impl Device { } /// Creates a [`Buffer`]. - pub fn create_buffer(&self, desc: &BufferDescriptor) -> Buffer { + pub fn create_buffer(&self, desc: &BufferDescriptor<'_>) -> Buffer { let mut map_context = MapContext::new(desc.size); if desc.mapped_at_creation { map_context.initial_range = 0..desc.size; @@ -2670,7 +2673,7 @@ impl Device { /// Creates a new [`Texture`]. /// /// `desc` specifies the general format of the texture. - pub fn create_texture(&self, desc: &TextureDescriptor) -> Texture { + pub fn create_texture(&self, desc: &TextureDescriptor<'_>) -> Texture { let (id, data) = DynContext::device_create_texture(&*self.context, &self.id, self.data.as_ref(), desc); Texture { @@ -2701,7 +2704,7 @@ impl Device { pub unsafe fn create_texture_from_hal( &self, hal_texture: A::Texture, - desc: &TextureDescriptor, + desc: &TextureDescriptor<'_>, ) -> Texture { let texture = unsafe { self.context @@ -2742,7 +2745,7 @@ impl Device { pub unsafe fn create_buffer_from_hal( &self, hal_buffer: A::Buffer, - desc: &BufferDescriptor, + desc: &BufferDescriptor<'_>, ) -> Buffer { let mut map_context = MapContext::new(desc.size); if desc.mapped_at_creation { @@ -2774,7 +2777,7 @@ impl Device { /// Creates a new [`Sampler`]. /// /// `desc` specifies the behavior of the sampler. - pub fn create_sampler(&self, desc: &SamplerDescriptor) -> Sampler { + pub fn create_sampler(&self, desc: &SamplerDescriptor<'_>) -> Sampler { let (id, data) = DynContext::device_create_sampler(&*self.context, &self.id, self.data.as_ref(), desc); Sampler { @@ -2785,7 +2788,7 @@ impl Device { } /// Creates a new [`QuerySet`]. - pub fn create_query_set(&self, desc: &QuerySetDescriptor) -> QuerySet { + pub fn create_query_set(&self, desc: &QuerySetDescriptor<'_>) -> QuerySet { let (id, data) = DynContext::device_create_query_set(&*self.context, &self.id, self.data.as_ref(), desc); QuerySet { @@ -3180,12 +3183,12 @@ impl Drop for BufferViewMut<'_> { impl Buffer { /// Return the binding view of the entire buffer. - pub fn as_entire_binding(&self) -> BindingResource { + pub fn as_entire_binding(&self) -> BindingResource<'_> { BindingResource::Buffer(self.as_entire_buffer_binding()) } /// Return the binding view of the entire buffer. - pub fn as_entire_buffer_binding(&self) -> BufferBinding { + pub fn as_entire_buffer_binding(&self) -> BufferBinding<'_> { BufferBinding { buffer: self, offset: 0, @@ -3195,7 +3198,7 @@ impl Buffer { /// Use only a portion of this Buffer for a given operation. Choosing a range with no end /// will use the rest of the buffer. Using a totally unbounded range will use the entire buffer. - pub fn slice>(&self, bounds: S) -> BufferSlice { + pub fn slice>(&self, bounds: S) -> BufferSlice<'_> { let (offset, size) = range_to_offset_size(bounds); BufferSlice { buffer: self, @@ -3354,7 +3357,7 @@ impl Texture { } /// Creates a view of this texture. - pub fn create_view(&self, desc: &TextureViewDescriptor) -> TextureView { + pub fn create_view(&self, desc: &TextureViewDescriptor<'_>) -> TextureView { let (id, data) = DynContext::texture_create_view(&*self.context, &self.id, self.data.as_ref(), desc); TextureView { @@ -3370,7 +3373,7 @@ impl Texture { } /// Make an `ImageCopyTexture` representing the whole texture. - pub fn as_image_copy(&self) -> ImageCopyTexture { + pub fn as_image_copy(&self) -> ImageCopyTexture<'_> { ImageCopyTexture { texture: self, mip_level: 0, @@ -3498,7 +3501,7 @@ impl CommandEncoder { /// Begins recording of a compute pass. /// /// This function returns a [`ComputePass`] object which records a single compute pass. - pub fn begin_compute_pass(&mut self, desc: &ComputePassDescriptor) -> ComputePass { + pub fn begin_compute_pass(&mut self, desc: &ComputePassDescriptor<'_>) -> ComputePass<'_> { let id = self.id.as_ref().unwrap(); let (id, data) = DynContext::command_encoder_begin_compute_pass( &*self.context, @@ -3545,8 +3548,8 @@ impl CommandEncoder { /// Copy data from a buffer to a texture. pub fn copy_buffer_to_texture( &mut self, - source: ImageCopyBuffer, - destination: ImageCopyTexture, + source: ImageCopyBuffer<'_>, + destination: ImageCopyTexture<'_>, copy_size: Extent3d, ) { DynContext::command_encoder_copy_buffer_to_texture( @@ -3562,8 +3565,8 @@ impl CommandEncoder { /// Copy data from a texture to a buffer. pub fn copy_texture_to_buffer( &mut self, - source: ImageCopyTexture, - destination: ImageCopyBuffer, + source: ImageCopyTexture<'_>, + destination: ImageCopyBuffer<'_>, copy_size: Extent3d, ) { DynContext::command_encoder_copy_texture_to_buffer( @@ -3585,8 +3588,8 @@ impl CommandEncoder { /// - Copy would overrun either texture pub fn copy_texture_to_texture( &mut self, - source: ImageCopyTexture, - destination: ImageCopyTexture, + source: ImageCopyTexture<'_>, + destination: ImageCopyTexture<'_>, copy_size: Extent3d, ) { DynContext::command_encoder_copy_texture_to_texture( @@ -4495,7 +4498,7 @@ impl<'a> Drop for ComputePass<'a> { impl<'a> RenderBundleEncoder<'a> { /// Finishes recording and returns a [`RenderBundle`] that can be executed in other render passes. - pub fn finish(self, desc: &RenderBundleDescriptor) -> RenderBundle { + pub fn finish(self, desc: &RenderBundleDescriptor<'_>) -> RenderBundle { let (id, data) = DynContext::render_bundle_encoder_finish(&*self.context, self.id, self.data, desc); RenderBundle { @@ -4738,7 +4741,7 @@ pub struct QueueWriteBufferView<'a> { not(target_feature = "atomics") ) ))] -static_assertions::assert_impl_all!(QueueWriteBufferView: Send, Sync); +static_assertions::assert_impl_all!(QueueWriteBufferView<'_>: Send, Sync); impl Deref for QueueWriteBufferView<'_> { type Target = [u8]; @@ -4855,7 +4858,7 @@ impl Queue { /// This method fails if `size` overruns the size of `texture`, or if `data` is too short. pub fn write_texture( &self, - texture: ImageCopyTexture, + texture: ImageCopyTexture<'_>, data: &[u8], data_layout: ImageDataLayout, size: Extent3d, @@ -4876,7 +4879,7 @@ impl Queue { pub fn copy_external_image_to_texture( &self, source: &wgt::ImageCopyExternalImage, - dest: ImageCopyTextureTagged, + dest: ImageCopyTextureTagged<'_>, size: Extent3d, ) { DynContext::queue_copy_external_image_to_texture( @@ -5141,7 +5144,7 @@ impl Copy for Id {} #[cfg(feature = "expose-ids")] impl fmt::Debug for Id { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("Id").field(&self.0).finish() } } @@ -5366,7 +5369,7 @@ impl Surface<'_> { /// The returned value is guaranteed to be unique among all `Surface`s created from the same /// `Instance`. #[cfg_attr(docsrs, doc(cfg(feature = "expose-ids")))] - pub fn global_id(&self) -> Id { + pub fn global_id(&self) -> Id> { Id(self.id.global_id(), std::marker::PhantomData) } } diff --git a/wgpu/src/util/belt.rs b/wgpu/src/util/belt.rs index 98ad2c1395..d6ef7a0c46 100644 --- a/wgpu/src/util/belt.rs +++ b/wgpu/src/util/belt.rs @@ -98,7 +98,7 @@ impl StagingBelt { offset: BufferAddress, size: BufferSize, device: &Device, - ) -> BufferViewMut { + ) -> BufferViewMut<'_> { let mut chunk = if let Some(index) = self .active_chunks .iter() diff --git a/wgpu/src/util/device.rs b/wgpu/src/util/device.rs index f8e02421eb..840f9775f2 100644 --- a/wgpu/src/util/device.rs +++ b/wgpu/src/util/device.rs @@ -13,7 +13,7 @@ pub struct BufferInitDescriptor<'a> { /// Utility methods not meant to be in the main API. pub trait DeviceExt { /// Creates a [Buffer](crate::Buffer) with data to initialize it. - fn create_buffer_init(&self, desc: &BufferInitDescriptor) -> crate::Buffer; + fn create_buffer_init(&self, desc: &BufferInitDescriptor<'_>) -> crate::Buffer; /// Upload an entire texture and its mipmaps from a source buffer. /// @@ -30,7 +30,7 @@ pub trait DeviceExt { fn create_texture_with_data( &self, queue: &crate::Queue, - desc: &crate::TextureDescriptor, + desc: &crate::TextureDescriptor<'_>, data: &[u8], ) -> crate::Texture; } @@ -77,7 +77,7 @@ impl DeviceExt for crate::Device { fn create_texture_with_data( &self, queue: &crate::Queue, - desc: &crate::TextureDescriptor, + desc: &crate::TextureDescriptor<'_>, data: &[u8], ) -> crate::Texture { // Implicitly add the COPY_DST usage diff --git a/wgpu/src/util/init.rs b/wgpu/src/util/init.rs index 3b28753e48..9c06095c28 100644 --- a/wgpu/src/util/init.rs +++ b/wgpu/src/util/init.rs @@ -40,7 +40,7 @@ pub fn power_preference_from_env() -> Option { #[cfg(not(target_arch = "wasm32"))] pub fn initialize_adapter_from_env( instance: &Instance, - compatible_surface: Option<&Surface>, + compatible_surface: Option<&Surface<'_>>, ) -> Option { let desired_adapter_name = std::env::var("WGPU_ADAPTER_NAME") .as_deref() @@ -72,7 +72,7 @@ pub fn initialize_adapter_from_env( #[cfg(target_arch = "wasm32")] pub fn initialize_adapter_from_env( _instance: &Instance, - _compatible_surface: Option<&Surface>, + _compatible_surface: Option<&Surface<'_>>, ) -> Option { None } diff --git a/wgpu/src/util/mod.rs b/wgpu/src/util/mod.rs index 5c814e0c51..98b6155f15 100644 --- a/wgpu/src/util/mod.rs +++ b/wgpu/src/util/mod.rs @@ -34,7 +34,7 @@ pub use wgt::math::*; /// - Input is empty /// - SPIR-V magic number is missing from beginning of stream #[cfg(feature = "spirv")] -pub fn make_spirv(data: &[u8]) -> super::ShaderSource { +pub fn make_spirv(data: &[u8]) -> super::ShaderSource<'_> { super::ShaderSource::SpirV(make_spirv_raw(data)) } @@ -42,7 +42,7 @@ pub fn make_spirv(data: &[u8]) -> super::ShaderSource { /// Returns raw slice instead of ShaderSource. /// /// [`Device::create_shader_module_spirv`]: crate::Device::create_shader_module_spirv -pub fn make_spirv_raw(data: &[u8]) -> Cow<[u32]> { +pub fn make_spirv_raw(data: &[u8]) -> Cow<'_, [u32]> { const MAGIC_NUMBER: u32 = 0x0723_0203; assert_eq!( data.len() % size_of::(), @@ -94,7 +94,7 @@ impl DownloadBuffer { pub fn read_buffer( device: &super::Device, queue: &super::Queue, - buffer: &super::BufferSlice, + buffer: &super::BufferSlice<'_>, callback: impl FnOnce(Result) + Send + 'static, ) { let size = match buffer.size {