Skip to content

Commit 27802e6

Browse files
authored
bevy_render: Apply #![deny(clippy::allow_attributes, clippy::allow_attributes_without_reason)] (#17194)
# Objective - #17111 ## Solution Set the `clippy::allow_attributes` and `clippy::allow_attributes_without_reason` lints to `deny`, and bring `bevy_render` in line with the new restrictions. ## Testing `cargo clippy` and `cargo test --package bevy_render` were run, and no errors were encountered.
1 parent 6f68776 commit 27802e6

File tree

12 files changed

+59
-18
lines changed

12 files changed

+59
-18
lines changed

crates/bevy_render/src/camera/camera.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#![expect(
2+
clippy::module_inception,
3+
reason = "The parent module contains all things viewport-related, while this module handles cameras as a component. However, a rename/refactor which should clear up this lint is being discussed; see #17196."
4+
)]
15
use super::{ClearColorConfig, Projection};
26
use crate::{
37
batching::gpu_preprocessing::{GpuPreprocessingMode, GpuPreprocessingSupport},
@@ -893,7 +897,10 @@ impl NormalizedRenderTarget {
893897
///
894898
/// [`OrthographicProjection`]: crate::camera::OrthographicProjection
895899
/// [`PerspectiveProjection`]: crate::camera::PerspectiveProjection
896-
#[allow(clippy::too_many_arguments)]
900+
#[expect(
901+
clippy::too_many_arguments,
902+
reason = "Could be rewritten with less arguments using a QueryData-implementing struct, but doesn't need to be."
903+
)]
897904
pub fn camera_system(
898905
mut window_resized_events: EventReader<WindowResized>,
899906
mut window_created_events: EventReader<WindowCreated>,

crates/bevy_render/src/camera/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#[allow(clippy::module_inception)]
21
mod camera;
32
mod camera_driver_node;
43
mod clear_color;

crates/bevy_render/src/diagnostic/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ use super::{RenderDevice, RenderQueue};
4343
/// # Supported platforms
4444
/// Timestamp queries and pipeline statistics are currently supported only on Vulkan and DX12.
4545
/// On other platforms (Metal, WebGPU, WebGL2) only CPU time will be recorded.
46-
#[allow(clippy::doc_markdown)]
4746
#[derive(Default)]
4847
pub struct RenderDiagnosticsPlugin;
4948

crates/bevy_render/src/lib.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#![expect(missing_docs, reason = "Not all docs are written yet, see #3492.")]
2-
#![expect(unsafe_code)]
2+
#![expect(unsafe_code, reason = "Unsafe code is used to improve performance.")]
3+
#![deny(
4+
clippy::allow_attributes,
5+
clippy::allow_attributes_without_reason,
6+
reason = "See #17111; To be removed once all crates are in-line with these attributes"
7+
)]
38
#![cfg_attr(
49
any(docsrs, docsrs_dep),
510
expect(

crates/bevy_render/src/mesh/allocator.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ pub struct MeshBufferSlice<'a> {
156156
pub struct SlabId(pub NonMaxU32);
157157

158158
/// Data for a single slab.
159-
#[allow(clippy::large_enum_variant)]
160159
enum Slab {
161160
/// A slab that can contain multiple objects.
162161
General(GeneralSlab),
@@ -527,7 +526,10 @@ impl MeshAllocator {
527526
}
528527

529528
/// A generic function that copies either vertex or index data into a slab.
530-
#[allow(clippy::too_many_arguments)]
529+
#[expect(
530+
clippy::too_many_arguments,
531+
reason = "Could be rewritten with less arguments using a QueryData-implementing struct, but doesn't need to be."
532+
)]
531533
fn copy_element_data(
532534
&mut self,
533535
mesh_id: &AssetId<Mesh>,

crates/bevy_render/src/render_asset.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ pub trait RenderAsset: Send + Sync + 'static + Sized {
5353
/// Size of the data the asset will upload to the gpu. Specifying a return value
5454
/// will allow the asset to be throttled via [`RenderAssetBytesPerFrame`].
5555
#[inline]
56-
#[allow(unused_variables)]
56+
#[expect(
57+
unused_variables,
58+
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."
59+
)]
5760
fn byte_len(source_asset: &Self::SourceAsset) -> Option<usize> {
5861
None
5962
}
@@ -235,7 +238,10 @@ pub(crate) fn extract_render_asset<A: RenderAsset>(
235238
let mut removed = <HashSet<_>>::default();
236239

237240
for event in events.read() {
238-
#[allow(clippy::match_same_arms)]
241+
#[expect(
242+
clippy::match_same_arms,
243+
reason = "LoadedWithDependencies is marked as a TODO, so it's likely this will no longer lint soon."
244+
)]
239245
match event {
240246
AssetEvent::Added { id } | AssetEvent::Modified { id } => {
241247
changed_assets.insert(*id);

crates/bevy_render/src/render_phase/draw.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ pub trait Draw<P: PhaseItem>: Send + Sync + 'static {
2222
/// Prepares the draw function to be used. This is called once and only once before the phase
2323
/// begins. There may be zero or more [`draw`](Draw::draw) calls following a call to this function.
2424
/// Implementing this is optional.
25-
#[allow(unused_variables)]
25+
#[expect(
26+
unused_variables,
27+
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."
28+
)]
2629
fn prepare(&mut self, world: &'_ World) {}
2730

2831
/// Draws a [`PhaseItem`] by issuing zero or more `draw` calls via the [`TrackedRenderPass`].
@@ -232,7 +235,14 @@ macro_rules! render_command_tuple_impl {
232235
type ViewQuery = ($($name::ViewQuery,)*);
233236
type ItemQuery = ($($name::ItemQuery,)*);
234237

235-
#[allow(non_snake_case)]
238+
#[expect(
239+
clippy::allow_attributes,
240+
reason = "We are in a macro; as such, `non_snake_case` may not always lint."
241+
)]
242+
#[allow(
243+
non_snake_case,
244+
reason = "Parameter and variable names are provided by the macro invocation, not by us."
245+
)]
236246
fn render<'w>(
237247
_item: &P,
238248
($($view,)*): ROQueryItem<'w, Self::ViewQuery>,

