From faf11a77618f87ba18fb5a12962bf93bcccd458e Mon Sep 17 00:00:00 2001 From: daxpedda Date: Sat, 28 Oct 2023 01:29:28 +0200 Subject: [PATCH] Apply `elided_lifetimes_in_paths` --- wgpu/src/backend/direct.rs | 62 +++++++-------- 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, 222 insertions(+), 219 deletions(-) diff --git a/wgpu/src/backend/direct.rs b/wgpu/src/backend/direct.rs index bfdd1909abc..adf044da56e 100644 --- a/wgpu/src/backend/direct.rs +++ b/wgpu/src/backend/direct.rs @@ -100,7 +100,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; @@ -133,7 +133,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; @@ -158,7 +158,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 { @@ -307,7 +307,7 @@ impl Context { sink_mutex: &Mutex, cause: impl Error + WasmNotSend + WasmNotSync + 'static, label_key: &'static str, - label: Label, + label: Label<'_>, string: &'static str, ) { let error = wgc::error::ContextError { @@ -374,14 +374,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, @@ -395,7 +395,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(), @@ -608,7 +608,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 { @@ -625,7 +625,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; @@ -888,7 +888,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; @@ -950,7 +950,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 { @@ -978,7 +978,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 { @@ -1003,7 +1003,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; @@ -1118,7 +1118,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 @@ -1161,7 +1161,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; @@ -1232,7 +1232,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; @@ -1310,7 +1310,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; @@ -1340,7 +1340,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), @@ -1380,7 +1380,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); @@ -2327,7 +2327,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, @@ -2431,7 +2431,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, @@ -2458,7 +2458,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, @@ -2484,7 +2484,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( @@ -2502,7 +2502,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, @@ -2519,8 +2519,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, @@ -2537,7 +2537,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, @@ -2552,7 +2552,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, @@ -2567,7 +2570,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, @@ -2582,7 +2585,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, @@ -2597,7 +2600,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, @@ -2612,7 +2615,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; @@ -2634,7 +2637,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 { @@ -2665,7 +2668,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 @@ -2706,7 +2709,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 { @@ -2738,7 +2741,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 { @@ -2749,7 +2752,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 { @@ -3131,12 +3134,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, @@ -3146,7 +3149,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, @@ -3305,7 +3308,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 { @@ -3321,7 +3324,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, @@ -3449,7 +3452,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, @@ -3496,8 +3499,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( @@ -3513,8 +3516,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( @@ -3536,8 +3539,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( @@ -4446,7 +4449,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 { @@ -4689,7 +4692,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]; @@ -4806,7 +4809,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, @@ -4827,7 +4830,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( @@ -5091,7 +5094,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() } } @@ -5316,7 +5319,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 98ad2c13959..d6ef7a0c466 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 2d6f0ed7fe8..a35fa5482e2 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 3b28753e48e..9c06095c283 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 5c814e0c51c..98b6155f153 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 {