bevy_ui: Apply #![deny(clippy::allow_attributes, clippy::allow_attributes_without_reason)] (#17229)

# Objective
- https://github.com/bevyengine/bevy/issues/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.
This commit is contained in:
MichiRecRoom 2025-01-08 14:30:19 -05:00 committed by GitHub
parent 5f0674f6c3
commit 8b4c25ad5f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 70 additions and 26 deletions

View File

@ -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)>,

View File

@ -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>,

View File

@ -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();
@ -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();
@ -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();

View File

@ -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",

View File

@ -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};

View File

@ -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>,

View File

@ -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>>,

View File

@ -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>,
@ -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>,
@ -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>,
@ -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>,
@ -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>,

View File

@ -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>,
@ -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>>,

View File

@ -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>,

View File

@ -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))>>,

View File

@ -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>) {}
}

View File

@ -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,
};

View File

@ -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,
@ -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>>,
@ -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,
@ -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>>,