diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 831ab5529..c61149675 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,3 +43,23 @@ jobs: - name: cargo doc run: cargo --version; cargo doc --lib --no-deps continue-on-error: true + + lint: + name: Clippy + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - run: rustup component add clippy + - uses: actions-rs/cargo@v1 + with: + command: clippy + args: -- -D warnings + - uses: actions-rs/cargo@v1 + with: + command: fmt + args: -- --check diff --git a/wgpu/examples/capture/main.rs b/wgpu/examples/capture/main.rs index a1e9b21d3..dc77fffab 100644 --- a/wgpu/examples/capture/main.rs +++ b/wgpu/examples/capture/main.rs @@ -155,7 +155,7 @@ async fn create_png( // from the padded_buffer we write just the unpadded bytes into the image for chunk in padded_buffer.chunks(buffer_dimensions.padded_bytes_per_row) { png_writer - .write(&chunk[..buffer_dimensions.unpadded_bytes_per_row]) + .write_all(&chunk[..buffer_dimensions.unpadded_bytes_per_row]) .unwrap(); } png_writer.finish().unwrap(); diff --git a/wgpu/examples/framework.rs b/wgpu/examples/framework.rs index a99d79ed0..7392ca846 100644 --- a/wgpu/examples/framework.rs +++ b/wgpu/examples/framework.rs @@ -6,7 +6,7 @@ use winit::{ event_loop::{ControlFlow, EventLoop}, }; -#[cfg_attr(rustfmt, rustfmt_skip)] +#[rustfmt::skip] #[allow(unused)] pub const OPENGL_TO_WGPU_MATRIX: cgmath::Matrix4 = cgmath::Matrix4::new( 1.0, 0.0, 0.0, 0.0, diff --git a/wgpu/examples/msaa-line/main.rs b/wgpu/examples/msaa-line/main.rs index 7800a6e71..871418541 100644 --- a/wgpu/examples/msaa-line/main.rs +++ b/wgpu/examples/msaa-line/main.rs @@ -101,7 +101,7 @@ impl Example { let multisampled_frame_descriptor = &wgpu::TextureDescriptor { size: multisampled_texture_extent, mip_level_count: 1, - sample_count: sample_count, + sample_count, dimension: wgpu::TextureDimension::D2, format: sc_desc.format, usage: wgpu::TextureUsage::RENDER_ATTACHMENT, @@ -192,6 +192,7 @@ impl framework::Example for Example { } } + #[allow(clippy::single_match)] fn update(&mut self, event: winit::event::WindowEvent) { match event { winit::event::WindowEvent::KeyboardInput { input, .. } => { diff --git a/wgpu/examples/shadow/main.rs b/wgpu/examples/shadow/main.rs index ac926d709..c0649e1f6 100644 --- a/wgpu/examples/shadow/main.rs +++ b/wgpu/examples/shadow/main.rs @@ -294,7 +294,7 @@ impl framework::Example for Example { use cgmath::{Decomposed, Deg, InnerSpace, Quaternion, Rotation3}; let transform = Decomposed { - disp: cube.offset.clone(), + disp: cube.offset, rot: Quaternion::from_axis_angle(cube.offset.normalize(), Deg(cube.angle)), scale: cube.scale, }; diff --git a/wgpu/examples/skybox/main.rs b/wgpu/examples/skybox/main.rs index fa3b90ee7..d2cf0f4bf 100644 --- a/wgpu/examples/skybox/main.rs +++ b/wgpu/examples/skybox/main.rs @@ -363,6 +363,7 @@ impl framework::Example for Skybox { } } + #[allow(clippy::single_match)] fn update(&mut self, event: winit::event::WindowEvent) { match event { winit::event::WindowEvent::CursorMoved { position, .. } => { @@ -443,7 +444,7 @@ impl framework::Example for Skybox { } rpass.set_pipeline(&self.sky_pipeline); - rpass.draw(0..3 as u32, 0..1); + rpass.draw(0..3, 0..1); } queue.submit(std::iter::once(encoder.finish())); diff --git a/wgpu/examples/water/main.rs b/wgpu/examples/water/main.rs index 5b21fdfa7..71666a924 100644 --- a/wgpu/examples/water/main.rs +++ b/wgpu/examples/water/main.rs @@ -662,6 +662,7 @@ impl framework::Example for Example { self.reflect_view = reflect_view; } + #[allow(clippy::eq_op)] fn render( &mut self, frame: &wgpu::SwapChainTexture, diff --git a/wgpu/examples/water/point_gen.rs b/wgpu/examples/water/point_gen.rs index f12b4b621..d14f99751 100644 --- a/wgpu/examples/water/point_gen.rs +++ b/wgpu/examples/water/point_gen.rs @@ -30,7 +30,7 @@ const S45: f32 = std::f32::consts::FRAC_1_SQRT_2; /// const C45: f32 = S45; -const SQRT_3: f32 = 1.73205080757; +const SQRT_3: f32 = 1.7320508; #[repr(C)] #[derive(Copy, Clone, Debug, PartialEq, Pod, Zeroable)] diff --git a/wgpu/src/backend/direct.rs b/wgpu/src/backend/direct.rs index 4fa5563d6..4178ca7f9 100644 --- a/wgpu/src/backend/direct.rs +++ b/wgpu/src/backend/direct.rs @@ -78,15 +78,12 @@ impl Context { let sink = sink_mutex.lock(); let mut source_opt: Option<&(dyn Error + 'static)> = Some(&error); while let Some(source) = source_opt { - if let Some(device_error) = source.downcast_ref::() { - match device_error { - wgc::device::DeviceError::OutOfMemory => { - return sink.handle_error(crate::Error::OutOfMemoryError { - source: Box::new(error), - }); - } - _ => {} - } + if let Some(wgc::device::DeviceError::OutOfMemory) = + source.downcast_ref::() + { + return sink.handle_error(crate::Error::OutOfMemoryError { + source: Box::new(error), + }); } source_opt = source.source(); } @@ -156,14 +153,14 @@ mod pass_impl { fn insert_debug_marker(&mut self, label: &str) { unsafe { let label = std::ffi::CString::new(label).unwrap(); - wgpu_compute_pass_insert_debug_marker(self, label.as_ptr().into(), 0); + wgpu_compute_pass_insert_debug_marker(self, label.as_ptr(), 0); } } fn push_debug_group(&mut self, group_label: &str) { unsafe { let label = std::ffi::CString::new(group_label).unwrap(); - wgpu_compute_pass_push_debug_group(self, label.as_ptr().into(), 0); + wgpu_compute_pass_push_debug_group(self, label.as_ptr(), 0); } } fn pop_debug_group(&mut self) { @@ -362,14 +359,14 @@ mod pass_impl { fn insert_debug_marker(&mut self, label: &str) { unsafe { let label = std::ffi::CString::new(label).unwrap(); - wgpu_render_pass_insert_debug_marker(self, label.as_ptr().into(), 0); + wgpu_render_pass_insert_debug_marker(self, label.as_ptr(), 0); } } fn push_debug_group(&mut self, group_label: &str) { unsafe { let label = std::ffi::CString::new(group_label).unwrap(); - wgpu_render_pass_push_debug_group(self, label.as_ptr().into(), 0); + wgpu_render_pass_push_debug_group(self, label.as_ptr(), 0); } } @@ -637,6 +634,7 @@ impl crate::Context for Context { type SwapChainOutputDetail = SwapChainOutputDetail; type RequestAdapterFuture = Ready>; + #[allow(clippy::type_complexity)] type RequestDeviceFuture = Ready>; type MapAsyncFuture = native_gpu_future::GpuFuture>; @@ -853,11 +851,8 @@ impl crate::Context for Context { { // gather all the array view IDs first for entry in desc.entries.iter() { - match entry.resource { - BindingResource::TextureViewArray(array) => { - arrayed_texture_views.extend(array.iter().map(|view| view.id)); - } - _ => {} + if let BindingResource::TextureViewArray(array) = entry.resource { + arrayed_texture_views.extend(array.iter().map(|view| view.id)); } } } @@ -1290,7 +1285,7 @@ impl crate::Context for Context { MapMode::Write => wgc::device::HostMap::Write, }, callback: buffer_map_future_wrapper, - user_data: completion.to_raw() as _, + user_data: completion.into_raw() as _, }; let global = &self.0; diff --git a/wgpu/src/backend/error.rs b/wgpu/src/backend/error.rs index 6aff00600..e02fa2170 100644 --- a/wgpu/src/backend/error.rs +++ b/wgpu/src/backend/error.rs @@ -163,12 +163,9 @@ impl PrettyError for wgc::binding_model::CreatePipelineLayoutError { fn fmt_pretty(&self, context: &super::Context) -> String { let global = context.global(); let mut ret = format_error_line(self); - match *self { - Self::InvalidBindGroupLayout(id) => { - let name = wgc::gfx_select!(id => global.bind_group_layout_label(id)); - ret.push_str(&format_label_line("bind group layout", &name)); - } - _ => {} + if let Self::InvalidBindGroupLayout(id) = *self { + let name = wgc::gfx_select!(id => global.bind_group_layout_label(id)); + ret.push_str(&format_label_line("bind group layout", &name)); }; ret } @@ -192,12 +189,9 @@ impl PrettyError for wgc::command::RenderPassErrorInner { fn fmt_pretty(&self, context: &super::Context) -> String { let global = context.global(); let mut ret = format_error_line(self); - match *self { - Self::InvalidAttachment(id) => { - let name = wgc::gfx_select!(id => global.texture_view_label(id)); - ret.push_str(&format_label_line("attachment", &name)); - } - _ => {} + if let Self::InvalidAttachment(id) = *self { + let name = wgc::gfx_select!(id => global.texture_view_label(id)); + ret.push_str(&format_label_line("attachment", &name)); }; ret } diff --git a/wgpu/src/backend/native_gpu_future.rs b/wgpu/src/backend/native_gpu_future.rs index 5c50c4966..a37b97538 100644 --- a/wgpu/src/backend/native_gpu_future.rs +++ b/wgpu/src/backend/native_gpu_future.rs @@ -55,7 +55,7 @@ impl GpuFutureCompletion { }; } - pub(crate) fn to_raw(self) -> *mut OpaqueData { + pub(crate) fn into_raw(self) -> *mut OpaqueData { Arc::into_raw(self.data) as _ } diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index c4badb49a..f0f036891 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -2853,7 +2853,7 @@ impl SwapChain { let output = view_id.map(|id| SwapChainTexture { view: TextureView { context: Arc::clone(&self.context), - id: id, + id, owned: false, }, detail, diff --git a/wgpu/src/util/device.rs b/wgpu/src/util/device.rs index 06775ee30..ca58b16e8 100644 --- a/wgpu/src/util/device.rs +++ b/wgpu/src/util/device.rs @@ -42,7 +42,8 @@ impl DeviceExt for crate::Device { // 2. buffer size must be greater than 0. // Therefore we round the value up to the nearest multiple, and ensure it's at least COPY_BUFFER_ALIGNMENT. let align_mask = crate::COPY_BUFFER_ALIGNMENT - 1; - let padded_size = ((unpadded_size + align_mask) & !align_mask).max(crate::COPY_BUFFER_ALIGNMENT); + let padded_size = + ((unpadded_size + align_mask) & !align_mask).max(crate::COPY_BUFFER_ALIGNMENT); let wgt_descriptor = crate::BufferDescriptor { label: descriptor.label, diff --git a/wgpu/src/util/mod.rs b/wgpu/src/util/mod.rs index 9f58ef99c..374a7efe3 100644 --- a/wgpu/src/util/mod.rs +++ b/wgpu/src/util/mod.rs @@ -24,7 +24,7 @@ pub use encoder::RenderEncoder; /// - Input length isn't multiple of 4 /// - Input is longer than [`usize::max_value`] /// - SPIR-V magic number is missing from beginning of stream -pub fn make_spirv<'a>(data: &'a [u8]) -> super::ShaderSource<'a> { +pub fn make_spirv(data: &[u8]) -> super::ShaderSource { const MAGIC_NUMBER: u32 = 0x0723_0203; assert_eq!(