Skip to content

Commit

Permalink
fix clippy for rust 1.67 (#3435)
Browse files Browse the repository at this point in the history
* clippy --fix

* elide lifetimes

* fmt and more fixes

* disable clippy::needless_borrowed_reference as it clashes with clippy::pattern_type_mismatch

* missed flags for target=wasm32-unknown-unknown
  • Loading branch information
Elabajaba authored Feb 1, 2023
1 parent c371e70 commit 1e27fd4
Show file tree
Hide file tree
Showing 26 changed files with 94 additions and 102 deletions.
2 changes: 1 addition & 1 deletion wgpu-core/src/command/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ pub enum RenderPassErrorInner {
#[error(transparent)]
MissingDownlevelFlags(#[from] MissingDownlevelFlags),
#[error("indirect draw uses bytes {offset}..{end_offset} {} which overruns indirect buffer of size {buffer_size}",
count.map_or_else(String::new, |v| format!("(using count {})", v)))]
count.map_or_else(String::new, |v| format!("(using count {v})")))]
IndirectBufferOverrun {
count: Option<NonZeroU32>,
offset: u64,
Expand Down
6 changes: 3 additions & 3 deletions wgpu-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ pub struct ErrorFormatter<'a> {

impl<'a> ErrorFormatter<'a> {
pub fn error(&mut self, err: &dyn Error) {
writeln!(self.writer, " {}", err).expect("Error formatting error");
writeln!(self.writer, " {err}").expect("Error formatting error");
}

pub fn note(&mut self, note: &dyn fmt::Display) {
writeln!(self.writer, " note: {}", note).expect("Error formatting error");
writeln!(self.writer, " note: {note}").expect("Error formatting error");
}

pub fn label(&mut self, label_key: &str, label_value: &str) {
if !label_key.is_empty() && !label_value.is_empty() {
self.note(&format!("{} = `{}`", label_key, label_value));
self.note(&format!("{label_key} = `{label_value}`"));
}
}

Expand Down
2 changes: 1 addition & 1 deletion wgpu-core/src/hub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ impl<T, I: id::TypedId> Storage<T, I> {
}
match std::mem::replace(&mut self.map[index], element) {
Element::Vacant => {}
_ => panic!("Index {:?} is already occupied", index),
_ => panic!("Index {index:?} is already occupied"),
}
}

Expand Down
2 changes: 2 additions & 0 deletions wgpu-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
// For some reason `rustc` can warn about these in const generics even
// though they are required.
unused_braces,
// Clashes with clippy::pattern_type_mismatch
clippy::needless_borrowed_reference,
)]
#![warn(
trivial_casts,
Expand Down
2 changes: 1 addition & 1 deletion wgpu-core/src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl fmt::Display for ShaderError<naga::front::wgsl::ParseError> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let label = self.label.as_deref().unwrap_or_default();
let string = self.inner.emit_to_string(&self.source);
write!(f, "\nShader '{}' parsing {}", label, string)
write!(f, "\nShader '{label}' parsing {string}")
}
}
impl fmt::Display for ShaderError<naga::WithSpan<naga::valid::ValidationError>> {
Expand Down
9 changes: 3 additions & 6 deletions wgpu-hal/src/auxil/renderdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ impl RenderDoc {
Err(e) => {
return RenderDoc::NotAvailable {
reason: format!(
"Unable to load renderdoc library '{}': {:?}",
renderdoc_filename, e
"Unable to load renderdoc library '{renderdoc_filename}': {e:?}"
),
}
}
Expand All @@ -75,8 +74,7 @@ impl RenderDoc {
Err(e) => {
return RenderDoc::NotAvailable {
reason: format!(
"Unable to get RENDERDOC_GetAPI from renderdoc library '{}': {:?}",
renderdoc_filename, e
"Unable to get RENDERDOC_GetAPI from renderdoc library '{renderdoc_filename}': {e:?}"
),
}
}
Expand All @@ -91,8 +89,7 @@ impl RenderDoc {
},
return_value => RenderDoc::NotAvailable {
reason: format!(
"Unable to get API from renderdoc library '{}': {}",
renderdoc_filename, return_value
"Unable to get API from renderdoc library '{renderdoc_filename}': {return_value}"
),
},
}
Expand Down
4 changes: 2 additions & 2 deletions wgpu-hal/src/dx12/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ impl super::Device {
profiling::scope!("naga::back::hlsl::write");
writer
.write(module, &stage.module.naga.info)
.map_err(|e| crate::PipelineError::Linkage(stage_bit, format!("HLSL: {:?}", e)))?
.map_err(|e| crate::PipelineError::Linkage(stage_bit, format!("HLSL: {e:?}")))?
};

let full_stage = format!(
Expand All @@ -231,7 +231,7 @@ impl super::Device {

let raw_ep = reflection_info.entry_point_names[ep_index]
.as_ref()
.map_err(|e| crate::PipelineError::Linkage(stage_bit, format!("{}", e)))?;
.map_err(|e| crate::PipelineError::Linkage(stage_bit, format!("{e}")))?;

let source_name = stage
.module
Expand Down
8 changes: 4 additions & 4 deletions wgpu-hal/src/dx12/shader_compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub(super) fn compile_fxc(
log::Level::Info,
),
Err(e) => {
let mut full_msg = format!("FXC D3DCompile error ({})", e);
let mut full_msg = format!("FXC D3DCompile error ({e})");
if !error.is_null() {
use std::fmt::Write as _;
let message = unsafe {
Expand Down Expand Up @@ -150,7 +150,7 @@ mod dxc {
let blob = match dxc_container
.library
.create_blob_with_encoding_from_str(source)
.map_err(|e| crate::PipelineError::Linkage(stage_bit, format!("DXC blob error: {}", e)))
.map_err(|e| crate::PipelineError::Linkage(stage_bit, format!("DXC blob error: {e}")))
{
Ok(blob) => blob,
Err(e) => return (Err(e), log::Level::Error),
Expand All @@ -176,15 +176,15 @@ mod dxc {
Err(e) => (
Err(crate::PipelineError::Linkage(
stage_bit,
format!("DXC compile error: {}", e),
format!("DXC compile error: {e}"),
)),
log::Level::Error,
),
},
Err(e) => (
Err(crate::PipelineError::Linkage(
stage_bit,
format!("DXC compile error: {:?}", e),
format!("DXC compile error: {e:?}"),
)),
log::Level::Error,
),
Expand Down
4 changes: 2 additions & 2 deletions wgpu-hal/src/dx12/suballocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ mod allocation {
match allocator.lock().allocator.free(allocation.allocation) {
Ok(_) => (),
// TODO: Don't panic here
Err(e) => panic!("Failed to destroy dx12 buffer, {}", e),
Err(e) => panic!("Failed to destroy dx12 buffer, {e}"),
};
}

Expand All @@ -164,7 +164,7 @@ mod allocation {
match allocator.lock().allocator.free(allocation.allocation) {
Ok(_) => (),
// TODO: Don't panic here
Err(e) => panic!("Failed to destroy dx12 texture, {}", e),
Err(e) => panic!("Failed to destroy dx12 texture, {e}"),
};
}

Expand Down
8 changes: 4 additions & 4 deletions wgpu-hal/src/gles/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,12 @@ impl super::Device {
policies,
)
.map_err(|e| {
let msg = format!("{}", e);
let msg = format!("{e}");
crate::PipelineError::Linkage(map_naga_stage(naga_stage), msg)
})?;

let reflection_info = writer.write().map_err(|e| {
let msg = format!("{}", e);
let msg = format!("{e}");
crate::PipelineError::Linkage(map_naga_stage(naga_stage), msg)
})?;

Expand Down Expand Up @@ -358,7 +358,7 @@ impl super::Device {

// Create empty fragment shader if only vertex shader is present
if has_stages == wgt::ShaderStages::VERTEX {
let shader_src = format!("#version {} es \n void main(void) {{}}", glsl_version,);
let shader_src = format!("#version {glsl_version} es \n void main(void) {{}}",);
log::info!("Only vertex shader is present. Creating an empty fragment shader",);
let shader = unsafe {
Self::compile_shader(
Expand Down Expand Up @@ -1248,7 +1248,7 @@ impl crate::Device<super::Api> for super::Device {

if let Some(label) = desc.label {
temp_string.clear();
let _ = write!(temp_string, "{}[{}]", label, i);
let _ = write!(temp_string, "{label}[{i}]");
let name = unsafe { mem::transmute(query) };
unsafe { gl.object_label(glow::QUERY, name, Some(&temp_string)) };
}
Expand Down
2 changes: 2 additions & 0 deletions wgpu-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
clippy::non_send_fields_in_send_ty,
// TODO!
clippy::missing_safety_doc,
// Clashes with clippy::pattern_type_mismatch
clippy::needless_borrowed_reference,
)]
#![warn(
trivial_casts,
Expand Down
8 changes: 4 additions & 4 deletions wgpu-hal/src/vulkan/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ impl gpu_alloc::MemoryDevice<vk::DeviceMemory> for super::DeviceShared {
Err(gpu_alloc::OutOfMemory::OutOfHostMemory)
}
Err(vk::Result::ERROR_TOO_MANY_OBJECTS) => panic!("Too many objects"),
Err(err) => panic!("Unexpected Vulkan error: `{}`", err),
Err(err) => panic!("Unexpected Vulkan error: `{err}`"),
}
}

Expand All @@ -348,7 +348,7 @@ impl gpu_alloc::MemoryDevice<vk::DeviceMemory> for super::DeviceShared {
Err(gpu_alloc::DeviceMapError::OutOfHostMemory)
}
Err(vk::Result::ERROR_MEMORY_MAP_FAILED) => Err(gpu_alloc::DeviceMapError::MapFailed),
Err(err) => panic!("Unexpected Vulkan error: `{}`", err),
Err(err) => panic!("Unexpected Vulkan error: `{err}`"),
}
}

Expand Down Expand Up @@ -707,7 +707,7 @@ impl super::Device {
Some(&pipeline_options),
)
}
.map_err(|e| crate::PipelineError::Linkage(stage_flags, format!("{}", e)))?;
.map_err(|e| crate::PipelineError::Linkage(stage_flags, format!("{e}")))?;
self.create_shader_module_impl(&spv)?
}
};
Expand Down Expand Up @@ -1489,7 +1489,7 @@ impl crate::Device<super::Api> for super::Device {
&naga_options,
None,
)
.map_err(|e| crate::ShaderError::Compilation(format!("{}", e)))?,
.map_err(|e| crate::ShaderError::Compilation(format!("{e}")))?,
)
}
crate::ShaderInput::SpirV(spv) => Cow::Borrowed(spv),
Expand Down
73 changes: 35 additions & 38 deletions wgpu-info/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ mod inner {
let features = adapter.features();
let limits = adapter.limits();

println!("Adapter {}:", idx);
println!("Adapter {idx}:");
println!("\t Backend: {:?}", info.backend);
println!("\t Name: {:?}", info.name);
println!("\t VendorID: {:?}", info.vendor);
Expand All @@ -147,7 +147,7 @@ mod inner {
let bit = wgpu::Features::from_bits(1 << i as u64);
if let Some(bit) = bit {
if wgpu::Features::all().contains(bit) {
println!("\t\t{:>63} {}", format!("{:?}:", bit), features.contains(bit));
println!("\t\t{:>63} {}", format!("{bit:?}:"), features.contains(bit));
}
}
}
Expand Down Expand Up @@ -184,48 +184,48 @@ mod inner {
max_compute_workgroup_size_z,
max_compute_workgroups_per_dimension,
} = limits;
println!("\t\t Max Texture Dimension 1d: {}", max_texture_dimension_1d);
println!("\t\t Max Texture Dimension 2d: {}", max_texture_dimension_2d);
println!("\t\t Max Texture Dimension 3d: {}", max_texture_dimension_3d);
println!("\t\t Max Texture Array Layers: {}", max_texture_array_layers);
println!("\t\t Max Bind Groups: {}", max_bind_groups);
println!("\t\t Max Bindings Per Bind Group: {}", max_bindings_per_bind_group);
println!("\t\t Max Dynamic Uniform Buffers Per Pipeline Layout: {}", max_dynamic_uniform_buffers_per_pipeline_layout);
println!("\t\t Max Dynamic Storage Buffers Per Pipeline Layout: {}", max_dynamic_storage_buffers_per_pipeline_layout);
println!("\t\t Max Sampled Textures Per Shader Stage: {}", max_sampled_textures_per_shader_stage);
println!("\t\t Max Samplers Per Shader Stage: {}", max_samplers_per_shader_stage);
println!("\t\t Max Storage Buffers Per Shader Stage: {}", max_storage_buffers_per_shader_stage);
println!("\t\t Max Storage Textures Per Shader Stage: {}", max_storage_textures_per_shader_stage);
println!("\t\t Max Uniform Buffers Per Shader Stage: {}", max_uniform_buffers_per_shader_stage);
println!("\t\t Max Uniform Buffer Binding Size: {}", max_uniform_buffer_binding_size);
println!("\t\t Max Storage Buffer Binding Size: {}", max_storage_buffer_binding_size);
println!("\t\t Max Buffer Size: {}", max_buffer_size);
println!("\t\t Max Vertex Buffers: {}", max_vertex_buffers);
println!("\t\t Max Vertex Attributes: {}", max_vertex_attributes);
println!("\t\t Max Vertex Buffer Array Stride: {}", max_vertex_buffer_array_stride);
println!("\t\t Max Push Constant Size: {}", max_push_constant_size);
println!("\t\t Min Uniform Buffer Offset Alignment: {}", min_uniform_buffer_offset_alignment);
println!("\t\t Min Storage Buffer Offset Alignment: {}", min_storage_buffer_offset_alignment);
println!("\t\t Max Inter-Stage Shader Component: {}", max_inter_stage_shader_components);
println!("\t\t Max Compute Workgroup Storage Size: {}", max_compute_workgroup_storage_size);
println!("\t\t Max Compute Invocations Per Workgroup: {}", max_compute_invocations_per_workgroup);
println!("\t\t Max Compute Workgroup Size X: {}", max_compute_workgroup_size_x);
println!("\t\t Max Compute Workgroup Size Y: {}", max_compute_workgroup_size_y);
println!("\t\t Max Compute Workgroup Size Z: {}", max_compute_workgroup_size_z);
println!("\t\t Max Compute Workgroups Per Dimension: {}", max_compute_workgroups_per_dimension);
println!("\t\t Max Texture Dimension 1d: {max_texture_dimension_1d}");
println!("\t\t Max Texture Dimension 2d: {max_texture_dimension_2d}");
println!("\t\t Max Texture Dimension 3d: {max_texture_dimension_3d}");
println!("\t\t Max Texture Array Layers: {max_texture_array_layers}");
println!("\t\t Max Bind Groups: {max_bind_groups}");
println!("\t\t Max Bindings Per Bind Group: {max_bindings_per_bind_group}");
println!("\t\t Max Dynamic Uniform Buffers Per Pipeline Layout: {max_dynamic_uniform_buffers_per_pipeline_layout}");
println!("\t\t Max Dynamic Storage Buffers Per Pipeline Layout: {max_dynamic_storage_buffers_per_pipeline_layout}");
println!("\t\t Max Sampled Textures Per Shader Stage: {max_sampled_textures_per_shader_stage}");
println!("\t\t Max Samplers Per Shader Stage: {max_samplers_per_shader_stage}");
println!("\t\t Max Storage Buffers Per Shader Stage: {max_storage_buffers_per_shader_stage}");
println!("\t\t Max Storage Textures Per Shader Stage: {max_storage_textures_per_shader_stage}");
println!("\t\t Max Uniform Buffers Per Shader Stage: {max_uniform_buffers_per_shader_stage}");
println!("\t\t Max Uniform Buffer Binding Size: {max_uniform_buffer_binding_size}");
println!("\t\t Max Storage Buffer Binding Size: {max_storage_buffer_binding_size}");
println!("\t\t Max Buffer Size: {max_buffer_size}");
println!("\t\t Max Vertex Buffers: {max_vertex_buffers}");
println!("\t\t Max Vertex Attributes: {max_vertex_attributes}");
println!("\t\t Max Vertex Buffer Array Stride: {max_vertex_buffer_array_stride}");
println!("\t\t Max Push Constant Size: {max_push_constant_size}");
println!("\t\t Min Uniform Buffer Offset Alignment: {min_uniform_buffer_offset_alignment}");
println!("\t\t Min Storage Buffer Offset Alignment: {min_storage_buffer_offset_alignment}");
println!("\t\t Max Inter-Stage Shader Component: {max_inter_stage_shader_components}");
println!("\t\t Max Compute Workgroup Storage Size: {max_compute_workgroup_storage_size}");
println!("\t\t Max Compute Invocations Per Workgroup: {max_compute_invocations_per_workgroup}");
println!("\t\t Max Compute Workgroup Size X: {max_compute_workgroup_size_x}");
println!("\t\t Max Compute Workgroup Size Y: {max_compute_workgroup_size_y}");
println!("\t\t Max Compute Workgroup Size Z: {max_compute_workgroup_size_z}");
println!("\t\t Max Compute Workgroups Per Dimension: {max_compute_workgroups_per_dimension}");

println!("\tDownlevel Properties:");
let wgpu::DownlevelCapabilities {
shader_model,
limits: _,
flags,
} = downlevel;
println!("\t\t Shader Model: {:?}", shader_model);
println!("\t\t Shader Model: {shader_model:?}");
for i in 0..(size_of::<wgpu::DownlevelFlags>() * 8) {
let bit = wgpu::DownlevelFlags::from_bits(1 << i as u64);
if let Some(bit) = bit {
if wgpu::DownlevelFlags::all().contains(bit) {
println!("\t\t{:>37} {}", format!("{:?}:", bit), flags.contains(bit));
println!("\t\t{:>37} {}", format!("{bit:?}:"), flags.contains(bit));
}
}
}
Expand All @@ -241,7 +241,7 @@ mod inner {
format!("{format:?}:")
}
};
print!("\t\t{:>21}", format_name);
print!("\t\t{format_name:>21}");
for i in 0..(size_of::<wgpu::TextureUsages>() * 8) {
let bit = wgpu::TextureUsages::from_bits(1 << i as u32);
if let Some(bit) = bit {
Expand Down Expand Up @@ -338,10 +338,7 @@ mod inner {

let all_time = all_start.elapsed().as_secs_f32();

println!(
"=========== {} adapters PASSED in {:.3}s ===========",
adapter_count, all_time
);
println!("=========== {adapter_count} adapters PASSED in {all_time:.3}s ===========");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion wgpu/examples/boids/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ impl framework::Example for Example {
for i in 0..2 {
particle_buffers.push(
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
label: Some(&format!("Particle Buffer {}", i)),
label: Some(&format!("Particle Buffer {i}")),
contents: bytemuck::cast_slice(&initial_particle_data),
usage: wgpu::BufferUsages::VERTEX
| wgpu::BufferUsages::STORAGE
Expand Down
2 changes: 1 addition & 1 deletion wgpu/examples/cube/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl<F: Future<Output = Option<wgpu::Error>>> Future for ErrorFuture<F> {
let inner = unsafe { self.map_unchecked_mut(|me| &mut me.inner) };
inner.poll(cx).map(|error| {
if let Some(e) = error {
panic!("Rendering {}", e);
panic!("Rendering {e}");
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion wgpu/examples/hello-compute/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const OVERFLOW: u32 = 0xffffffff;
async fn run() {
let numbers = if std::env::args().len() <= 1 {
let default = vec![1, 2, 3, 4];
println!("No numbers were provided, defaulting to {:?}", default);
println!("No numbers were provided, defaulting to {default:?}");
default
} else {
std::env::args()
Expand Down
Loading

0 comments on commit 1e27fd4

Please sign in to comment.