Skip to content

Commit

Permalink
bevy_ui: Apply `#![deny(clippy::allow_attributes, clippy::allow_attri…
Browse files Browse the repository at this point in the history
…butes_without_reason)]` (#17229)

# Objective
- #17111

## Solution
Set the `clippy::allow_attributes` and
`clippy::allow_attributes_without_reason` lints to `deny`, and bring
`bevy_ui` in line with the new restrictions.

## Testing
`cargo clippy --tests` and `cargo test --package bevy_ui` were run, and
no errors were encountered.
  • Loading branch information
LikeLakers2 authored Jan 8, 2025
1 parent 5f0674f commit 8b4c25a
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 26 deletions.
5 changes: 4 additions & 1 deletion crates/bevy_ui/src/focus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ pub struct NodeQuery {
/// The system that sets Interaction for all UI elements based on the mouse cursor activity
///
/// Entities with a hidden [`ViewVisibility`] are always treated as released.
#[allow(clippy::too_many_arguments)]
#[expect(
clippy::too_many_arguments,
reason = "Could be rewritten with less arguments using a QueryData-implementing struct, but doesn't need to be."
)]
pub fn ui_focus_system(
mut state: Local<State>,
camera_query: Query<(Entity, &Camera)>,
Expand Down
5 changes: 4 additions & 1 deletion crates/bevy_ui/src/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ struct CameraLayoutInfo {
}

/// Updates the UI's layout tree, computes the new layout geometry and then updates the sizes and transforms of all the UI nodes.
#[allow(clippy::too_many_arguments)]
#[expect(
clippy::too_many_arguments,
reason = "Could be rewritten with less arguments using a QueryData-implementing struct, but doesn't need to be."
)]
pub fn ui_layout_system(
mut commands: Commands,
mut buffers: Local<UiLayoutSystemBuffers>,
Expand Down
15 changes: 12 additions & 3 deletions crates/bevy_ui/src/layout/ui_surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,10 @@ mod tests {
);
}

#[allow(unreachable_code)]
#[expect(
unreachable_code,
reason = "Certain pieces of code tested here cause the test to fail if made reachable; see #16362 for progress on fixing this"
)]
#[test]
fn test_remove_camera_entities() {
let mut ui_surface = UiSurface::default();
Expand Down Expand Up @@ -512,7 +515,10 @@ mod tests {
assert_eq!(root_node_pair, None);
}

#[allow(unreachable_code)]
#[expect(
unreachable_code,
reason = "Certain pieces of code tested here cause the test to fail if made reachable; see #16362 for progress on fixing this"
)]
#[test]
fn test_remove_entities() {
let mut ui_surface = UiSurface::default();
Expand Down Expand Up @@ -592,7 +598,10 @@ mod tests {
assert_eq!(ui_surface.taffy.parent(child_node), Some(parent_node));
}

#[allow(unreachable_code)]
#[expect(
unreachable_code,
reason = "Certain pieces of code tested here cause the test to fail if made reachable; see #16362 for progress on fixing this"
)]
#[test]
fn test_set_camera_children() {
let mut ui_surface = UiSurface::default();
Expand Down
5 changes: 5 additions & 0 deletions crates/bevy_ui/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#![expect(missing_docs, reason = "Not all docs are written yet, see #3492.")]
#![deny(
clippy::allow_attributes,
clippy::allow_attributes_without_reason,
reason = "See #17111; To be removed once all crates are in-line with these attributes"
)]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![doc(
html_logo_url = "https://bevyengine.org/assets/icon.png",
Expand Down
2 changes: 0 additions & 2 deletions crates/bevy_ui/src/picking_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
//! camera.
//! - To correctly sort picks, the order of `bevy_ui` is set to be the camera order plus 0.5.
#![allow(clippy::type_complexity)]
#![allow(clippy::too_many_arguments)]
#![deny(missing_docs)]

use crate::{focus::pick_rounded_rect, prelude::*, UiStack};
Expand Down
5 changes: 4 additions & 1 deletion crates/bevy_ui/src/render/box_shadow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,10 @@ pub fn queue_shadows(
}
}

#[allow(clippy::too_many_arguments)]
#[expect(
clippy::too_many_arguments,
reason = "Could be rewritten with less arguments using a QueryData-implementing struct, but doesn't need to be."
)]
pub fn prepare_shadows(
mut commands: Commands,
render_device: Res<RenderDevice>,
Expand Down
1 change: 0 additions & 1 deletion crates/bevy_ui/src/render/debug_overlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ impl Default for UiDebugOptions {
}
}

