From aa2ebbb43f388f2d300b5e72deac1012abbc9cd7 Mon Sep 17 00:00:00 2001 From: BD103 <59022059+BD103@users.noreply.github.com> Date: Fri, 12 Apr 2024 22:05:38 -0400 Subject: [PATCH] Fix some nightly Clippy lints (#12927) # Objective - I daily drive nightly Rust when developing Bevy, so I notice when new warnings are raised by `cargo check` and Clippy. - `cargo +nightly clippy` raises a few of these new warnings. ## Solution - Fix most warnings from `cargo +nightly clippy` - I skipped the docs-related warnings because some were covered by #12692. - Use `Clone::clone_from` in applicable scenarios, which can sometimes avoid an extra allocation. - Implement `Default` for structs that have a `pub const fn new() -> Self` method. - Fix an occurrence where generic constraints were defined in both `` and `where C: Trait`. - Removed generic constraints that were implied by the `Bundle` trait. --- ## Changelog - `BatchingStrategy`, `NonGenericTypeCell`, and `GenericTypeCell` now implement `Default`. --- crates/bevy_ecs/src/query/par_iter.rs | 6 ++++++ crates/bevy_ecs/src/schedule/stepping.rs | 2 +- crates/bevy_hierarchy/src/child_builder.rs | 2 +- crates/bevy_reflect/src/impls/std.rs | 4 ++-- crates/bevy_reflect/src/utility.rs | 12 ++++++++++++ crates/bevy_render/src/extract_component.rs | 4 ++-- 6 files changed, 24 insertions(+), 6 deletions(-) diff --git a/crates/bevy_ecs/src/query/par_iter.rs b/crates/bevy_ecs/src/query/par_iter.rs index 1d18b69ca0..27bc201783 100644 --- a/crates/bevy_ecs/src/query/par_iter.rs +++ b/crates/bevy_ecs/src/query/par_iter.rs @@ -78,6 +78,12 @@ impl BatchingStrategy { } } +impl Default for BatchingStrategy { + fn default() -> Self { + Self::new() + } +} + /// A parallel iterator over query results of a [`Query`](crate::system::Query). /// /// This struct is created by the [`Query::par_iter`](crate::system::Query::par_iter) and diff --git a/crates/bevy_ecs/src/schedule/stepping.rs b/crates/bevy_ecs/src/schedule/stepping.rs index a129993e89..f516faaa20 100644 --- a/crates/bevy_ecs/src/schedule/stepping.rs +++ b/crates/bevy_ecs/src/schedule/stepping.rs @@ -696,7 +696,7 @@ impl ScheduleState { // if our NodeId list hasn't been populated, copy it over from the // schedule if self.node_ids.len() != schedule.systems_len() { - self.node_ids = schedule.executable().system_ids.clone(); + self.node_ids.clone_from(&schedule.executable().system_ids); } // Now that we have the schedule, apply any pending system behavior diff --git a/crates/bevy_hierarchy/src/child_builder.rs b/crates/bevy_hierarchy/src/child_builder.rs index 9f36fe679e..6c32979666 100644 --- a/crates/bevy_hierarchy/src/child_builder.rs +++ b/crates/bevy_hierarchy/src/child_builder.rs @@ -481,7 +481,7 @@ pub struct WorldChildBuilder<'w> { impl<'w> WorldChildBuilder<'w> { /// Spawns an entity with the given bundle and inserts it into the parent entity's [`Children`]. /// Also adds [`Parent`] component to the created entity. - pub fn spawn(&mut self, bundle: impl Bundle + Send + Sync + 'static) -> EntityWorldMut<'_> { + pub fn spawn(&mut self, bundle: impl Bundle) -> EntityWorldMut<'_> { let entity = self.world.spawn((bundle, Parent(self.parent))).id(); push_child_unchecked(self.world, self.parent, entity); push_events( diff --git a/crates/bevy_reflect/src/impls/std.rs b/crates/bevy_reflect/src/impls/std.rs index f81db9d6c7..c97ad5fc54 100644 --- a/crates/bevy_reflect/src/impls/std.rs +++ b/crates/bevy_reflect/src/impls/std.rs @@ -1059,7 +1059,7 @@ impl Reflect for Cow<'static, str> { fn apply(&mut self, value: &dyn Reflect) { let value = value.as_any(); if let Some(value) = value.downcast_ref::() { - *self = value.clone(); + self.clone_from(value); } else { panic!("Value is not a {}.", Self::type_path()); } @@ -1548,7 +1548,7 @@ impl Reflect for Cow<'static, Path> { fn apply(&mut self, value: &dyn Reflect) { let value = value.as_any(); if let Some(value) = value.downcast_ref::() { - *self = value.clone(); + self.clone_from(value); } else { panic!("Value is not a {}.", Self::type_path()); } diff --git a/crates/bevy_reflect/src/utility.rs b/crates/bevy_reflect/src/utility.rs index 2c026441ed..df860d194c 100644 --- a/crates/bevy_reflect/src/utility.rs +++ b/crates/bevy_reflect/src/utility.rs @@ -110,6 +110,12 @@ impl NonGenericTypeCell { } } +impl Default for NonGenericTypeCell { + fn default() -> Self { + Self::new() + } +} + /// A container for [`TypedProperty`] over generic types, allowing instances to be stored statically. /// /// This is specifically meant for use with generic types. If your type isn't generic, @@ -245,6 +251,12 @@ impl GenericTypeCell { } } +impl Default for GenericTypeCell { + fn default() -> Self { + Self::new() + } +} + /// Deterministic fixed state hasher to be used by implementors of [`Reflect::reflect_hash`]. /// /// Hashes should be deterministic across processes so hashes can be used as diff --git a/crates/bevy_render/src/extract_component.rs b/crates/bevy_render/src/extract_component.rs index a19f93539b..4b327cf6af 100644 --- a/crates/bevy_render/src/extract_component.rs +++ b/crates/bevy_render/src/extract_component.rs @@ -123,14 +123,14 @@ impl Default for ComponentUniforms { /// This system prepares all components of the corresponding component type. /// They are transformed into uniforms and stored in the [`ComponentUniforms`] resource. -fn prepare_uniform_components( +fn prepare_uniform_components( mut commands: Commands, render_device: Res, render_queue: Res, mut component_uniforms: ResMut>, components: Query<(Entity, &C)>, ) where - C: ShaderType + WriteInto + Clone, + C: Component + ShaderType + WriteInto + Clone, { let components_iter = components.iter(); let count = components_iter.len();