From 694c980c821c758f3d272e77a0dc7a75107d7ade Mon Sep 17 00:00:00 2001 From: TimJentzsch Date: Sun, 6 Nov 2022 01:42:15 +0000 Subject: [PATCH] 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()` --- crates/bevy_asset/src/loader.rs | 4 ++-- crates/bevy_ecs/src/schedule/ambiguity_detection.rs | 8 ++++---- crates/bevy_ecs/src/schedule/stage.rs | 2 +- crates/bevy_ecs/src/system/system_param.rs | 4 ++-- crates/bevy_pbr/src/material.rs | 4 ++-- crates/bevy_render/src/render_asset.rs | 4 ++-- crates/bevy_render/src/render_phase/mod.rs | 3 +-- crates/bevy_sprite/src/mesh2d/material.rs | 4 ++-- 8 files changed, 16 insertions(+), 17 deletions(-) diff --git a/crates/bevy_asset/src/loader.rs b/crates/bevy_asset/src/loader.rs index f6a5153b49..931efacb4c 100644 --- a/crates/bevy_asset/src/loader.rs +++ b/crates/bevy_asset/src/loader.rs @@ -86,8 +86,8 @@ impl LoadedAsset { /// Adds dependencies on other assets at the provided paths. #[must_use] - pub fn with_dependencies(mut self, mut asset_paths: Vec>) -> Self { - for asset_path in asset_paths.drain(..) { + pub fn with_dependencies(mut self, asset_paths: Vec>) -> Self { + for asset_path in asset_paths { self.add_dependency(asset_path); } self diff --git a/crates/bevy_ecs/src/schedule/ambiguity_detection.rs b/crates/bevy_ecs/src/schedule/ambiguity_detection.rs index 6bd61f469e..558754c9df 100644 --- a/crates/bevy_ecs/src/schedule/ambiguity_detection.rs +++ b/crates/bevy_ecs/src/schedule/ambiguity_detection.rs @@ -235,9 +235,9 @@ fn find_ambiguities(systems: &[SystemContainer]) -> Vec<(usize, usize, Vec Vec<(usize, usize, Vec, world: &World, ) { - let mut conflicts = system_access.get_conflicts_single(current); + let conflicts = system_access.get_conflicts_single(current); if conflicts.is_empty() { return; } let conflicting_components = conflicts - .drain(..) + .into_iter() .map(|component_id| world.components.get_info(component_id).unwrap().name()) .collect::>(); let accesses = conflicting_components.join(", "); diff --git a/crates/bevy_pbr/src/material.rs b/crates/bevy_pbr/src/material.rs index fecb2e9861..d294b7eeb3 100644 --- a/crates/bevy_pbr/src/material.rs +++ b/crates/bevy_pbr/src/material.rs @@ -536,8 +536,8 @@ fn prepare_materials( fallback_image: Res, pipeline: Res>, ) { - let mut queued_assets = std::mem::take(&mut prepare_next_frame.assets); - for (handle, material) in queued_assets.drain(..) { + let queued_assets = std::mem::take(&mut prepare_next_frame.assets); + for (handle, material) in queued_assets.into_iter() { match prepare_material( &material, &render_device, diff --git a/crates/bevy_render/src/render_asset.rs b/crates/bevy_render/src/render_asset.rs index b4c38dae3c..9bdee8a4cd 100644 --- a/crates/bevy_render/src/render_asset.rs +++ b/crates/bevy_render/src/render_asset.rs @@ -186,8 +186,8 @@ fn prepare_assets( param: StaticSystemParam<::Param>, ) { let mut param = param.into_inner(); - let mut queued_assets = std::mem::take(&mut prepare_next_frame.assets); - for (handle, extracted_asset) in queued_assets.drain(..) { + let queued_assets = std::mem::take(&mut prepare_next_frame.assets); + for (handle, extracted_asset) in queued_assets { match R::prepare_asset(extracted_asset, &mut param) { Ok(prepared_asset) => { render_assets.insert(handle, prepared_asset); diff --git a/crates/bevy_render/src/render_phase/mod.rs b/crates/bevy_render/src/render_phase/mod.rs index 7c2686eebf..29564481ca 100644 --- a/crates/bevy_render/src/render_phase/mod.rs +++ b/crates/bevy_render/src/render_phase/mod.rs @@ -35,8 +35,7 @@ impl RenderPhase { /// Batches the compatible [`BatchedPhaseItem`]s of this render phase pub fn batch(&mut self) { // TODO: this could be done in-place - let mut items = std::mem::take(&mut self.items); - let mut items = items.drain(..); + let mut items = std::mem::take(&mut self.items).into_iter(); self.items.reserve(items.len()); diff --git a/crates/bevy_sprite/src/mesh2d/material.rs b/crates/bevy_sprite/src/mesh2d/material.rs index 01bd223bbf..2e4e03179b 100644 --- a/crates/bevy_sprite/src/mesh2d/material.rs +++ b/crates/bevy_sprite/src/mesh2d/material.rs @@ -471,8 +471,8 @@ fn prepare_materials_2d( fallback_image: Res, pipeline: Res>, ) { - let mut queued_assets = std::mem::take(&mut prepare_next_frame.assets); - for (handle, material) in queued_assets.drain(..) { + let queued_assets = std::mem::take(&mut prepare_next_frame.assets); + for (handle, material) in queued_assets { match prepare_material2d( &material, &render_device,