Skip to content

Commit 694c980

Browse files
committed
Fix clippy::iter_with_drain (#6485)
# Objective Fixes #6483. - Fix the [`clippy::iter_with_drain`](https://rust-lang.github.io/rust-clippy/master/index.html#iter_with_drain) warnings - From the docs: "`.into_iter()` is simpler with better performance" ## Solution - Replace `.drain(..)` for `Vec` with `.into_iter()`
1 parent 66f495c commit 694c980

File tree

8 files changed

+16
-17
lines changed

8 files changed

+16
-17
lines changed

crates/bevy_asset/src/loader.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ impl<T: Asset> LoadedAsset<T> {
8686

8787
/// Adds dependencies on other assets at the provided paths.
8888
#[must_use]
89-
pub fn with_dependencies(mut self, mut asset_paths: Vec<AssetPath<'static>>) -> Self {
90-
for asset_path in asset_paths.drain(..) {
89+
pub fn with_dependencies(mut self, asset_paths: Vec<AssetPath<'static>>) -> Self {
90+
for asset_path in asset_paths {
9191
self.add_dependency(asset_path);
9292
}
9393
self

crates/bevy_ecs/src/schedule/ambiguity_detection.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,9 @@ fn find_ambiguities(systems: &[SystemContainer]) -> Vec<(usize, usize, Vec<Compo
235235
}
236236
all_dependants[index] = dependants;
237237
}
238-
let mut all_relations = all_dependencies
239-
.drain(..)
240-
.zip(all_dependants.drain(..))
238+
let all_relations = all_dependencies
239+
.into_iter()
240+
.zip(all_dependants.into_iter())
241241
.enumerate()
242242
.map(|(index, (dependencies, dependants))| {
243243
let mut relations = FixedBitSet::with_capacity(systems.len());
@@ -250,7 +250,7 @@ fn find_ambiguities(systems: &[SystemContainer]) -> Vec<(usize, usize, Vec<Compo
250250
let mut ambiguities = Vec::new();
251251
let full_bitset: FixedBitSet = (0..systems.len()).collect();
252252
let mut processed = FixedBitSet::with_capacity(systems.len());
253-
for (index_a, relations) in all_relations.drain(..).enumerate() {
253+
for (index_a, relations) in all_relations.into_iter().enumerate() {
254254
// TODO: prove that `.take(index_a)` would be correct here, and uncomment it if so.
255255
for index_b in full_bitset.difference(&relations)
256256
// .take(index_a)

crates/bevy_ecs/src/schedule/stage.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ impl SystemStage {
309309
}
310310
}
311311
});
312-
for system in systems.drain(..) {
312+
for system in systems {
313313
self.add_system_inner(system, set_run_criteria_index);
314314
}
315315
self

crates/bevy_ecs/src/system/system_param.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,12 @@ fn assert_component_access_compatibility(
203203
current: &FilteredAccess<ComponentId>,
204204
world: &World,
205205
) {
206-
let mut conflicts = system_access.get_conflicts_single(current);
206+
let conflicts = system_access.get_conflicts_single(current);
207207
if conflicts.is_empty() {
208208
return;
209209
}
210210
let conflicting_components = conflicts
211-
.drain(..)
211+
.into_iter()
212212
.map(|component_id| world.components.get_info(component_id).unwrap().name())
213213
.collect::<Vec<&str>>();
214214
let accesses = conflicting_components.join(", ");

crates/bevy_pbr/src/material.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -536,8 +536,8 @@ fn prepare_materials<M: Material>(
536536
fallback_image: Res<FallbackImage>,
537537
pipeline: Res<MaterialPipeline<M>>,
538538
) {
539-
let mut queued_assets = std::mem::take(&mut prepare_next_frame.assets);
540-
for (handle, material) in queued_assets.drain(..) {
539+
let queued_assets = std::mem::take(&mut prepare_next_frame.assets);
540+
for (handle, material) in queued_assets.into_iter() {
541541
match prepare_material(
542542
&material,
543543
&render_device,

crates/bevy_render/src/render_asset.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ fn prepare_assets<R: RenderAsset>(
186186
param: StaticSystemParam<<R as RenderAsset>::Param>,
187187
) {
188188
let mut param = param.into_inner();
189-
let mut queued_assets = std::mem::take(&mut prepare_next_frame.assets);
190-
for (handle, extracted_asset) in queued_assets.drain(..) {
189+
let queued_assets = std::mem::take(&mut prepare_next_frame.assets);
190+
for (handle, extracted_asset) in queued_assets {
191191
match R::prepare_asset(extracted_asset, &mut param) {
192192
Ok(prepared_asset) => {
193193
render_assets.insert(handle, prepared_asset);

crates/bevy_render/src/render_phase/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ impl<I: BatchedPhaseItem> RenderPhase<I> {
3535
/// Batches the compatible [`BatchedPhaseItem`]s of this render phase
3636
pub fn batch(&mut self) {
3737
// TODO: this could be done in-place
38-
let mut items = std::mem::take(&mut self.items);
39-
let mut items = items.drain(..);
38+
let mut items = std::mem::take(&mut self.items).into_iter();
4039

4140
self.items.reserve(items.len());
4241

crates/bevy_sprite/src/mesh2d/material.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,8 @@ fn prepare_materials_2d<M: Material2d>(
471471
fallback_image: Res<FallbackImage>,
472472
pipeline: Res<Material2dPipeline<M>>,
473473
) {
474-
let mut queued_assets = std::mem::take(&mut prepare_next_frame.assets);
475-
for (handle, material) in queued_assets.drain(..) {
474+
let queued_assets = std::mem::take(&mut prepare_next_frame.assets);
475+
for (handle, material) in queued_assets {
476476
match prepare_material2d(
477477
&material,
478478
&render_device,

0 commit comments

Comments
 (0)