Skip to content

Commit 700ee46

Browse files
authored
Fix some lints from rust 1.89 bump (#22034)
# Objective - In #21822 the MSRV bump triggers some new lint warnings, so this pr fixes them. ## Solution - Bumped the msrv in bevy_ecs and fixed the lints. But this pr does not actually bump the msrv. These fixes are all for combining nested if's together.
1 parent 6e88ae2 commit 700ee46

File tree

6 files changed

+54
-57
lines changed

6 files changed

+54
-57
lines changed

crates/bevy_ecs/src/component/clone.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,20 +110,18 @@ pub fn component_clone_via_reflect(source: &SourceComponent, ctx: &mut Component
110110
// Try to clone using ReflectFromReflect
111111
if let Some(reflect_from_reflect) =
112112
registry.get_type_data::<bevy_reflect::ReflectFromReflect>(type_id)
113-
{
114-
if let Some(mut component) =
113+
&& let Some(mut component) =
115114
reflect_from_reflect.from_reflect(source_component_reflect.as_partial_reflect())
115+
{
116+
if let Some(reflect_component) =
117+
registry.get_type_data::<crate::reflect::ReflectComponent>(type_id)
116118
{
117-
if let Some(reflect_component) =
118-
registry.get_type_data::<crate::reflect::ReflectComponent>(type_id)
119-
{
120-
reflect_component.map_entities(&mut *component, ctx.entity_mapper());
121-
}
122-
drop(registry);
123-
124-
ctx.write_target_component_reflect(component);
125-
return;
119+
reflect_component.map_entities(&mut *component, ctx.entity_mapper());
126120
}
121+
drop(registry);
122+
123+
ctx.write_target_component_reflect(component);
124+
return;
127125
}
128126
// Else, try to clone using ReflectDefault
129127
if let Some(reflect_default) =

crates/bevy_ecs/src/entity/clone_entities.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,11 +1144,11 @@ impl OptOut {
11441144
#[inline]
11451145
fn filter_deny(&mut self, id: ComponentId, world: &World) {
11461146
self.deny.insert(id);
1147-
if self.attach_required_by_components {
1148-
if let Some(required_by) = world.components().get_required_by(id) {
1149-
self.deny.extend(required_by.iter());
1150-
};
1151-
}
1147+
if self.attach_required_by_components
1148+
&& let Some(required_by) = world.components().get_required_by(id)
1149+
{
1150+
self.deny.extend(required_by.iter());
1151+
};
11521152
}
11531153
}
11541154

crates/bevy_ecs/src/observer/mod.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -219,18 +219,18 @@ impl World {
219219
&& observers.entity_component_observers.is_empty()
220220
{
221221
cache.component_observers.remove(component);
222-
if let Some(flag) = Observers::is_archetype_cached(event_key) {
223-
if let Some(by_component) = archetypes.by_component.get(component) {
224-
for archetype in by_component.keys() {
225-
let archetype = &mut archetypes.archetypes[archetype.index()];
226-
if archetype.contains(*component) {
227-
let no_longer_observed = archetype
228-
.iter_components()
229-
.all(|id| !cache.component_observers.contains_key(&id));
230-
231-
if no_longer_observed {
232-
archetype.flags.set(flag, false);
233-
}
222+
if let Some(flag) = Observers::is_archetype_cached(event_key)
223+
&& let Some(by_component) = archetypes.by_component.get(component)
224+
{
225+
for archetype in by_component.keys() {
226+
let archetype = &mut archetypes.archetypes[archetype.index()];
227+
if archetype.contains(*component) {
228+
let no_longer_observed = archetype
229+
.iter_components()
230+
.all(|id| !cache.component_observers.contains_key(&id));
231+
232+
if no_longer_observed {
233+
archetype.flags.set(flag, false);
234234
}
235235
}
236236
}

crates/bevy_ecs/src/query/fetch.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3319,10 +3319,10 @@ mod tests {
33193319

33203320
fn system(query: Query<EntityRef>) {
33213321
for entity_ref in &query {
3322-
if let Some(c) = entity_ref.get_ref::<C>() {
3323-
if !c.is_added() {
3324-
panic!("Expected C to be added");
3325-
}
3322+
if let Some(c) = entity_ref.get_ref::<C>()
3323+
&& !c.is_added()
3324+
{
3325+
panic!("Expected C to be added");
33263326
}
33273327
}
33283328
}

crates/bevy_ecs/src/relationship/mod.rs

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -188,28 +188,27 @@ pub trait Relationship: Component + Sized {
188188
}
189189
}
190190
let target_entity = world.entity(entity).get::<Self>().unwrap().get();
191-
if let Ok(mut target_entity_mut) = world.get_entity_mut(target_entity) {
192-
if let Some(mut relationship_target) =
191+
if let Ok(mut target_entity_mut) = world.get_entity_mut(target_entity)
192+
&& let Some(mut relationship_target) =
193193
target_entity_mut.get_mut::<Self::RelationshipTarget>()
194-
{
195-
relationship_target.collection_mut_risky().remove(entity);
196-
if relationship_target.len() == 0 {
197-
let command = |mut entity: EntityWorldMut| {
198-
// this "remove" operation must check emptiness because in the event that an identical
199-
// relationship is inserted on top, this despawn would result in the removal of that identical
200-
// relationship ... not what we want!
201-
if entity
202-
.get::<Self::RelationshipTarget>()
203-
.is_some_and(RelationshipTarget::is_empty)
204-
{
205-
entity.remove::<Self::RelationshipTarget>();
206-
}
207-
};
208-
209-
world
210-
.commands()
211-
.queue_silenced(command.with_entity(target_entity));
212-
}
194+
{
195+
relationship_target.collection_mut_risky().remove(entity);
196+
if relationship_target.len() == 0 {
197+
let command = |mut entity: EntityWorldMut| {
198+
// this "remove" operation must check emptiness because in the event that an identical
199+
// relationship is inserted on top, this despawn would result in the removal of that identical
200+
// relationship ... not what we want!
201+
if entity
202+
.get::<Self::RelationshipTarget>()
203+
.is_some_and(RelationshipTarget::is_empty)
204+
{
205+
entity.remove::<Self::RelationshipTarget>();
206+
}
207+
};
208+
209+
world
210+
.commands()
211+
.queue_silenced(command.with_entity(target_entity));
213212
}
214213
}
215214
}

crates/bevy_ecs/src/system/system.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -442,10 +442,10 @@ where
442442
// Note that the `downcast_mut` check is based on the static type,
443443
// and can be optimized out after monomorphization.
444444
let any: &mut dyn Any = &mut value;
445-
if let Some(err) = any.downcast_mut::<SystemParamValidationError>() {
446-
if err.skipped {
447-
return Self::Skipped(core::mem::replace(err, SystemParamValidationError::EMPTY));
448-
}
445+
if let Some(err) = any.downcast_mut::<SystemParamValidationError>()
446+
&& err.skipped
447+
{
448+
return Self::Skipped(core::mem::replace(err, SystemParamValidationError::EMPTY));
449449
}
450450
Self::Failed(From::from(value))
451451
}

0 commit comments

Comments
 (0)