#[allow(clippy::too_many_arguments)]
pub fn extract_debug_overlay(
mut commands: Commands,
debug_options: Extract<Res<UiDebugOptions>>,
Expand Down
9 changes: 4 additions & 5 deletions crates/bevy_ui/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ impl ExtractedUiNodes {
}
}

#[allow(clippy::too_many_arguments)]
pub fn extract_uinode_background_colors(
mut commands: Commands,
mut extracted_uinodes: ResMut<ExtractedUiNodes>,
Expand Down Expand Up @@ -310,7 +309,6 @@ pub fn extract_uinode_background_colors(
}
}

#[allow(clippy::too_many_arguments)]
pub fn extract_uinode_images(
mut commands: Commands,
mut extracted_uinodes: ResMut<ExtractedUiNodes>,
Expand Down Expand Up @@ -613,7 +611,6 @@ pub fn extract_ui_camera_view(
transparent_render_phases.retain(|entity, _| live_entities.contains(entity));
}

#[allow(clippy::too_many_arguments)]
pub fn extract_text_sections(
mut commands: Commands,
mut extracted_uinodes: ResMut<ExtractedUiNodes>,
Expand Down Expand Up @@ -790,7 +787,6 @@ pub mod shader_flags {
pub const BORDER: u32 = 8;
}

#[allow(clippy::too_many_arguments)]
pub fn queue_uinodes(
extracted_uinodes: Res<ExtractedUiNodes>,
ui_pipeline: Res<UiPipeline>,
Expand Down Expand Up @@ -839,7 +835,10 @@ pub struct ImageNodeBindGroups {
pub values: HashMap<AssetId<Image>, BindGroup>,
}

#[allow(clippy::too_many_arguments)]
#[expect(
clippy::too_many_arguments,
reason = "Could be rewritten with less arguments using a QueryData-implementing struct, but doesn't need to be."
)]
pub fn prepare_uinodes(
mut commands: Commands,
render_device: Res<RenderDevice>,
Expand Down
10 changes: 8 additions & 2 deletions crates/bevy_ui/src/render/ui_material_pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,10 @@ pub fn extract_ui_material_nodes<M: UiMaterial>(
}
}

#[allow(clippy::too_many_arguments)]
#[expect(
clippy::too_many_arguments,
reason = "Could be rewritten with less arguments using a QueryData-implementing struct, but doesn't need to be."
)]
pub fn prepare_uimaterial_nodes<M: UiMaterial>(
mut commands: Commands,
render_device: Res<RenderDevice>,
Expand Down Expand Up @@ -605,7 +608,10 @@ impl<M: UiMaterial> RenderAsset for PreparedUiMaterial<M> {
}
}

#[allow(clippy::too_many_arguments)]
#[expect(
clippy::too_many_arguments,
reason = "Could be rewritten with less arguments using a QueryData-implementing struct, but doesn't need to be."
)]
pub fn queue_ui_material_nodes<M: UiMaterial>(
extracted_uinodes: Res<ExtractedUiMaterialNodes<M>>,
draw_functions: Res<DrawFunctions<TransparentUi>>,
Expand Down
5 changes: 4 additions & 1 deletion crates/bevy_ui/src/render/ui_texture_slice_pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,10 @@ pub fn queue_ui_slices(
}
}

