mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 12:43:34 +00:00
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`.
This commit is contained in:
parent
78345a2f7a
commit
aa2ebbb43f
6 changed files with 24 additions and 6 deletions
|
@ -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).
|
/// 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
|
/// This struct is created by the [`Query::par_iter`](crate::system::Query::par_iter) and
|
||||||
|
|
|
@ -696,7 +696,7 @@ impl ScheduleState {
|
||||||
// if our NodeId list hasn't been populated, copy it over from the
|
// if our NodeId list hasn't been populated, copy it over from the
|
||||||
// schedule
|
// schedule
|
||||||
if self.node_ids.len() != schedule.systems_len() {
|
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
|
// Now that we have the schedule, apply any pending system behavior
|
||||||
|
|
|
@ -481,7 +481,7 @@ pub struct WorldChildBuilder<'w> {
|
||||||
impl<'w> WorldChildBuilder<'w> {
|
impl<'w> WorldChildBuilder<'w> {
|
||||||
/// Spawns an entity with the given bundle and inserts it into the parent entity's [`Children`].
|
/// Spawns an entity with the given bundle and inserts it into the parent entity's [`Children`].
|
||||||
/// Also adds [`Parent`] component to the created entity.
|
/// 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();
|
let entity = self.world.spawn((bundle, Parent(self.parent))).id();
|
||||||
push_child_unchecked(self.world, self.parent, entity);
|
push_child_unchecked(self.world, self.parent, entity);
|
||||||
push_events(
|
push_events(
|
||||||
|
|
|
@ -1059,7 +1059,7 @@ impl Reflect for Cow<'static, str> {
|
||||||
fn apply(&mut self, value: &dyn Reflect) {
|
fn apply(&mut self, value: &dyn Reflect) {
|
||||||
let value = value.as_any();
|
let value = value.as_any();
|
||||||
if let Some(value) = value.downcast_ref::<Self>() {
|
if let Some(value) = value.downcast_ref::<Self>() {
|
||||||
*self = value.clone();
|
self.clone_from(value);
|
||||||
} else {
|
} else {
|
||||||
panic!("Value is not a {}.", Self::type_path());
|
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) {
|
fn apply(&mut self, value: &dyn Reflect) {
|
||||||
let value = value.as_any();
|
let value = value.as_any();
|
||||||
if let Some(value) = value.downcast_ref::<Self>() {
|
if let Some(value) = value.downcast_ref::<Self>() {
|
||||||
*self = value.clone();
|
self.clone_from(value);
|
||||||
} else {
|
} else {
|
||||||
panic!("Value is not a {}.", Self::type_path());
|
panic!("Value is not a {}.", Self::type_path());
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,6 +110,12 @@ impl<T: TypedProperty> NonGenericTypeCell<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T: TypedProperty> Default for NonGenericTypeCell<T> {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A container for [`TypedProperty`] over generic types, allowing instances to be stored statically.
|
/// 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,
|
/// This is specifically meant for use with generic types. If your type isn't generic,
|
||||||
|
@ -245,6 +251,12 @@ impl<T: TypedProperty> GenericTypeCell<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T: TypedProperty> Default for GenericTypeCell<T> {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Deterministic fixed state hasher to be used by implementors of [`Reflect::reflect_hash`].
|
/// 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
|
/// Hashes should be deterministic across processes so hashes can be used as
|
||||||
|
|
|
@ -123,14 +123,14 @@ impl<C: Component + ShaderType> Default for ComponentUniforms<C> {
|
||||||
|
|
||||||
/// This system prepares all components of the corresponding component type.
|
/// This system prepares all components of the corresponding component type.
|
||||||
/// They are transformed into uniforms and stored in the [`ComponentUniforms`] resource.
|
/// They are transformed into uniforms and stored in the [`ComponentUniforms`] resource.
|
||||||
fn prepare_uniform_components<C: Component>(
|
fn prepare_uniform_components<C>(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
render_device: Res<RenderDevice>,
|
render_device: Res<RenderDevice>,
|
||||||
render_queue: Res<RenderQueue>,
|
render_queue: Res<RenderQueue>,
|
||||||
mut component_uniforms: ResMut<ComponentUniforms<C>>,
|
mut component_uniforms: ResMut<ComponentUniforms<C>>,
|
||||||
components: Query<(Entity, &C)>,
|
components: Query<(Entity, &C)>,
|
||||||
) where
|
) where
|
||||||
C: ShaderType + WriteInto + Clone,
|
C: Component + ShaderType + WriteInto + Clone,
|
||||||
{
|
{
|
||||||
let components_iter = components.iter();
|
let components_iter = components.iter();
|
||||||
let count = components_iter.len();
|
let count = components_iter.len();
|
||||||
|
|
Loading…
Reference in a new issue