diff --git a/crates/bevy_ecs/src/removal_detection.rs b/crates/bevy_ecs/src/removal_detection.rs index 1aaaa01c95..c81a5cfa1e 100644 --- a/crates/bevy_ecs/src/removal_detection.rs +++ b/crates/bevy_ecs/src/removal_detection.rs @@ -233,8 +233,7 @@ impl<'w, 's, T: Component> RemovedComponents<'w, 's, T> { /// Returns `true` if there are no events available to read. pub fn is_empty(&self) -> bool { self.events() - .map(|events| self.reader.is_empty(events)) - .unwrap_or(true) + .is_none_or(|events| self.reader.is_empty(events)) } /// Consumes all available events. diff --git a/crates/bevy_hierarchy/src/query_extension.rs b/crates/bevy_hierarchy/src/query_extension.rs index 6396ddcfb7..35ebaf8025 100644 --- a/crates/bevy_hierarchy/src/query_extension.rs +++ b/crates/bevy_hierarchy/src/query_extension.rs @@ -139,10 +139,10 @@ impl<'w, 's, D: QueryData, F: QueryFilter> HierarchyQueryExt<'w, 's, D, F> for Q { self.iter_descendants_depth_first(entity).filter(|entity| { self.get(*entity) + .ok() // These are leaf nodes if they have the `Children` component but it's empty - .map(|children| children.is_empty()) // Or if they don't have the `Children` component at all - .unwrap_or(true) + .is_none_or(|children| children.is_empty()) }) } diff --git a/crates/bevy_picking/src/mesh_picking/mod.rs b/crates/bevy_picking/src/mesh_picking/mod.rs index a848097a68..42671beb7b 100644 --- a/crates/bevy_picking/src/mesh_picking/mod.rs +++ b/crates/bevy_picking/src/mesh_picking/mod.rs @@ -99,10 +99,7 @@ pub fn update_hits( let entity_layers = layers.get(entity).cloned().unwrap_or_default(); let render_layers_match = cam_layers.intersects(&entity_layers); - let is_pickable = pickables - .get(entity) - .map(|p| p.is_hoverable) - .unwrap_or(true); + let is_pickable = pickables.get(entity).ok().is_none_or(|p| p.is_hoverable); marker_requirement && render_layers_match && is_pickable }, diff --git a/crates/bevy_reflect/derive/src/container_attributes.rs b/crates/bevy_reflect/derive/src/container_attributes.rs index b134c571c0..bdb94db06b 100644 --- a/crates/bevy_reflect/derive/src/container_attributes.rs +++ b/crates/bevy_reflect/derive/src/container_attributes.rs @@ -89,10 +89,7 @@ pub(crate) struct FromReflectAttrs { impl FromReflectAttrs { /// Returns true if `FromReflect` should be automatically derived as part of the `Reflect` derive. pub fn should_auto_derive(&self) -> bool { - self.auto_derive - .as_ref() - .map(LitBool::value) - .unwrap_or(true) + self.auto_derive.as_ref().is_none_or(LitBool::value) } } @@ -112,10 +109,7 @@ pub(crate) struct TypePathAttrs { impl TypePathAttrs { /// Returns true if `TypePath` should be automatically derived as part of the `Reflect` derive. pub fn should_auto_derive(&self) -> bool { - self.auto_derive - .as_ref() - .map(LitBool::value) - .unwrap_or(true) + self.auto_derive.as_ref().is_none_or(LitBool::value) } } diff --git a/crates/bevy_scene/src/scene_spawner.rs b/crates/bevy_scene/src/scene_spawner.rs index edba01b40c..7117542d83 100644 --- a/crates/bevy_scene/src/scene_spawner.rs +++ b/crates/bevy_scene/src/scene_spawner.rs @@ -375,12 +375,12 @@ impl SceneSpawner { // the scene parent if !world .get_entity(entity) + .ok() // This will filter only the scene root entity, as all other from the // scene have a parent - .map(|entity| entity.contains::()) - // Default is true so that it won't run on an entity that wouldn't exist anymore + // Entities that wouldn't exist anymore are also skipped // this case shouldn't happen anyway - .unwrap_or(true) + .is_none_or(|entity| entity.contains::()) { world.entity_mut(parent).add_child(entity); } diff --git a/crates/bevy_sprite/src/picking_backend.rs b/crates/bevy_sprite/src/picking_backend.rs index bd57aaf202..a88e15fdb9 100644 --- a/crates/bevy_sprite/src/picking_backend.rs +++ b/crates/bevy_sprite/src/picking_backend.rs @@ -186,9 +186,7 @@ fn sprite_picking( }; blocked = cursor_in_valid_pixels_of_sprite - && picking_behavior - .map(|p| p.should_block_lower) - .unwrap_or(true); + && picking_behavior.is_none_or(|p| p.should_block_lower); cursor_in_valid_pixels_of_sprite.then(|| { let hit_pos_world = diff --git a/crates/bevy_ui/src/render/mod.rs b/crates/bevy_ui/src/render/mod.rs index f4fd9af023..84a458921c 100644 --- a/crates/bevy_ui/src/render/mod.rs +++ b/crates/bevy_ui/src/render/mod.rs @@ -702,14 +702,9 @@ pub fn extract_text_sections( rect, }); - if text_layout_info - .glyphs - .get(i + 1) - .map(|info| { - info.span_index != current_span || info.atlas_info.texture != atlas_info.texture - }) - .unwrap_or(true) - { + if text_layout_info.glyphs.get(i + 1).is_none_or(|info| { + info.span_index != current_span || info.atlas_info.texture != atlas_info.texture + }) { let id = commands.spawn(TemporaryRenderEntity).id(); extracted_uinodes.uinodes.insert(