#[allow(clippy::too_many_arguments)]
#[expect(
clippy::too_many_arguments,
reason = "Could be rewritten with less arguments using a QueryData-implementing struct, but doesn't need to be."
)]
pub fn prepare_ui_slices(
mut commands: Commands,
render_device: Res<RenderDevice>,
Expand Down
5 changes: 4 additions & 1 deletion crates/bevy_ui/src/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ impl ChildBufferCache {
/// Create a list of root nodes from parentless entities and entities with a `GlobalZIndex` component.
/// Then build the `UiStack` from a walk of the existing layout trees starting from each root node,
/// filtering branches by `Without<GlobalZIndex>`so that we don't revisit nodes.
#[allow(clippy::too_many_arguments)]
#[expect(
clippy::too_many_arguments,
reason = "Could be rewritten with less arguments using a QueryData-implementing struct, but doesn't need to be."
)]
pub fn ui_stack_system(
mut cache: Local<ChildBufferCache>,
mut root_nodes: Local<Vec<(Entity, (i32, i32))>>,
Expand Down
5 changes: 4 additions & 1 deletion crates/bevy_ui/src/ui_material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ pub trait UiMaterial: AsBindGroup + Asset + Clone + Sized {
ShaderRef::Default
}

#[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(descriptor: &mut RenderPipelineDescriptor, key: UiMaterialKey<Self>) {}
}
Expand Down
4 changes: 1 addition & 3 deletions crates/bevy_ui/src/ui_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1812,11 +1812,9 @@ pub struct GridPlacement {
}

impl GridPlacement {
#[allow(unsafe_code)]
pub const DEFAULT: Self = Self {
start: None,
// SAFETY: This is trivially safe as 1 is non-zero.
span: Some(unsafe { NonZero::<u16>::new_unchecked(1) }),
span: NonZero::<u16>::new(1),
end: None,
};

Expand Down
20 changes: 16 additions & 4 deletions crates/bevy_ui/src/widget/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,10 @@ impl Measure for TextMeasure {
}
}

#[allow(clippy::too_many_arguments)]
#[expect(
clippy::too_many_arguments,
reason = "Could be rewritten with less arguments using a QueryData-implementing struct, but doesn't need to be."
)]
#[inline]
fn create_text_measure<'a>(
entity: Entity,
Expand Down Expand Up @@ -242,7 +245,10 @@ fn create_text_measure<'a>(
/// is only able to detect that a `Text` component has changed and will regenerate the `Measure` on
/// color changes. This can be expensive, particularly for large blocks of text, and the [`bypass_change_detection`](bevy_ecs::change_detection::DetectChangesMut::bypass_change_detection)
/// method should be called when only changing the `Text`'s colors.
#[allow(clippy::too_many_arguments)]
#[expect(
clippy::too_many_arguments,
reason = "Could be rewritten with less arguments using a QueryData-implementing struct, but doesn't need to be."
)]
pub fn measure_text_system(
mut scale_factors_buffer: Local<EntityHashMap<f32>>,
mut last_scale_factors: Local<EntityHashMap<f32>>,
Expand Down Expand Up @@ -310,7 +316,10 @@ pub fn measure_text_system(
core::mem::swap(&mut *last_scale_factors, &mut *scale_factors_buffer);
}

#[allow(clippy::too_many_arguments)]
#[expect(
clippy::too_many_arguments,
reason = "Could be rewritten with less arguments using a QueryData-implementing struct, but doesn't need to be."
)]
#[inline]
fn queue_text(
entity: Entity,
Expand Down Expand Up @@ -382,7 +391,10 @@ fn queue_text(
///
/// [`ResMut<Assets<Image>>`](Assets<Image>) -- This system only adds new [`Image`] assets.
/// It does not modify or observe existing ones. The exception is when adding new glyphs to a [`bevy_text::FontAtlas`].
#[allow(clippy::too_many_arguments)]
#[expect(
clippy::too_many_arguments,
reason = "Could be rewritten with less arguments using a QueryData-implementing struct, but doesn't need to be."
)]
pub fn text_system(
mut textures: ResMut<Assets<Image>>,
fonts: Res<Assets<Font>>,
Expand Down

0 comments on commit 8b4c25a

Please sign in to comment.