From ddf5cb19ce972c4963e84f84e50fedd65d4c4f07 Mon Sep 17 00:00:00 2001 From: MichiRecRoom <1008889+LikeLakers2@users.noreply.github.com> Date: Fri, 10 Jan 2025 06:50:59 -0500 Subject: [PATCH 1/5] Apply `#![deny(clippy::allow_attributes, clippy::allow_attributes_without_reason)]` to bevy_pbr --- crates/bevy_pbr/src/extended_material.rs | 8 ++++---- crates/bevy_pbr/src/lib.rs | 7 ++++++- crates/bevy_pbr/src/light_probe/mod.rs | 1 - crates/bevy_pbr/src/material.rs | 8 ++++---- crates/bevy_pbr/src/ssao/mod.rs | 5 ++++- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/crates/bevy_pbr/src/extended_material.rs b/crates/bevy_pbr/src/extended_material.rs index 1b2d48e4c69f9..87094fc147736 100644 --- a/crates/bevy_pbr/src/extended_material.rs +++ b/crates/bevy_pbr/src/extended_material.rs @@ -37,7 +37,6 @@ pub trait MaterialExtension: Asset + AsBindGroup + Clone + Sized { /// Returns this material's fragment shader. If [`ShaderRef::Default`] is returned, the base material mesh fragment shader /// will be used. - #[allow(unused_variables)] fn fragment_shader() -> ShaderRef { ShaderRef::Default } @@ -50,7 +49,6 @@ pub trait MaterialExtension: Asset + AsBindGroup + Clone + Sized { /// Returns this material's prepass fragment shader. If [`ShaderRef::Default`] is returned, the base material prepass fragment shader /// will be used. - #[allow(unused_variables)] fn prepass_fragment_shader() -> ShaderRef { ShaderRef::Default } @@ -63,7 +61,6 @@ pub trait MaterialExtension: Asset + AsBindGroup + Clone + Sized { /// Returns this material's prepass fragment shader. If [`ShaderRef::Default`] is returned, the base material deferred fragment shader /// will be used. - #[allow(unused_variables)] fn deferred_fragment_shader() -> ShaderRef { ShaderRef::Default } @@ -95,7 +92,10 @@ pub trait MaterialExtension: Asset + AsBindGroup + Clone + Sized { /// Customizes the default [`RenderPipelineDescriptor`] for a specific entity using the entity's /// [`MaterialPipelineKey`] and [`MeshVertexBufferLayoutRef`] as input. /// Specialization for the base material is applied before this function is called. - #[allow(unused_variables)] + #[expect( + unused_variables, + reason = "The parameters here are intentionally unused by the default implementation; however, putting underscores here will result in the underscores being copied by rust-analyzer's tab completion." + )] #[inline] fn specialize( pipeline: &MaterialExtensionPipeline, diff --git a/crates/bevy_pbr/src/lib.rs b/crates/bevy_pbr/src/lib.rs index 15f8795ffbac4..ec67b70c8b501 100644 --- a/crates/bevy_pbr/src/lib.rs +++ b/crates/bevy_pbr/src/lib.rs @@ -1,6 +1,11 @@ #![expect(missing_docs, reason = "Not all docs are written yet, see #3492.")] #![cfg_attr(docsrs, feature(doc_auto_cfg))] -#![deny(unsafe_code)] +#![forbid(unsafe_code)] +#![deny( + clippy::allow_attributes, + clippy::allow_attributes_without_reason, + reason = "See #17111; To be removed once all crates are in-line with these attributes" +)] #![doc( html_logo_url = "https://bevyengine.org/assets/icon.png", html_favicon_url = "https://bevyengine.org/assets/icon.png" diff --git a/crates/bevy_pbr/src/light_probe/mod.rs b/crates/bevy_pbr/src/light_probe/mod.rs index 4961983ecd383..75bf47b5ce61a 100644 --- a/crates/bevy_pbr/src/light_probe/mod.rs +++ b/crates/bevy_pbr/src/light_probe/mod.rs @@ -185,7 +185,6 @@ pub struct ViewLightProbesUniformOffset(u32); /// This information is parameterized by the [`LightProbeComponent`] type. This /// will either be [`EnvironmentMapLight`] for reflection probes or /// [`IrradianceVolume`] for irradiance volumes. -#[allow(dead_code)] struct LightProbeInfo where C: LightProbeComponent, diff --git a/crates/bevy_pbr/src/material.rs b/crates/bevy_pbr/src/material.rs index 362b4b6d31020..4882d1b5fd149 100644 --- a/crates/bevy_pbr/src/material.rs +++ b/crates/bevy_pbr/src/material.rs @@ -124,7 +124,6 @@ pub trait Material: Asset + AsBindGroup + Clone + Sized { /// Returns this material's fragment shader. If [`ShaderRef::Default`] is returned, the default mesh fragment shader /// will be used. - #[allow(unused_variables)] fn fragment_shader() -> ShaderRef { ShaderRef::Default } @@ -174,7 +173,6 @@ pub trait Material: Asset + AsBindGroup + Clone + Sized { /// /// This is used for the various [prepasses](bevy_core_pipeline::prepass) as well as for generating the depth maps /// required for shadow mapping. - #[allow(unused_variables)] fn prepass_fragment_shader() -> ShaderRef { ShaderRef::Default } @@ -187,7 +185,6 @@ pub trait Material: Asset + AsBindGroup + Clone + Sized { /// Returns this material's deferred fragment shader. If [`ShaderRef::Default`] is returned, the default deferred fragment shader /// will be used. - #[allow(unused_variables)] fn deferred_fragment_shader() -> ShaderRef { ShaderRef::Default } @@ -230,7 +227,10 @@ pub trait Material: Asset + AsBindGroup + Clone + Sized { /// Customizes the default [`RenderPipelineDescriptor`] for a specific entity using the entity's /// [`MaterialPipelineKey`] and [`MeshVertexBufferLayoutRef`] as input. - #[allow(unused_variables)] + #[expect( + unused_variables, + reason = "The parameters here are intentionally unused by the default implementation; however, putting underscores here will result in the underscores being copied by rust-analyzer's tab completion." + )] #[inline] fn specialize( pipeline: &MaterialPipeline, diff --git a/crates/bevy_pbr/src/ssao/mod.rs b/crates/bevy_pbr/src/ssao/mod.rs index d2271b9b38b67..5dbd85e68d6b2 100644 --- a/crates/bevy_pbr/src/ssao/mod.rs +++ b/crates/bevy_pbr/src/ssao/mod.rs @@ -752,10 +752,13 @@ fn prepare_ssao_bind_groups( } } -#[allow(clippy::needless_range_loop)] fn generate_hilbert_index_lut() -> [[u16; 64]; 64] { let mut t = [[0; 64]; 64]; + #[expect( + clippy::needless_range_loop, + reason = "Rewriting this loop to use iterators would make the code much harder to read for very little performance gain." + )] for x in 0..64 { for y in 0..64 { t[x][y] = hilbert_index(x as u16, y as u16); From 311393ea67f829dddfe9595c334974580dff1899 Mon Sep 17 00:00:00 2001 From: MichiRecRoom <1008889+LikeLakers2@users.noreply.github.com> Date: Fri, 10 Jan 2025 07:02:28 -0500 Subject: [PATCH 2/5] Appease CI. --- crates/bevy_pbr/src/extended_material.rs | 3 --- crates/bevy_pbr/src/material.rs | 3 --- 2 files changed, 6 deletions(-) diff --git a/crates/bevy_pbr/src/extended_material.rs b/crates/bevy_pbr/src/extended_material.rs index 87094fc147736..35cb1129d26fb 100644 --- a/crates/bevy_pbr/src/extended_material.rs +++ b/crates/bevy_pbr/src/extended_material.rs @@ -67,7 +67,6 @@ pub trait MaterialExtension: Asset + AsBindGroup + Clone + Sized { /// Returns this material's [`crate::meshlet::MeshletMesh`] fragment shader. If [`ShaderRef::Default`] is returned, /// the default meshlet mesh fragment shader will be used. - #[allow(unused_variables)] #[cfg(feature = "meshlet")] fn meshlet_mesh_fragment_shader() -> ShaderRef { ShaderRef::Default @@ -75,7 +74,6 @@ pub trait MaterialExtension: Asset + AsBindGroup + Clone + Sized { /// Returns this material's [`crate::meshlet::MeshletMesh`] prepass fragment shader. If [`ShaderRef::Default`] is returned, /// the default meshlet mesh prepass fragment shader will be used. - #[allow(unused_variables)] #[cfg(feature = "meshlet")] fn meshlet_mesh_prepass_fragment_shader() -> ShaderRef { ShaderRef::Default @@ -83,7 +81,6 @@ pub trait MaterialExtension: Asset + AsBindGroup + Clone + Sized { /// Returns this material's [`crate::meshlet::MeshletMesh`] deferred fragment shader. If [`ShaderRef::Default`] is returned, /// the default meshlet mesh deferred fragment shader will be used. - #[allow(unused_variables)] #[cfg(feature = "meshlet")] fn meshlet_mesh_deferred_fragment_shader() -> ShaderRef { ShaderRef::Default diff --git a/crates/bevy_pbr/src/material.rs b/crates/bevy_pbr/src/material.rs index 4882d1b5fd149..5324d77d1fc3d 100644 --- a/crates/bevy_pbr/src/material.rs +++ b/crates/bevy_pbr/src/material.rs @@ -195,7 +195,6 @@ pub trait Material: Asset + AsBindGroup + Clone + Sized { /// This is part of an experimental feature, and is unnecessary to implement unless you are using `MeshletMesh`'s. /// /// See [`crate::meshlet::MeshletMesh`] for limitations. - #[allow(unused_variables)] #[cfg(feature = "meshlet")] fn meshlet_mesh_fragment_shader() -> ShaderRef { ShaderRef::Default @@ -207,7 +206,6 @@ pub trait Material: Asset + AsBindGroup + Clone + Sized { /// This is part of an experimental feature, and is unnecessary to implement unless you are using `MeshletMesh`'s. /// /// See [`crate::meshlet::MeshletMesh`] for limitations. - #[allow(unused_variables)] #[cfg(feature = "meshlet")] fn meshlet_mesh_prepass_fragment_shader() -> ShaderRef { ShaderRef::Default @@ -219,7 +217,6 @@ pub trait Material: Asset + AsBindGroup + Clone + Sized { /// This is part of an experimental feature, and is unnecessary to implement unless you are using `MeshletMesh`'s. /// /// See [`crate::meshlet::MeshletMesh`] for limitations. - #[allow(unused_variables)] #[cfg(feature = "meshlet")] fn meshlet_mesh_deferred_fragment_shader() -> ShaderRef { ShaderRef::Default From 4cdbca42b17113a2a78daf8d07d73686709e942f Mon Sep 17 00:00:00 2001 From: MichiRecRoom <1008889+LikeLakers2@users.noreply.github.com> Date: Fri, 10 Jan 2025 11:56:37 -0500 Subject: [PATCH 3/5] Implement usage of `core::array::from_fn` into `generate_hilbert_index_lut()`, per suggestion from Benjamin --- crates/bevy_pbr/src/ssao/mod.rs | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/crates/bevy_pbr/src/ssao/mod.rs b/crates/bevy_pbr/src/ssao/mod.rs index 5dbd85e68d6b2..96c88702312e9 100644 --- a/crates/bevy_pbr/src/ssao/mod.rs +++ b/crates/bevy_pbr/src/ssao/mod.rs @@ -753,19 +753,8 @@ fn prepare_ssao_bind_groups( } fn generate_hilbert_index_lut() -> [[u16; 64]; 64] { - let mut t = [[0; 64]; 64]; - - #[expect( - clippy::needless_range_loop, - reason = "Rewriting this loop to use iterators would make the code much harder to read for very little performance gain." - )] - for x in 0..64 { - for y in 0..64 { - t[x][y] = hilbert_index(x as u16, y as u16); - } - } - - t + use core::array::from_fn; + from_fn(|x| from_fn(|y| hilbert_index(x as u16, y as u16))) } // https://www.shadertoy.com/view/3tB3z3 From 53c979d7202362c1c21307661102bafff600768e Mon Sep 17 00:00:00 2001 From: MichiRecRoom <1008889+LikeLakers2@users.noreply.github.com> Date: Fri, 10 Jan 2025 13:22:15 -0500 Subject: [PATCH 4/5] Reimplement the function using `.iter_mut()`, as some seem to find for-loops easier to understand than `core::array::from_fn` --- crates/bevy_pbr/src/ssao/mod.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/crates/bevy_pbr/src/ssao/mod.rs b/crates/bevy_pbr/src/ssao/mod.rs index 96c88702312e9..17d32572a16a8 100644 --- a/crates/bevy_pbr/src/ssao/mod.rs +++ b/crates/bevy_pbr/src/ssao/mod.rs @@ -753,8 +753,15 @@ fn prepare_ssao_bind_groups( } fn generate_hilbert_index_lut() -> [[u16; 64]; 64] { - use core::array::from_fn; - from_fn(|x| from_fn(|y| hilbert_index(x as u16, y as u16))) + let mut t = [[0; 64]; 64]; + + for (x, array) in t.iter_mut().enumerate() { + for (y, item) in array.iter_mut().enumerate() { + *item = hilbert_index(x as u16, y as u16); + } + } + + t } // https://www.shadertoy.com/view/3tB3z3 From 076fb68b60bafa5add3d5ee6701557c9e6c7fe91 Mon Sep 17 00:00:00 2001 From: MichiRecRoom <1008889+LikeLakers2@users.noreply.github.com> Date: Fri, 10 Jan 2025 13:49:36 -0500 Subject: [PATCH 5/5] Revert "Reimplement the function using `.iter_mut()`, as some seem to find for-loops easier to understand than `core::array::from_fn`" This reverts commit 53c979d7202362c1c21307661102bafff600768e. --- crates/bevy_pbr/src/ssao/mod.rs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/crates/bevy_pbr/src/ssao/mod.rs b/crates/bevy_pbr/src/ssao/mod.rs index 17d32572a16a8..96c88702312e9 100644 --- a/crates/bevy_pbr/src/ssao/mod.rs +++ b/crates/bevy_pbr/src/ssao/mod.rs @@ -753,15 +753,8 @@ fn prepare_ssao_bind_groups( } fn generate_hilbert_index_lut() -> [[u16; 64]; 64] { - let mut t = [[0; 64]; 64]; - - for (x, array) in t.iter_mut().enumerate() { - for (y, item) in array.iter_mut().enumerate() { - *item = hilbert_index(x as u16, y as u16); - } - } - - t + use core::array::from_fn; + from_fn(|x| from_fn(|y| hilbert_index(x as u16, y as u16))) } // https://www.shadertoy.com/view/3tB3z3