crates/bevy_render/src/render_resource/pipeline_cache.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ impl ShaderCache {
210210
Ok(())
211211
}
212212

213-
#[allow(clippy::result_large_err)]
214213
fn get(
215214
&mut self,
216215
render_device: &RenderDevice,
@@ -917,7 +916,10 @@ impl PipelineCache {
917916
mut events: Extract<EventReader<AssetEvent<Shader>>>,
918917
) {
919918
for event in events.read() {
920-
#[allow(clippy::match_same_arms)]
919+
#[expect(
920+
clippy::match_same_arms,
921+
reason = "LoadedWithDependencies is marked as a TODO, so it's likely this will no longer lint soon."
922+
)]
921923
match event {
922924
// PERF: Instead of blocking waiting for the shader cache lock, try again next frame if the lock is currently held
923925
AssetEvent::Added { id } | AssetEvent::Modified { id } => {

crates/bevy_render/src/render_resource/resource_macros.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ macro_rules! define_atomic_id {
44
#[derive(Copy, Clone, Hash, Eq, PartialEq, PartialOrd, Ord, Debug)]
55
pub struct $atomic_id_type(core::num::NonZero<u32>);
66

7-
// We use new instead of default to indicate that each ID created will be unique.
8-
#[allow(clippy::new_without_default)]
97
impl $atomic_id_type {
8+
#[expect(
9+
clippy::new_without_default,
10+
reason = "Implementing the `Default` trait on atomic IDs would imply that two `<AtomicIdType>::default()` equal each other. By only implementing `new()`, we indicate that each atomic ID created will be unique."
11+
)]
1012
pub fn new() -> Self {
1113
use core::sync::atomic::{AtomicU32, Ordering};
1214

crates/bevy_render/src/settings.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,11 @@ impl Default for WgpuSettings {
8686
{
8787
wgpu::Limits::downlevel_webgl2_defaults()
8888
} else {
89-
#[allow(unused_mut)]
89+
#[expect(clippy::allow_attributes, reason = "`unused_mut` is not always linted")]
90+
#[allow(
91+
unused_mut,
92+
reason = "This variable needs to be mutable if the `ci_limits` feature is enabled"
93+
)]
9094
let mut limits = wgpu::Limits::default();
9195
#[cfg(feature = "ci_limits")]
9296
{

crates/bevy_render/src/view/window/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ impl WindowSurfaces {
213213
/// another alternative is to try to use [`ANGLE`](https://github.com/gfx-rs/wgpu#angle) and
214214
/// [`Backends::GL`](crate::settings::Backends::GL) if your GPU/drivers support `OpenGL 4.3` / `OpenGL ES 3.0` or
215215
/// later.
216-
#[allow(clippy::too_many_arguments)]
217216
pub fn prepare_windows(
218217
mut windows: ResMut<ExtractedWindows>,
219218
mut window_surfaces: ResMut<WindowSurfaces>,

crates/bevy_render/src/view/window/screenshot.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,10 @@ fn extract_screenshots(
251251
system_state.apply(&mut main_world);
252252
}
253253

254-
#[allow(clippy::too_many_arguments)]
254+
#[expect(
255+
clippy::too_many_arguments,
256+
reason = "Could be rewritten with less arguments using a QueryData-implementing struct, but doesn't need to be."
257+
)]
255258
fn prepare_screenshots(
256259
targets: Res<RenderScreenshotTargets>,
257260
mut prepared: ResMut<RenderScreenshotsPrepared>,
@@ -576,7 +579,10 @@ pub(crate) fn submit_screenshot_commands(world: &World, encoder: &mut CommandEnc
576579
}
577580
}
578581

579-
#[allow(clippy::too_many_arguments)]
582+
#[expect(
583+
clippy::too_many_arguments,
584+
reason = "Could be rewritten with less arguments using a QueryData-implementing struct, but doesn't need to be."
585+
)]
580586
fn render_screenshot(
581587
encoder: &mut CommandEncoder,
582588
prepared: &RenderScreenshotsPrepared,

0 commit comments

Comments
 (0)