Skip to content

Commit aa2ebbb

Browse files
authored
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 `<C: Trait>` and `where C: Trait`. - Removed generic constraints that were implied by the `Bundle` trait. --- ## Changelog - `BatchingStrategy`, `NonGenericTypeCell`, and `GenericTypeCell` now implement `Default`.
1 parent 78345a2 commit aa2ebbb

File tree

6 files changed

+24
-6
lines changed

6 files changed

+24
-6
lines changed

crates/bevy_ecs/src/query/par_iter.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ impl BatchingStrategy {
7878
}
7979
}
8080

81+
impl Default for BatchingStrategy {
82+
fn default() -> Self {
83+
Self::new()
84+
}
85+
}
86+
8187
/// A parallel iterator over query results of a [`Query`](crate::system::Query).
8288
///
8389
/// This struct is created by the [`Query::par_iter`](crate::system::Query::par_iter) and

crates/bevy_ecs/src/schedule/stepping.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ impl ScheduleState {
696696
// if our NodeId list hasn't been populated, copy it over from the
697697
// schedule
698698
if self.node_ids.len() != schedule.systems_len() {
699-
self.node_ids = schedule.executable().system_ids.clone();
699+
self.node_ids.clone_from(&schedule.executable().system_ids);
700700
}
701701

702702
// Now that we have the schedule, apply any pending system behavior

crates/bevy_hierarchy/src/child_builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ pub struct WorldChildBuilder<'w> {
481481
impl<'w> WorldChildBuilder<'w> {
482482
/// Spawns an entity with the given bundle and inserts it into the parent entity's [`Children`].
483483
/// Also adds [`Parent`] component to the created entity.
484-
pub fn spawn(&mut self, bundle: impl Bundle + Send + Sync + 'static) -> EntityWorldMut<'_> {
484+
pub fn spawn(&mut self, bundle: impl Bundle) -> EntityWorldMut<'_> {
485485
let entity = self.world.spawn((bundle, Parent(self.parent))).id();
486486
push_child_unchecked(self.world, self.parent, entity);
487487
push_events(

crates/bevy_reflect/src/impls/std.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,7 @@ impl Reflect for Cow<'static, str> {
10591059
fn apply(&mut self, value: &dyn Reflect) {
10601060
let value = value.as_any();
10611061
if let Some(value) = value.downcast_ref::<Self>() {
1062-
*self = value.clone();
1062+
self.clone_from(value);
10631063
} else {
10641064
panic!("Value is not a {}.", Self::type_path());
10651065
}
@@ -1548,7 +1548,7 @@ impl Reflect for Cow<'static, Path> {
15481548
fn apply(&mut self, value: &dyn Reflect) {
15491549
let value = value.as_any();
15501550
if let Some(value) = value.downcast_ref::<Self>() {
1551-
*self = value.clone();
1551+
self.clone_from(value);
15521552
} else {
15531553
panic!("Value is not a {}.", Self::type_path());
15541554
}

crates/bevy_reflect/src/utility.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ impl<T: TypedProperty> NonGenericTypeCell<T> {
110110
}
111111
}
112112

113+
impl<T: TypedProperty> Default for NonGenericTypeCell<T> {
114+
fn default() -> Self {
115+
Self::new()
116+
}
117+
}
118+
113119
/// A container for [`TypedProperty`] over generic types, allowing instances to be stored statically.
114120
///
115121
/// This is specifically meant for use with generic types. If your type isn't generic,
@@ -245,6 +251,12 @@ impl<T: TypedProperty> GenericTypeCell<T> {
245251
}
246252
}
247253

254+
impl<T: TypedProperty> Default for GenericTypeCell<T> {
255+
fn default() -> Self {
256+
Self::new()
257+
}
258+
}
259+
248260
/// Deterministic fixed state hasher to be used by implementors of [`Reflect::reflect_hash`].
249261
///
250262
/// Hashes should be deterministic across processes so hashes can be used as

crates/bevy_render/src/extract_component.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,14 @@ impl<C: Component + ShaderType> Default for ComponentUniforms<C> {
123123

124124
/// This system prepares all components of the corresponding component type.
125125
/// They are transformed into uniforms and stored in the [`ComponentUniforms`] resource.
126-
fn prepare_uniform_components<C: Component>(
126+
fn prepare_uniform_components<C>(
127127
mut commands: Commands,
128128
render_device: Res<RenderDevice>,
129129
render_queue: Res<RenderQueue>,
130130
mut component_uniforms: ResMut<ComponentUniforms<C>>,
131131
components: Query<(Entity, &C)>,
132132
) where
133-
C: ShaderType + WriteInto + Clone,
133+
C: Component + ShaderType + WriteInto + Clone,
134134
{
135135
let components_iter = components.iter();
136136
let count = components_iter.len();

0 commit comments

Comments
 (0)