diff --git a/crates/bevy_ecs/src/entity/mod.rs b/crates/bevy_ecs/src/entity/mod.rs index be142a594cd1d1..abfd3513ea50e2 100644 --- a/crates/bevy_ecs/src/entity/mod.rs +++ b/crates/bevy_ecs/src/entity/mod.rs @@ -196,6 +196,7 @@ impl<'a> Iterator for ReserveEntitiesIterator<'a> { } impl<'a> core::iter::ExactSizeIterator for ReserveEntitiesIterator<'a> {} +impl<'a> core::iter::FusedIterator for ReserveEntitiesIterator<'a> {} #[derive(Debug, Default)] pub struct Entities { diff --git a/crates/bevy_ecs/src/query/iter.rs b/crates/bevy_ecs/src/query/iter.rs index 84843283cc6fb9..ebc0e327921105 100644 --- a/crates/bevy_ecs/src/query/iter.rs +++ b/crates/bevy_ecs/src/query/iter.rs @@ -5,7 +5,7 @@ use crate::{ query::{Fetch, QueryState, WorldQuery}, storage::{TableId, Tables}, }; -use std::{borrow::Borrow, marker::PhantomData, mem::MaybeUninit}; +use std::{borrow::Borrow, iter::FusedIterator, marker::PhantomData, mem::MaybeUninit}; use super::{QueryFetch, QueryItem, ReadOnlyFetch}; @@ -72,6 +72,12 @@ where } } +// This is correct as [`QueryIter`] always returns `None` once exhausted. +impl<'w, 's, Q: WorldQuery, QF, F: WorldQuery> FusedIterator for QueryIter<'w, 's, Q, QF, F> where + QF: Fetch<'w, State = Q::State> +{ +} + /// An [`Iterator`] over query results of a [`Query`](crate::system::Query). /// /// This struct is created by the [`Query::iter_many`](crate::system::Query::iter_many) method. @@ -359,6 +365,15 @@ where } } +// This is correct as [`QueryCombinationIter`] always returns `None` once exhausted. +impl<'w, 's, Q: WorldQuery, F: WorldQuery, const K: usize> FusedIterator + for QueryCombinationIter<'w, 's, Q, F, K> +where + QueryFetch<'w, Q>: Clone + ReadOnlyFetch, + QueryFetch<'w, F>: Clone + ReadOnlyFetch, +{ +} + struct QueryIterationCursor<'w, 's, Q: WorldQuery, QF: Fetch<'w, State = Q::State>, F: WorldQuery> { table_id_iter: std::slice::Iter<'s, TableId>, archetype_id_iter: std::slice::Iter<'s, ArchetypeId>, diff --git a/crates/bevy_ecs/src/world/spawn_batch.rs b/crates/bevy_ecs/src/world/spawn_batch.rs index 8ca0bc8d750683..002e30a2b3f3af 100644 --- a/crates/bevy_ecs/src/world/spawn_batch.rs +++ b/crates/bevy_ecs/src/world/spawn_batch.rs @@ -3,6 +3,7 @@ use crate::{ entity::Entity, world::World, }; +use std::iter::FusedIterator; pub struct SpawnBatchIter<'w, I> where @@ -84,3 +85,10 @@ where self.inner.len() } } + +impl FusedIterator for SpawnBatchIter<'_, I> +where + I: FusedIterator, + T: Bundle, +{ +} diff --git a/crates/bevy_reflect/src/array.rs b/crates/bevy_reflect/src/array.rs index 45271d5ddca5ea..59ecc8949d9880 100644 --- a/crates/bevy_reflect/src/array.rs +++ b/crates/bevy_reflect/src/array.rs @@ -1,7 +1,7 @@ use crate::{serde::Serializable, Reflect, ReflectMut, ReflectRef}; -use std::fmt::Debug; use std::{ any::Any, + fmt::Debug, hash::{Hash, Hasher}, }; diff --git a/crates/bevy_render/src/mesh/mesh/mod.rs b/crates/bevy_render/src/mesh/mesh/mod.rs index 45f88e16d09e40..8f891ec0e7e487 100644 --- a/crates/bevy_render/src/mesh/mesh/mod.rs +++ b/crates/bevy_render/src/mesh/mesh/mod.rs @@ -14,7 +14,7 @@ use bevy_ecs::system::{lifetimeless::SRes, SystemParamItem}; use bevy_math::*; use bevy_reflect::TypeUuid; use bevy_utils::Hashed; -use std::{collections::BTreeMap, hash::Hash}; +use std::{collections::BTreeMap, hash::Hash, iter::FusedIterator}; use thiserror::Error; use wgpu::{ util::BufferInitDescriptor, BufferUsages, IndexFormat, VertexAttribute, VertexFormat, @@ -749,8 +749,18 @@ impl Iterator for IndicesIter<'_> { IndicesIter::U32(iter) => iter.next().map(|val| *val as usize), } } + + fn size_hint(&self) -> (usize, Option) { + match self { + IndicesIter::U16(iter) => iter.size_hint(), + IndicesIter::U32(iter) => iter.size_hint(), + } + } } +impl<'a> ExactSizeIterator for IndicesIter<'a> {} +impl<'a> FusedIterator for IndicesIter<'a> {} + impl From<&Indices> for IndexFormat { fn from(indices: &Indices) -> Self { match indices { diff --git a/crates/bevy_render/src/render_resource/pipeline_cache.rs b/crates/bevy_render/src/render_resource/pipeline_cache.rs index 02971c966c26c0..204a94745bbeb3 100644 --- a/crates/bevy_render/src/render_resource/pipeline_cache.rs +++ b/crates/bevy_render/src/render_resource/pipeline_cache.rs @@ -13,7 +13,7 @@ use bevy_asset::{AssetEvent, Assets, Handle}; use bevy_ecs::event::EventReader; use bevy_ecs::system::{Res, ResMut}; use bevy_utils::{default, tracing::error, Entry, HashMap, HashSet}; -use std::{hash::Hash, mem, ops::Deref, sync::Arc}; +use std::{hash::Hash, iter::FusedIterator, mem, ops::Deref, sync::Arc}; use thiserror::Error; use wgpu::{PipelineLayoutDescriptor, ShaderModule, VertexBufferLayout as RawVertexBufferLayout}; @@ -672,3 +672,5 @@ impl<'a> Iterator for ErrorSources<'a> { current } } + +impl<'a> FusedIterator for ErrorSources<'a> {}