From d8974e7c3d84189313268f475ceeff9393cedffa Mon Sep 17 00:00:00 2001 From: danieleades Date: Sun, 13 Feb 2022 22:33:55 +0000 Subject: [PATCH] small and mostly pointless refactoring (#2934) What is says on the tin. This has got more to do with making `clippy` slightly more *quiet* than it does with changing anything that might greatly impact readability or performance. that said, deriving `Default` for a couple of structs is a nice easy win --- crates/bevy_app/src/app.rs | 14 ++--- crates/bevy_asset/src/asset_server.rs | 8 +-- crates/bevy_asset/src/assets.rs | 10 ++-- crates/bevy_asset/src/handle.rs | 15 +++--- crates/bevy_asset/src/io/file_asset_io.rs | 2 +- crates/bevy_asset/src/loader.rs | 6 ++- crates/bevy_core/src/float_ord.rs | 4 +- crates/bevy_core/src/time/fixed_timestep.rs | 3 +- crates/bevy_core/src/time/timer.rs | 2 +- crates/bevy_core_pipeline/src/lib.rs | 2 +- crates/bevy_core_pipeline/src/main_pass_2d.rs | 2 +- crates/bevy_core_pipeline/src/main_pass_3d.rs | 6 +-- crates/bevy_derive/src/bevy_main.rs | 7 +-- crates/bevy_derive/src/lib.rs | 2 +- crates/bevy_diagnostic/src/diagnostic.rs | 3 +- crates/bevy_ecs/macros/src/component.rs | 4 +- crates/bevy_ecs/macros/src/lib.rs | 8 +-- crates/bevy_ecs/src/archetype.rs | 2 +- crates/bevy_ecs/src/bundle.rs | 10 ++-- crates/bevy_ecs/src/component.rs | 2 +- crates/bevy_ecs/src/entity/mod.rs | 4 +- crates/bevy_ecs/src/event.rs | 4 +- crates/bevy_ecs/src/lib.rs | 2 +- crates/bevy_ecs/src/query/access.rs | 2 +- crates/bevy_ecs/src/query/fetch.rs | 43 ++++++++------- crates/bevy_ecs/src/query/state.rs | 17 +++--- .../src/schedule/executor_parallel.rs | 2 +- crates/bevy_ecs/src/schedule/mod.rs | 19 ++++--- crates/bevy_ecs/src/schedule/stage.rs | 26 ++++++---- crates/bevy_ecs/src/schedule/system_set.rs | 6 +++ crates/bevy_ecs/src/storage/blob_vec.rs | 4 +- crates/bevy_ecs/src/storage/sparse_set.rs | 2 +- crates/bevy_ecs/src/storage/table.rs | 8 +-- crates/bevy_ecs/src/system/commands/mod.rs | 10 ++-- crates/bevy_ecs/src/system/function_system.rs | 1 + crates/bevy_ecs/src/system/mod.rs | 10 ++-- crates/bevy_ecs/src/system/query.rs | 8 +-- crates/bevy_ecs/src/system/system_param.rs | 22 ++++---- crates/bevy_ecs/src/world/entity_ref.rs | 4 +- crates/bevy_ecs/src/world/mod.rs | 52 +++++++++---------- crates/bevy_ecs/src/world/world_cell.rs | 22 ++++---- crates/bevy_gltf/src/loader.rs | 23 ++++---- crates/bevy_input/src/gamepad.rs | 12 ++--- crates/bevy_macro_utils/src/lib.rs | 2 +- crates/bevy_pbr/src/light.rs | 4 +- crates/bevy_pbr/src/material.rs | 2 +- crates/bevy_pbr/src/pbr_material.rs | 2 +- crates/bevy_pbr/src/render/light.rs | 2 +- .../bevy_reflect_derive/src/lib.rs | 12 ++--- .../bevy_reflect_derive/src/reflect_trait.rs | 2 +- .../bevy_reflect_derive/src/type_uuid.rs | 7 +-- crates/bevy_reflect/src/impls/std.rs | 10 ++-- crates/bevy_reflect/src/map.rs | 2 +- crates/bevy_reflect/src/struct_trait.rs | 2 +- crates/bevy_reflect/src/tuple.rs | 2 +- crates/bevy_reflect/src/tuple_struct.rs | 2 +- crates/bevy_reflect/src/type_registry.rs | 2 +- .../bevy_render/src/camera/active_cameras.rs | 2 +- crates/bevy_render/src/camera/mod.rs | 2 +- crates/bevy_render/src/color/mod.rs | 2 +- crates/bevy_render/src/mesh/mesh/mod.rs | 8 ++- crates/bevy_render/src/mesh/shape/mod.rs | 4 +- crates/bevy_render/src/render_asset.rs | 2 +- crates/bevy_render/src/render_graph/graph.rs | 4 +- .../src/render_phase/draw_state.rs | 12 ++--- .../bevy_render/src/render_resource/buffer.rs | 2 +- .../bevy_render/src/render_resource/shader.rs | 1 + .../bevy_render/src/renderer/render_device.rs | 11 ++-- .../src/texture/image_texture_loader.rs | 2 +- .../src/view/visibility/render_layers.rs | 4 +- crates/bevy_scene/src/dynamic_scene.rs | 4 +- crates/bevy_scene/src/scene_loader.rs | 2 +- crates/bevy_scene/src/scene_spawner.rs | 4 +- crates/bevy_scene/src/serde.rs | 2 +- crates/bevy_sprite/src/texture_atlas.rs | 2 +- .../bevy_sprite/src/texture_atlas_builder.rs | 3 +- crates/bevy_tasks/examples/busy_behavior.rs | 2 +- crates/bevy_tasks/examples/idle_behavior.rs | 2 +- crates/bevy_tasks/src/countdown_event.rs | 2 +- crates/bevy_tasks/src/iter/adapters.rs | 22 +++----- crates/bevy_tasks/src/iter/mod.rs | 4 +- crates/bevy_tasks/src/task_pool.rs | 1 + crates/bevy_text/src/font.rs | 3 +- crates/bevy_text/src/glyph_brush.rs | 2 +- crates/bevy_text/src/pipeline.rs | 2 +- .../src/components/global_transform.rs | 6 ++- .../src/components/transform.rs | 2 + crates/bevy_ui/src/render/mod.rs | 2 +- crates/bevy_ui/src/render/render_pass.rs | 2 +- crates/bevy_ui/src/update.rs | 2 +- crates/bevy_window/src/window.rs | 5 +- crates/bevy_winit/src/lib.rs | 11 ++-- examples/2d/many_sprites.rs | 2 +- examples/2d/texture_atlas.rs | 2 +- .../external_source_external_thread.rs | 2 +- examples/ecs/timers.rs | 4 +- examples/game/game_menu.rs | 8 +-- examples/reflection/reflection_types.rs | 2 +- .../shader/compute_shader_game_of_life.rs | 2 +- 99 files changed, 329 insertions(+), 304 deletions(-) diff --git a/crates/bevy_app/src/app.rs b/crates/bevy_app/src/app.rs index 734ef502ab..5bbb9b5676 100644 --- a/crates/bevy_app/src/app.rs +++ b/crates/bevy_app/src/app.rs @@ -373,9 +373,10 @@ impl App { system: impl IntoSystemDescriptor, ) -> &mut Self { use std::any::TypeId; - if stage_label.type_id() == TypeId::of::() { - panic!("add systems to a startup stage using App::add_startup_system_to_stage"); - } + assert!( + stage_label.type_id() != TypeId::of::(), + "add systems to a startup stage using App::add_startup_system_to_stage" + ); self.schedule.add_system_to_stage(stage_label, system); self } @@ -407,9 +408,10 @@ impl App { system_set: SystemSet, ) -> &mut Self { use std::any::TypeId; - if stage_label.type_id() == TypeId::of::() { - panic!("add system sets to a startup stage using App::add_startup_system_set_to_stage"); - } + assert!( + stage_label.type_id() != TypeId::of::(), + "add system sets to a startup stage using App::add_startup_system_set_to_stage" + ); self.schedule .add_system_set_to_stage(stage_label, system_set); self diff --git a/crates/bevy_asset/src/asset_server.rs b/crates/bevy_asset/src/asset_server.rs index fb01fed3b1..f77d677c89 100644 --- a/crates/bevy_asset/src/asset_server.rs +++ b/crates/bevy_asset/src/asset_server.rs @@ -355,11 +355,11 @@ impl AssetServer { }); // load asset dependencies and prepare asset type hashmap - for (label, loaded_asset) in load_context.labeled_assets.iter_mut() { + for (label, loaded_asset) in &mut load_context.labeled_assets { let label_id = LabelId::from(label.as_ref().map(|label| label.as_str())); let type_uuid = loaded_asset.value.as_ref().unwrap().type_uuid(); source_info.asset_types.insert(label_id, type_uuid); - for dependency in loaded_asset.dependencies.iter() { + for dependency in &loaded_asset.dependencies { self.load_untracked(dependency.clone(), false); } } @@ -484,7 +484,7 @@ impl AssetServer { fn create_assets_in_load_context(&self, load_context: &mut LoadContext) { let asset_lifecycles = self.server.asset_lifecycles.read(); - for (label, asset) in load_context.labeled_assets.iter_mut() { + for (label, asset) in &mut load_context.labeled_assets { let asset_value = asset .value .take() @@ -674,7 +674,7 @@ mod test { extensions == vec!["v1.2.3.pong", "2.3.pong", "3.pong", "pong"], _ => false, } - ) + ); } #[test] diff --git a/crates/bevy_asset/src/assets.rs b/crates/bevy_asset/src/assets.rs index 27d013588a..a74bb19155 100644 --- a/crates/bevy_asset/src/assets.rs +++ b/crates/bevy_asset/src/assets.rs @@ -216,14 +216,14 @@ impl Assets { /// /// Keeps the allocated memory for reuse. pub fn clear(&mut self) { - self.assets.clear() + self.assets.clear(); } /// Reserves capacity for at least additional more elements to be inserted into the assets. /// /// The collection may reserve more space to avoid frequent reallocations. pub fn reserve(&mut self, additional: usize) { - self.assets.reserve(additional) + self.assets.reserve(additional); } /// Shrinks the capacity of the asset map as much as possible. @@ -231,7 +231,7 @@ impl Assets { /// It will drop down as much as possible while maintaining the internal rules and possibly /// leaving some space in accordance with the resize policy. pub fn shrink_to_fit(&mut self) { - self.assets.shrink_to_fit() + self.assets.shrink_to_fit(); } pub fn asset_event_system( @@ -241,7 +241,7 @@ impl Assets { // Check if the events are empty before calling `drain`. // As `drain` triggers change detection. if !assets.events.is_empty() { - events.send_batch(assets.events.drain()) + events.send_batch(assets.events.drain()); } } @@ -331,6 +331,6 @@ mod tests { let handle = assets_before.add(MyAsset); app.add_asset::(); // Ensure this doesn't overwrite the Asset let assets_after = app.world.get_resource_mut::>().unwrap(); - assert!(assets_after.get(handle).is_some()) + assert!(assets_after.get(handle).is_some()); } } diff --git a/crates/bevy_asset/src/handle.rs b/crates/bevy_asset/src/handle.rs index d5287a2f17..06fdee6907 100644 --- a/crates/bevy_asset/src/handle.rs +++ b/crates/bevy_asset/src/handle.rs @@ -179,8 +179,9 @@ impl Handle { } #[inline] + #[must_use] pub fn clone_weak(&self) -> Self { - Handle::weak(self.id) + Self::weak(self.id) } pub fn clone_untyped(&self) -> HandleUntyped { @@ -327,8 +328,9 @@ impl HandleUntyped { } } - pub fn clone_weak(&self) -> HandleUntyped { - HandleUntyped::weak(self.id) + #[must_use] + pub fn clone_weak(&self) -> Self { + Self::weak(self.id) } pub fn is_weak(&self) -> bool { @@ -344,9 +346,10 @@ impl HandleUntyped { /// The new handle will maintain the Strong or Weak status of the current handle. pub fn typed(mut self) -> Handle { if let HandleId::Id(type_uuid, _) = self.id { - if T::TYPE_UUID != type_uuid { - panic!("Attempted to convert handle to invalid type."); - } + assert!( + T::TYPE_UUID == type_uuid, + "Attempted to convert handle to invalid type." + ); } let handle_type = match &self.handle_type { HandleType::Strong(sender) => HandleType::Strong(sender.clone()), diff --git a/crates/bevy_asset/src/io/file_asset_io.rs b/crates/bevy_asset/src/io/file_asset_io.rs index efe762b542..3888380805 100644 --- a/crates/bevy_asset/src/io/file_asset_io.rs +++ b/crates/bevy_asset/src/io/file_asset_io.rs @@ -155,7 +155,7 @@ pub fn filesystem_watcher_system(asset_server: Res) { .. } = event { - for path in paths.iter() { + for path in &paths { if !changed.contains(path) { let relative_path = path.strip_prefix(&asset_io.root_path).unwrap(); let _ = asset_server.load_untracked(relative_path.into(), true); diff --git a/crates/bevy_asset/src/loader.rs b/crates/bevy_asset/src/loader.rs index 7b665bf8be..ac68f3c6d0 100644 --- a/crates/bevy_asset/src/loader.rs +++ b/crates/bevy_asset/src/loader.rs @@ -47,11 +47,13 @@ impl LoadedAsset { self.dependencies.push(asset_path.to_owned()); } + #[must_use] pub fn with_dependency(mut self, asset_path: AssetPath) -> Self { self.add_dependency(asset_path); self } + #[must_use] pub fn with_dependencies(mut self, mut asset_paths: Vec>) -> Self { for asset_path in asset_paths.drain(..) { self.add_dependency(asset_path); @@ -132,7 +134,7 @@ impl<'a> LoadContext<'a> { pub fn get_asset_metas(&self) -> Vec { let mut asset_metas = Vec::new(); - for (label, asset) in self.labeled_assets.iter() { + for (label, asset) in &self.labeled_assets { asset_metas.push(AssetMeta { dependencies: asset.dependencies.clone(), label: label.clone(), @@ -182,7 +184,7 @@ impl AssetLifecycle for AssetLifecycleChannel { id, version, })) - .unwrap() + .unwrap(); } else { panic!( "Failed to downcast asset to {}.", diff --git a/crates/bevy_core/src/float_ord.rs b/crates/bevy_core/src/float_ord.rs index cd573ca5fc..7b265e2016 100644 --- a/crates/bevy_core/src/float_ord.rs +++ b/crates/bevy_core/src/float_ord.rs @@ -41,10 +41,10 @@ impl Hash for FloatOrd { fn hash(&self, state: &mut H) { if self.0.is_nan() { // Ensure all NaN representations hash to the same value - state.write(bytemuck::bytes_of(&f32::NAN)) + state.write(bytemuck::bytes_of(&f32::NAN)); } else if self.0 == 0.0 { // Ensure both zeroes hash to the same value - state.write(bytemuck::bytes_of(&0.0f32)) + state.write(bytemuck::bytes_of(&0.0f32)); } else { state.write(bytemuck::bytes_of(&self.0)); } diff --git a/crates/bevy_core/src/time/fixed_timestep.rs b/crates/bevy_core/src/time/fixed_timestep.rs index 7b773cbc69..bd3384d4ca 100644 --- a/crates/bevy_core/src/time/fixed_timestep.rs +++ b/crates/bevy_core/src/time/fixed_timestep.rs @@ -109,6 +109,7 @@ impl FixedTimestep { /// Sets the label for the timestep. Setting a label allows a timestep /// to be observed by the global [`FixedTimesteps`] resource. + #[must_use] pub fn with_label(mut self, label: &str) -> Self { self.state.label = Some(label.to_string()); self @@ -197,7 +198,7 @@ impl System for FixedTimestep { } fn apply_buffers(&mut self, world: &mut World) { - self.internal_system.apply_buffers(world) + self.internal_system.apply_buffers(world); } fn initialize(&mut self, world: &mut World) { diff --git a/crates/bevy_core/src/time/timer.rs b/crates/bevy_core/src/time/timer.rs index 6cc4fc9d98..3f34a9d799 100644 --- a/crates/bevy_core/src/time/timer.rs +++ b/crates/bevy_core/src/time/timer.rs @@ -180,7 +180,7 @@ impl Timer { self.stopwatch.reset(); self.finished = self.just_finished(); } - self.repeating = repeating + self.repeating = repeating; } /// Advance the timer by `delta` seconds. diff --git a/crates/bevy_core_pipeline/src/lib.rs b/crates/bevy_core_pipeline/src/lib.rs index f63aed7240..a00a4b734c 100644 --- a/crates/bevy_core_pipeline/src/lib.rs +++ b/crates/bevy_core_pipeline/src/lib.rs @@ -334,7 +334,7 @@ pub fn extract_clear_color(clear_color: Res, mut render_world: ResMu // If the clear color has changed if clear_color.is_changed() { // Update the clear color resource in the render world - render_world.insert_resource(clear_color.clone()) + render_world.insert_resource(clear_color.clone()); } } diff --git a/crates/bevy_core_pipeline/src/main_pass_2d.rs b/crates/bevy_core_pipeline/src/main_pass_2d.rs index 8195a64cec..b3ad74a059 100644 --- a/crates/bevy_core_pipeline/src/main_pass_2d.rs +++ b/crates/bevy_core_pipeline/src/main_pass_2d.rs @@ -63,7 +63,7 @@ impl Node for MainPass2dNode { let mut draw_functions = draw_functions.write(); let mut tracked_pass = TrackedRenderPass::new(render_pass); - for item in transparent_phase.items.iter() { + for item in &transparent_phase.items { let draw_function = draw_functions.get_mut(item.draw_function).unwrap(); draw_function.draw(world, &mut tracked_pass, view_entity, item); } diff --git a/crates/bevy_core_pipeline/src/main_pass_3d.rs b/crates/bevy_core_pipeline/src/main_pass_3d.rs index bd1e491fe8..ebbb178ac8 100644 --- a/crates/bevy_core_pipeline/src/main_pass_3d.rs +++ b/crates/bevy_core_pipeline/src/main_pass_3d.rs @@ -82,7 +82,7 @@ impl Node for MainPass3dNode { .begin_render_pass(&pass_descriptor); let mut draw_functions = draw_functions.write(); let mut tracked_pass = TrackedRenderPass::new(render_pass); - for item in opaque_phase.items.iter() { + for item in &opaque_phase.items { let draw_function = draw_functions.get_mut(item.draw_function).unwrap(); draw_function.draw(world, &mut tracked_pass, view_entity, item); } @@ -116,7 +116,7 @@ impl Node for MainPass3dNode { .begin_render_pass(&pass_descriptor); let mut draw_functions = draw_functions.write(); let mut tracked_pass = TrackedRenderPass::new(render_pass); - for item in alpha_mask_phase.items.iter() { + for item in &alpha_mask_phase.items { let draw_function = draw_functions.get_mut(item.draw_function).unwrap(); draw_function.draw(world, &mut tracked_pass, view_entity, item); } @@ -154,7 +154,7 @@ impl Node for MainPass3dNode { .begin_render_pass(&pass_descriptor); let mut draw_functions = draw_functions.write(); let mut tracked_pass = TrackedRenderPass::new(render_pass); - for item in transparent_phase.items.iter() { + for item in &transparent_phase.items { let draw_function = draw_functions.get_mut(item.draw_function).unwrap(); draw_function.draw(world, &mut tracked_pass, view_entity, item); } diff --git a/crates/bevy_derive/src/bevy_main.rs b/crates/bevy_derive/src/bevy_main.rs index 00a50b634f..4a2650f36c 100644 --- a/crates/bevy_derive/src/bevy_main.rs +++ b/crates/bevy_derive/src/bevy_main.rs @@ -4,9 +4,10 @@ use syn::{parse_macro_input, ItemFn}; pub fn bevy_main(_attr: TokenStream, item: TokenStream) -> TokenStream { let input = parse_macro_input!(item as ItemFn); - if input.sig.ident != "main" { - panic!("`bevy_main` can only be used on a function called 'main'.") - } + assert!( + input.sig.ident == "main", + "`bevy_main` can only be used on a function called 'main'.", + ); TokenStream::from(quote! { #[no_mangle] diff --git a/crates/bevy_derive/src/lib.rs b/crates/bevy_derive/src/lib.rs index 98990c11c8..cd0da4668e 100644 --- a/crates/bevy_derive/src/lib.rs +++ b/crates/bevy_derive/src/lib.rs @@ -30,5 +30,5 @@ pub fn derive_app_label(input: TokenStream) -> TokenStream { let input = syn::parse_macro_input!(input as syn::DeriveInput); let mut trait_path = BevyManifest::default().get_path("bevy_app"); trait_path.segments.push(format_ident!("AppLabel").into()); - derive_label(input, trait_path) + derive_label(input, &trait_path) } diff --git a/crates/bevy_diagnostic/src/diagnostic.rs b/crates/bevy_diagnostic/src/diagnostic.rs index 05b08045d1..ba8d1a0c04 100644 --- a/crates/bevy_diagnostic/src/diagnostic.rs +++ b/crates/bevy_diagnostic/src/diagnostic.rs @@ -65,7 +65,7 @@ impl Diagnostic { "Diagnostic {:?} has name longer than {} characters, and so might overflow in the LogDiagnosticsPlugin\ Consider using a shorter name.", name, MAX_DIAGNOSTIC_NAME_WIDTH - ) + ); } Diagnostic { id, @@ -77,6 +77,7 @@ impl Diagnostic { } } + #[must_use] pub fn with_suffix(mut self, suffix: impl Into>) -> Self { self.suffix = suffix.into(); self diff --git a/crates/bevy_ecs/macros/src/component.rs b/crates/bevy_ecs/macros/src/component.rs index ab1e52bdb8..440fe31468 100644 --- a/crates/bevy_ecs/macros/src/component.rs +++ b/crates/bevy_ecs/macros/src/component.rs @@ -13,7 +13,7 @@ pub fn derive_component(input: TokenStream) -> TokenStream { Err(e) => return e.into_compile_error().into(), }; - let storage = storage_path(bevy_ecs_path.clone(), attrs.storage); + let storage = storage_path(&bevy_ecs_path, attrs.storage); ast.generics .make_where_clause() @@ -96,7 +96,7 @@ fn parse_component_attr(ast: &DeriveInput) -> Result { Ok(attrs) } -fn storage_path(bevy_ecs_path: Path, ty: StorageTy) -> TokenStream2 { +fn storage_path(bevy_ecs_path: &Path, ty: StorageTy) -> TokenStream2 { let typename = match ty { StorageTy::Table => Ident::new("TableStorage", Span::call_site()), StorageTy::SparseSet => Ident::new("SparseStorage", Span::call_site()), diff --git a/crates/bevy_ecs/macros/src/lib.rs b/crates/bevy_ecs/macros/src/lib.rs index ca5a6b17bf..3237ca64f5 100644 --- a/crates/bevy_ecs/macros/src/lib.rs +++ b/crates/bevy_ecs/macros/src/lib.rs @@ -433,7 +433,7 @@ pub fn derive_system_label(input: TokenStream) -> TokenStream { trait_path .segments .push(format_ident!("SystemLabel").into()); - derive_label(input, trait_path) + derive_label(input, &trait_path) } #[proc_macro_derive(StageLabel)] @@ -442,7 +442,7 @@ pub fn derive_stage_label(input: TokenStream) -> TokenStream { let mut trait_path = bevy_ecs_path(); trait_path.segments.push(format_ident!("schedule").into()); trait_path.segments.push(format_ident!("StageLabel").into()); - derive_label(input, trait_path) + derive_label(input, &trait_path) } #[proc_macro_derive(AmbiguitySetLabel)] @@ -453,7 +453,7 @@ pub fn derive_ambiguity_set_label(input: TokenStream) -> TokenStream { trait_path .segments .push(format_ident!("AmbiguitySetLabel").into()); - derive_label(input, trait_path) + derive_label(input, &trait_path) } #[proc_macro_derive(RunCriteriaLabel)] @@ -464,7 +464,7 @@ pub fn derive_run_criteria_label(input: TokenStream) -> TokenStream { trait_path .segments .push(format_ident!("RunCriteriaLabel").into()); - derive_label(input, trait_path) + derive_label(input, &trait_path) } pub(crate) fn bevy_ecs_path() -> syn::Path { diff --git a/crates/bevy_ecs/src/archetype.rs b/crates/bevy_ecs/src/archetype.rs index ca9d62cb46..cb5cfba3ab 100644 --- a/crates/bevy_ecs/src/archetype.rs +++ b/crates/bevy_ecs/src/archetype.rs @@ -520,7 +520,7 @@ impl Archetypes { } pub fn clear_entities(&mut self) { - for archetype in self.archetypes.iter_mut() { + for archetype in &mut self.archetypes { archetype.clear_entities(); } } diff --git a/crates/bevy_ecs/src/bundle.rs b/crates/bevy_ecs/src/bundle.rs index 3bf6881eb3..5700b2aabd 100644 --- a/crates/bevy_ecs/src/bundle.rs +++ b/crates/bevy_ecs/src/bundle.rs @@ -489,7 +489,7 @@ impl<'a, 'b> BundleInserter<'a, 'b> { { &mut *self.archetype } else if new_archetype.id() == swapped_location.archetype_id { - &mut *new_archetype + new_archetype } else { // SAFE: the only two borrowed archetypes are above and we just did collision checks &mut *self @@ -630,9 +630,11 @@ unsafe fn initialize_bundle( let mut deduped = component_ids.clone(); deduped.sort(); deduped.dedup(); - if deduped.len() != component_ids.len() { - panic!("Bundle {} has duplicate components", bundle_type_name); - } + assert!( + deduped.len() == component_ids.len(), + "Bundle {} has duplicate components", + bundle_type_name + ); BundleInfo { id, diff --git a/crates/bevy_ecs/src/component.rs b/crates/bevy_ecs/src/component.rs index ff970e69ab..ebb9896a60 100644 --- a/crates/bevy_ecs/src/component.rs +++ b/crates/bevy_ecs/src/component.rs @@ -179,7 +179,7 @@ pub struct ComponentDescriptor { impl ComponentDescriptor { // SAFETY: The pointer points to a valid value of type `T` and it is safe to drop this value. unsafe fn drop_ptr(x: *mut u8) { - x.cast::().drop_in_place() + x.cast::().drop_in_place(); } pub fn new() -> Self { diff --git a/crates/bevy_ecs/src/entity/mod.rs b/crates/bevy_ecs/src/entity/mod.rs index 75ee18ee49..cedfdbafca 100644 --- a/crates/bevy_ecs/src/entity/mod.rs +++ b/crates/bevy_ecs/src/entity/mod.rs @@ -540,7 +540,7 @@ impl Entities { unsafe { self.flush(|_entity, location| { location.archetype_id = ArchetypeId::INVALID; - }) + }); } } @@ -612,7 +612,7 @@ mod tests { unsafe { entities.flush(|_entity, _location| { // do nothing ... leaving entity location invalid - }) + }); }; assert!(entities.contains(e)); diff --git a/crates/bevy_ecs/src/event.rs b/crates/bevy_ecs/src/event.rs index 1b78f2229f..7147a275dd 100644 --- a/crates/bevy_ecs/src/event.rs +++ b/crates/bevy_ecs/src/event.rs @@ -250,8 +250,8 @@ fn internal_event_reader<'a, T>( } else { 0 }; - let a = events.events_a.get(a_index..).unwrap_or_else(|| &[]); - let b = events.events_b.get(b_index..).unwrap_or_else(|| &[]); + let a = events.events_a.get(a_index..).unwrap_or_default(); + let b = events.events_b.get(b_index..).unwrap_or_default(); let unread_count = a.len() + b.len(); *last_event_count = events.event_count - unread_count; let iterator = match events.state { diff --git a/crates/bevy_ecs/src/lib.rs b/crates/bevy_ecs/src/lib.rs index d48ea55929..eea47ce304 100644 --- a/crates/bevy_ecs/src/lib.rs +++ b/crates/bevy_ecs/src/lib.rs @@ -382,7 +382,7 @@ mod tests { world .query::<(Entity, &A)>() .par_for_each(&world, &task_pool, 2, |(e, &A(i))| { - results.lock().push((e, i)) + results.lock().push((e, i)); }); results.lock().sort(); assert_eq!( diff --git a/crates/bevy_ecs/src/query/access.rs b/crates/bevy_ecs/src/query/access.rs index 328df83834..1de838ae01 100644 --- a/crates/bevy_ecs/src/query/access.rs +++ b/crates/bevy_ecs/src/query/access.rs @@ -212,7 +212,7 @@ impl FilteredAccessSet { // if combined unfiltered access is incompatible, check each filtered access for // compatibility if !filtered_access.access.is_compatible(&self.combined_access) { - for current_filtered_access in self.filtered_accesses.iter() { + for current_filtered_access in &self.filtered_accesses { if !current_filtered_access.is_compatible(filtered_access) { return current_filtered_access .access diff --git a/crates/bevy_ecs/src/query/fetch.rs b/crates/bevy_ecs/src/query/fetch.rs index 5c3ed28038..8324da9bc9 100644 --- a/crates/bevy_ecs/src/query/fetch.rs +++ b/crates/bevy_ecs/src/query/fetch.rs @@ -250,11 +250,12 @@ unsafe impl FetchState for ReadState { } fn update_component_access(&self, access: &mut FilteredAccess) { - if access.access().has_write(self.component_id) { - panic!("&{} conflicts with a previous access in this query. Shared access cannot coincide with exclusive access.", - std::any::type_name::()); - } - access.add_read(self.component_id) + assert!( + !access.access().has_write(self.component_id), + "&{} conflicts with a previous access in this query. Shared access cannot coincide with exclusive access.", + std::any::type_name::(), + ); + access.add_read(self.component_id); } fn update_archetype_component_access( @@ -452,10 +453,11 @@ unsafe impl FetchState for WriteState { } fn update_component_access(&self, access: &mut FilteredAccess) { - if access.access().has_read(self.component_id) { - panic!("&mut {} conflicts with a previous access in this query. Mutable component access must be unique.", - std::any::type_name::()); - } + assert!( + !access.access().has_read(self.component_id), + "&mut {} conflicts with a previous access in this query. Mutable component access must be unique.", + std::any::type_name::(), + ); access.add_write(self.component_id); } @@ -551,7 +553,7 @@ impl<'w, 's, T: Component> Fetch<'w, 's> for WriteFetch { Mut { value: &mut *self.table_components.as_ptr().add(table_row), ticks: Ticks { - component_ticks: &mut *(&*self.table_ticks.add(table_row)).get(), + component_ticks: &mut *(*self.table_ticks.add(table_row)).get(), change_tick: self.change_tick, last_change_tick: self.last_change_tick, }, @@ -578,7 +580,7 @@ impl<'w, 's, T: Component> Fetch<'w, 's> for WriteFetch { Mut { value: &mut *self.table_components.as_ptr().add(table_row), ticks: Ticks { - component_ticks: &mut *(&*self.table_ticks.add(table_row)).get(), + component_ticks: &mut *(*self.table_ticks.add(table_row)).get(), change_tick: self.change_tick, last_change_tick: self.last_change_tick, }, @@ -705,7 +707,7 @@ unsafe impl FetchState for OptionState { ) { if self.state.matches_archetype(archetype) { self.state - .update_archetype_component_access(archetype, access) + .update_archetype_component_access(archetype, access); } } @@ -864,11 +866,12 @@ unsafe impl FetchState for ChangeTrackersState { } fn update_component_access(&self, access: &mut FilteredAccess) { - if access.access().has_write(self.component_id) { - panic!("ChangeTrackers<{}> conflicts with a previous access in this query. Shared access cannot coincide with exclusive access.", - std::any::type_name::()); - } - access.add_read(self.component_id) + assert!( + !access.access().has_write(self.component_id), + "ChangeTrackers<{}> conflicts with a previous access in this query. Shared access cannot coincide with exclusive access.", + std::any::type_name::() + ); + access.add_read(self.component_id); } fn update_archetype_component_access( @@ -989,7 +992,7 @@ impl<'w, 's, T: Component> Fetch<'w, 's> for ChangeTrackersFetch { StorageType::Table => { let table_row = *self.entity_table_rows.add(archetype_index); ChangeTrackers { - component_ticks: (&*self.table_ticks.add(table_row)).clone(), + component_ticks: (*self.table_ticks.add(table_row)).clone(), marker: PhantomData, last_change_tick: self.last_change_tick, change_tick: self.change_tick, @@ -998,7 +1001,7 @@ impl<'w, 's, T: Component> Fetch<'w, 's> for ChangeTrackersFetch { StorageType::SparseSet => { let entity = *self.entities.add(archetype_index); ChangeTrackers { - component_ticks: (&*self.sparse_set).get_ticks(entity).cloned().unwrap(), + component_ticks: (*self.sparse_set).get_ticks(entity).cloned().unwrap(), marker: PhantomData, last_change_tick: self.last_change_tick, change_tick: self.change_tick, @@ -1010,7 +1013,7 @@ impl<'w, 's, T: Component> Fetch<'w, 's> for ChangeTrackersFetch { #[inline] unsafe fn table_fetch(&mut self, table_row: usize) -> Self::Item { ChangeTrackers { - component_ticks: (&*self.table_ticks.add(table_row)).clone(), + component_ticks: (*self.table_ticks.add(table_row)).clone(), marker: PhantomData, last_change_tick: self.last_change_tick, change_tick: self.change_tick, diff --git a/crates/bevy_ecs/src/query/state.rs b/crates/bevy_ecs/src/query/state.rs index c13b0dc757..f675de4d89 100644 --- a/crates/bevy_ecs/src/query/state.rs +++ b/crates/bevy_ecs/src/query/state.rs @@ -101,10 +101,11 @@ where #[inline] pub fn validate_world(&self, world: &World) { - if world.id() != self.world_id { - panic!("Attempted to use {} with a mismatched World. QueryStates can only be used with the World they were created from.", - std::any::type_name::()); - } + assert!( + world.id() == self.world_id, + "Attempted to use {} with a mismatched World. QueryStates can only be used with the World they were created from.", + std::any::type_name::(), + ); } /// Creates a new [`Archetype`]. @@ -604,7 +605,7 @@ where ::init(world, &self.filter_state, last_change_tick, change_tick); if Q::Fetch::IS_DENSE && F::Fetch::IS_DENSE { let tables = &world.storages().tables; - for table_id in self.matched_table_ids.iter() { + for table_id in &self.matched_table_ids { let table = &tables[*table_id]; fetch.set_table(&self.fetch_state, table); filter.set_table(&self.filter_state, table); @@ -620,7 +621,7 @@ where } else { let archetypes = &world.archetypes; let tables = &world.storages().tables; - for archetype_id in self.matched_archetype_ids.iter() { + for archetype_id in &self.matched_archetype_ids { let archetype = &archetypes[*archetype_id]; fetch.set_archetype(&self.fetch_state, archetype, tables); filter.set_archetype(&self.filter_state, archetype, tables); @@ -664,7 +665,7 @@ where task_pool.scope(|scope| { if QF::IS_DENSE && F::Fetch::IS_DENSE { let tables = &world.storages().tables; - for table_id in self.matched_table_ids.iter() { + for table_id in &self.matched_table_ids { let table = &tables[*table_id]; let mut offset = 0; while offset < table.len() { @@ -696,7 +697,7 @@ where } } else { let archetypes = &world.archetypes; - for archetype_id in self.matched_archetype_ids.iter() { + for archetype_id in &self.matched_archetype_ids { let mut offset = 0; let archetype = &archetypes[*archetype_id]; while offset < archetype.len() { diff --git a/crates/bevy_ecs/src/schedule/executor_parallel.rs b/crates/bevy_ecs/src/schedule/executor_parallel.rs index c0acb5cbcf..5545f80ed6 100644 --- a/crates/bevy_ecs/src/schedule/executor_parallel.rs +++ b/crates/bevy_ecs/src/schedule/executor_parallel.rs @@ -373,7 +373,7 @@ mod tests { assert_eq!( receive_events(&world), vec![StartedSystems(3), StartedSystems(3),] - ) + ); } #[test] diff --git a/crates/bevy_ecs/src/schedule/mod.rs b/crates/bevy_ecs/src/schedule/mod.rs index 605efe4654..192dd00cb8 100644 --- a/crates/bevy_ecs/src/schedule/mod.rs +++ b/crates/bevy_ecs/src/schedule/mod.rs @@ -45,12 +45,14 @@ pub struct Schedule { impl Schedule { /// Similar to [`add_stage`](Self::add_stage), but it also returns itself. + #[must_use] pub fn with_stage(mut self, label: impl StageLabel, stage: S) -> Self { self.add_stage(label, stage); self } /// Similar to [`add_stage_after`](Self::add_stage_after), but it also returns itself. + #[must_use] pub fn with_stage_after( mut self, target: impl StageLabel, @@ -62,6 +64,7 @@ impl Schedule { } /// Similar to [`add_stage_before`](Self::add_stage_before), but it also returns itself. + #[must_use] pub fn with_stage_before( mut self, target: impl StageLabel, @@ -72,12 +75,14 @@ impl Schedule { self } + #[must_use] pub fn with_run_criteria>(mut self, system: S) -> Self { self.set_run_criteria(system); self } /// Similar to [`add_system_to_stage`](Self::add_system_to_stage), but it also returns itself. + #[must_use] pub fn with_system_in_stage( mut self, stage_label: impl StageLabel, @@ -109,9 +114,7 @@ impl Schedule { let label: Box = Box::new(label); self.stage_order.push(label.clone()); let prev = self.stages.insert(label.clone(), Box::new(stage)); - if prev.is_some() { - panic!("Stage already exists: {:?}.", label); - } + assert!(prev.is_none(), "Stage already exists: {:?}.", label); self } @@ -144,9 +147,7 @@ impl Schedule { self.stage_order.insert(target_index + 1, label.clone()); let prev = self.stages.insert(label.clone(), Box::new(stage)); - if prev.is_some() { - panic!("Stage already exists: {:?}.", label); - } + assert!(prev.is_none(), "Stage already exists: {:?}.", label); self } @@ -180,9 +181,7 @@ impl Schedule { self.stage_order.insert(target_index, label.clone()); let prev = self.stages.insert(label.clone(), Box::new(stage)); - if prev.is_some() { - panic!("Stage already exists: {:?}.", label); - } + assert!(prev.is_none(), "Stage already exists: {:?}.", label); self } @@ -335,7 +334,7 @@ impl Schedule { /// Executes each [`Stage`] contained in the schedule, one at a time. pub fn run_once(&mut self, world: &mut World) { - for label in self.stage_order.iter() { + for label in &self.stage_order { #[cfg(feature = "trace")] let stage_span = bevy_utils::tracing::info_span!("stage", name = ?label); #[cfg(feature = "trace")] diff --git a/crates/bevy_ecs/src/schedule/stage.rs b/crates/bevy_ecs/src/schedule/stage.rs index 96be9bf174..825105bf04 100644 --- a/crates/bevy_ecs/src/schedule/stage.rs +++ b/crates/bevy_ecs/src/schedule/stage.rs @@ -137,6 +137,7 @@ impl SystemStage { self.executor = executor; } + #[must_use] pub fn with_system(mut self, system: impl IntoSystemDescriptor) -> Self { self.add_system(system); self @@ -208,7 +209,7 @@ impl SystemStage { } pub fn apply_buffers(&mut self, world: &mut World) { - for container in self.parallel.iter_mut() { + for container in &mut self.parallel { let system = container.system_mut(); #[cfg(feature = "trace")] let span = bevy_utils::tracing::info_span!("system_commands", name = &*system.name()); @@ -251,6 +252,7 @@ impl SystemStage { &self.exclusive_before_commands } + #[must_use] pub fn with_system_set(mut self, system_set: SystemSet) -> Self { self.add_system_set(system_set); self @@ -261,7 +263,7 @@ impl SystemStage { let (run_criteria, mut systems) = system_set.bake(); let set_run_criteria_index = run_criteria.and_then(|criteria| { // validate that no systems have criteria - for system in systems.iter_mut() { + for system in &mut systems { if let Some(name) = match system { SystemDescriptor::Exclusive(descriptor) => descriptor .run_criteria @@ -285,15 +287,15 @@ impl SystemStage { Some(self.add_run_criteria_internal(descriptor)) } RunCriteriaDescriptorOrLabel::Label(label) => { - for system in systems.iter_mut() { + for system in &mut systems { match system { SystemDescriptor::Exclusive(descriptor) => { descriptor.run_criteria = - Some(RunCriteriaDescriptorOrLabel::Label(label.clone())) + Some(RunCriteriaDescriptorOrLabel::Label(label.clone())); } SystemDescriptor::Parallel(descriptor) => { descriptor.run_criteria = - Some(RunCriteriaDescriptorOrLabel::Label(label.clone())) + Some(RunCriteriaDescriptorOrLabel::Label(label.clone())); } } } @@ -308,6 +310,7 @@ impl SystemStage { self } + #[must_use] pub fn with_run_criteria>( mut self, system: S, @@ -325,6 +328,7 @@ impl SystemStage { self } + #[must_use] pub fn with_system_run_criteria(mut self, run_criteria: RunCriteriaDescriptor) -> Self { self.add_system_run_criteria(run_criteria); self @@ -612,7 +616,7 @@ impl SystemStage { .map(|label| (label.clone(), order_inverted[index].0)) }) .collect(); - for criteria in self.run_criteria.iter_mut() { + for criteria in &mut self.run_criteria { if let RunCriteriaInner::Piped { input: parent, .. } = &mut criteria.inner { let label = &criteria.after[0]; *parent = *labels.get(label).unwrap_or_else(|| { @@ -745,7 +749,7 @@ fn find_ambiguities(systems: &[impl SystemContainer]) -> Vec<(usize, usize, Vec< if let (Some(a), Some(b)) = (a_access, b_access) { let conflicts = a.get_conflicts(b); if !conflicts.is_empty() { - ambiguities.push((index_a, index_b, conflicts)) + ambiguities.push((index_a, index_b, conflicts)); } } else { ambiguities.push((index_a, index_b, Vec::new())); @@ -909,7 +913,7 @@ impl Stage for SystemStage { ShouldRun::YesAndCheckAgain | ShouldRun::NoAndCheckAgain => { match &mut criteria.inner { RunCriteriaInner::Single(system) => { - criteria.should_run = system.run((), world) + criteria.should_run = system.run((), world); } RunCriteriaInner::Piped { input: parent, @@ -917,7 +921,7 @@ impl Stage for SystemStage { .. } => { criteria.should_run = - system.run(run_criteria[*parent].should_run, world) + system.run(run_criteria[*parent].should_run, world); } } match criteria.should_run { @@ -1395,7 +1399,7 @@ mod tests { .with_system(make_parallel(4).label("4").after("3")) .with_system(make_parallel(3).label("3").after("2").before("4")); stage.run(&mut world); - for container in stage.parallel.iter() { + for container in &stage.parallel { assert!(container.dependencies().len() <= 1); } stage.set_executor(Box::new(SingleThreadedExecutor::default())); @@ -2092,7 +2096,7 @@ mod tests { // just wrapped over (u32::MAX / 2, 0, vec![ids[0], ids[3], ids[4]]), ]; - for (last_change_tick, change_tick, changed_entities) in test_cases.iter() { + for (last_change_tick, change_tick, changed_entities) in &test_cases { *world.change_tick.get_mut() = *change_tick; world.last_change_tick = *last_change_tick; diff --git a/crates/bevy_ecs/src/schedule/system_set.rs b/crates/bevy_ecs/src/schedule/system_set.rs index 0702445c79..5e32c2e48d 100644 --- a/crates/bevy_ecs/src/schedule/system_set.rs +++ b/crates/bevy_ecs/src/schedule/system_set.rs @@ -70,31 +70,37 @@ impl SystemSet { Self::new().with_run_criteria(State::::on_resume(s)) } + #[must_use] pub fn in_ambiguity_set(mut self, set: impl AmbiguitySetLabel) -> Self { self.ambiguity_sets.push(Box::new(set)); self } + #[must_use] pub fn with_system(mut self, system: impl IntoSystemDescriptor) -> Self { self.systems.push(system.into_descriptor()); self } + #[must_use] pub fn with_run_criteria(mut self, run_criteria: impl IntoRunCriteria) -> Self { self.run_criteria = Some(run_criteria.into()); self } + #[must_use] pub fn label(mut self, label: impl SystemLabel) -> Self { self.labels.push(Box::new(label)); self } + #[must_use] pub fn before(mut self, label: impl SystemLabel) -> Self { self.before.push(Box::new(label)); self } + #[must_use] pub fn after(mut self, label: impl SystemLabel) -> Self { self.after.push(Box::new(label)); self diff --git a/crates/bevy_ecs/src/storage/blob_vec.rs b/crates/bevy_ecs/src/storage/blob_vec.rs index ac2e61e274..6188baf5fe 100644 --- a/crates/bevy_ecs/src/storage/blob_vec.rs +++ b/crates/bevy_ecs/src/storage/blob_vec.rs @@ -180,7 +180,7 @@ impl BlobVec { pub unsafe fn swap_remove_and_drop_unchecked(&mut self, index: usize) { debug_assert!(index < self.len()); let value = self.swap_remove_and_forget_unchecked(index); - (self.drop)(value) + (self.drop)(value); } /// # Safety @@ -291,7 +291,7 @@ mod tests { // SAFETY: The pointer points to a valid value of type `T` and it is safe to drop this value. unsafe fn drop_ptr(x: *mut u8) { - x.cast::().drop_in_place() + x.cast::().drop_in_place(); } /// # Safety diff --git a/crates/bevy_ecs/src/storage/sparse_set.rs b/crates/bevy_ecs/src/storage/sparse_set.rs index 0b4efbe9bf..506987a0eb 100644 --- a/crates/bevy_ecs/src/storage/sparse_set.rs +++ b/crates/bevy_ecs/src/storage/sparse_set.rs @@ -466,7 +466,7 @@ mod tests { { let iter_results = set.values().collect::>(); - assert_eq!(iter_results, vec![&Foo(1), &Foo(2), &Foo(3)]) + assert_eq!(iter_results, vec![&Foo(1), &Foo(2), &Foo(3)]); } assert_eq!(set.remove(e2), Some(Foo(2))); diff --git a/crates/bevy_ecs/src/storage/table.rs b/crates/bevy_ecs/src/storage/table.rs index afa5375c62..7925011315 100644 --- a/crates/bevy_ecs/src/storage/table.rs +++ b/crates/bevy_ecs/src/storage/table.rs @@ -221,7 +221,7 @@ impl Table { self.columns.insert( component_info.id(), Column::with_capacity(component_info, self.entities.capacity()), - ) + ); } /// Removes the entity at the given row and returns the entity swapped in to replace it (if an @@ -495,13 +495,13 @@ impl Tables { } pub fn clear(&mut self) { - for table in self.tables.iter_mut() { + for table in &mut self.tables { table.clear(); } } pub(crate) fn check_change_ticks(&mut self, change_tick: u32) { - for table in self.tables.iter_mut() { + for table in &mut self.tables { table.check_change_ticks(change_tick); } } @@ -541,7 +541,7 @@ mod tests { let mut table = Table::with_capacity(0, columns.len()); table.add_column(components.get_info(component_id).unwrap()); let entities = (0..200).map(Entity::from_raw).collect::>(); - for entity in entities.iter() { + for entity in &entities { // SAFE: we allocate and immediately set data afterwards unsafe { let row = table.allocate(*entity); diff --git a/crates/bevy_ecs/src/system/commands/mod.rs b/crates/bevy_ecs/src/system/commands/mod.rs index ad237367b0..7d3f541dab 100644 --- a/crates/bevy_ecs/src/system/commands/mod.rs +++ b/crates/bevy_ecs/src/system/commands/mod.rs @@ -107,7 +107,7 @@ impl<'w, 's> Commands<'w, 's> { /// Spawns a [`Bundle`] without pre-allocating an [`Entity`]. The [`Entity`] will be allocated /// when this [`Command`] is applied. pub fn spawn_and_forget(&mut self, bundle: impl Bundle) { - self.queue.push(Spawn { bundle }) + self.queue.push(Spawn { bundle }); } /// Creates a new entity with the components contained in `bundle`. @@ -292,7 +292,7 @@ impl<'w, 's> Commands<'w, 's> { pub fn init_resource(&mut self) { self.queue.push(InitResource:: { _phantom: PhantomData::::default(), - }) + }); } /// Inserts a resource to the [`World`], overwriting any previous value of the same type. @@ -320,7 +320,7 @@ impl<'w, 's> Commands<'w, 's> { /// # bevy_ecs::system::assert_is_system(system); /// ``` pub fn insert_resource(&mut self, resource: R) { - self.queue.push(InsertResource { resource }) + self.queue.push(InsertResource { resource }); } /// Removes a resource from the [`World`]. @@ -571,7 +571,7 @@ impl<'w, 's, 'a> EntityCommands<'w, 's, 'a> { pub fn despawn(&mut self) { self.commands.add(Despawn { entity: self.entity, - }) + }); } /// Returns the underlying [`Commands`]. @@ -585,7 +585,7 @@ where F: FnOnce(&mut World) + Send + Sync + 'static, { fn write(self, world: &mut World) { - self(world) + self(world); } } diff --git a/crates/bevy_ecs/src/system/function_system.rs b/crates/bevy_ecs/src/system/function_system.rs index 4bb0f8db5c..36835c1d90 100644 --- a/crates/bevy_ecs/src/system/function_system.rs +++ b/crates/bevy_ecs/src/system/function_system.rs @@ -353,6 +353,7 @@ impl FunctionSystem::Config), diff --git a/crates/bevy_ecs/src/system/mod.rs b/crates/bevy_ecs/src/system/mod.rs index 738c312c40..1d489d6f97 100644 --- a/crates/bevy_ecs/src/system/mod.rs +++ b/crates/bevy_ecs/src/system/mod.rs @@ -364,27 +364,27 @@ mod tests { #[should_panic] fn conflicting_system_resources() { fn sys(_: ResMut, _: Res) {} - test_for_conflicting_resources(sys) + test_for_conflicting_resources(sys); } #[test] #[should_panic] fn conflicting_system_resources_reverse_order() { fn sys(_: Res, _: ResMut) {} - test_for_conflicting_resources(sys) + test_for_conflicting_resources(sys); } #[test] #[should_panic] fn conflicting_system_resources_multiple_mutable() { fn sys(_: ResMut, _: ResMut) {} - test_for_conflicting_resources(sys) + test_for_conflicting_resources(sys); } #[test] fn nonconflicting_system_resources() { fn sys(_: Local, _: ResMut, _: Local, _: ResMut) {} - test_for_conflicting_resources(sys) + test_for_conflicting_resources(sys); } #[test] @@ -564,7 +564,7 @@ mod tests { let bundle_info = bundles.get(bundle_id).unwrap(); let mut bundle_components = bundle_info.components().to_vec(); bundle_components.sort(); - for component_id in bundle_components.iter() { + for component_id in &bundle_components { assert!( components.get_info(*component_id).is_some(), "every bundle component exists in Components" diff --git a/crates/bevy_ecs/src/system/query.rs b/crates/bevy_ecs/src/system/query.rs index 4e911319a0..df1098fd71 100644 --- a/crates/bevy_ecs/src/system/query.rs +++ b/crates/bevy_ecs/src/system/query.rs @@ -464,7 +464,7 @@ where f, self.last_change_tick, self.change_tick, - ) + ); }; } @@ -499,7 +499,7 @@ where f, self.last_change_tick, self.change_tick, - ) + ); }; } @@ -525,7 +525,7 @@ where f, self.last_change_tick, self.change_tick, - ) + ); }; } @@ -547,7 +547,7 @@ where f, self.last_change_tick, self.change_tick, - ) + ); }; } diff --git a/crates/bevy_ecs/src/system/system_param.rs b/crates/bevy_ecs/src/system/system_param.rs index 7ed59883eb..9bc4b22efd 100644 --- a/crates/bevy_ecs/src/system/system_param.rs +++ b/crates/bevy_ecs/src/system/system_param.rs @@ -299,11 +299,12 @@ unsafe impl SystemParamState for ResState { fn init(world: &mut World, system_meta: &mut SystemMeta, _config: Self::Config) -> Self { let component_id = world.initialize_resource::(); let combined_access = system_meta.component_access_set.combined_access_mut(); - if combined_access.has_write(component_id) { - panic!( - "error[B0002]: Res<{}> in system {} conflicts with a previous ResMut<{0}> access. Consider removing the duplicate access.", - std::any::type_name::(), system_meta.name); - } + assert!( + !combined_access.has_write(component_id), + "error[B0002]: Res<{}> in system {} conflicts with a previous ResMut<{0}> access. Consider removing the duplicate access.", + std::any::type_name::(), + system_meta.name, + ); combined_access.add_read(component_id); let resource_archetype = world.archetypes.resource(); @@ -863,11 +864,12 @@ unsafe impl SystemParamState for NonSendState { let component_id = world.initialize_non_send_resource::(); let combined_access = system_meta.component_access_set.combined_access_mut(); - if combined_access.has_write(component_id) { - panic!( - "error[B0002]: NonSend<{}> in system {} conflicts with a previous mutable resource access ({0}). Consider removing the duplicate access.", - std::any::type_name::(), system_meta.name); - } + assert!( + !combined_access.has_write(component_id), + "error[B0002]: NonSend<{}> in system {} conflicts with a previous mutable resource access ({0}). Consider removing the duplicate access.", + std::any::type_name::(), + system_meta.name, + ); combined_access.add_read(component_id); let resource_archetype = world.archetypes.resource(); diff --git a/crates/bevy_ecs/src/world/entity_ref.rs b/crates/bevy_ecs/src/world/entity_ref.rs index eda55333fb..a9e9cd56b6 100644 --- a/crates/bevy_ecs/src/world/entity_ref.rs +++ b/crates/bevy_ecs/src/world/entity_ref.rs @@ -391,7 +391,7 @@ impl<'w> EntityMut<'w> { archetypes, storages, new_archetype_id, - ) + ); } } @@ -722,7 +722,7 @@ fn sorted_remove(source: &mut Vec, remove: &[T]) { } else { true } - }) + }); } #[cfg(test)] diff --git a/crates/bevy_ecs/src/world/mod.rs b/crates/bevy_ecs/src/world/mod.rs index d1404c9df2..ad037819e8 100644 --- a/crates/bevy_ecs/src/world/mod.rs +++ b/crates/bevy_ecs/src/world/mod.rs @@ -897,24 +897,21 @@ impl World { }; } AllocAtWithoutReplacement::DidNotExist => { - match spawn_or_insert { - SpawnOrInsert::Spawn(ref mut spawner) => { - // SAFE: `entity` is allocated (but non existent), bundle matches inserter - unsafe { spawner.spawn_non_existent(entity, bundle) }; - } - _ => { - let mut spawner = bundle_info.get_bundle_spawner( - &mut self.entities, - &mut self.archetypes, - &mut self.components, - &mut self.storages, - change_tick, - ); - // SAFE: `entity` is valid, `location` matches entity, bundle matches inserter - unsafe { spawner.spawn_non_existent(entity, bundle) }; - spawn_or_insert = SpawnOrInsert::Spawn(spawner); - } - }; + if let SpawnOrInsert::Spawn(ref mut spawner) = spawn_or_insert { + // SAFE: `entity` is allocated (but non existent), bundle matches inserter + unsafe { spawner.spawn_non_existent(entity, bundle) }; + } else { + let mut spawner = bundle_info.get_bundle_spawner( + &mut self.entities, + &mut self.archetypes, + &mut self.components, + &mut self.storages, + change_tick, + ); + // SAFE: `entity` is valid, `location` matches entity, bundle matches inserter + unsafe { spawner.spawn_non_existent(entity, bundle) }; + spawn_or_insert = SpawnOrInsert::Spawn(spawner); + } } AllocAtWithoutReplacement::ExistsWithWrongGeneration => { invalid_entities.push(entity); @@ -959,9 +956,11 @@ impl World { let column = unique_components.get_mut(component_id).unwrap_or_else(|| { panic!("resource does not exist: {}", std::any::type_name::()) }); - if column.is_empty() { - panic!("resource does not exist: {}", std::any::type_name::()); - } + assert!( + !column.is_empty(), + "resource does not exist: {}", + std::any::type_name::() + ); // SAFE: if a resource column exists, row 0 exists as well. caller takes ownership of // the ptr value / drop is called when R is dropped unsafe { column.swap_remove_and_forget_unchecked(0) } @@ -1126,12 +1125,11 @@ impl World { } pub(crate) fn validate_non_send_access(&self) { - if !self.main_thread_validator.is_main_thread() { - panic!( - "attempted to access NonSend resource {} off of the main thread", - std::any::type_name::() - ); - } + assert!( + self.main_thread_validator.is_main_thread(), + "attempted to access NonSend resource {} off of the main thread", + std::any::type_name::(), + ); } /// Empties queued entities and adds them to the empty [Archetype](crate::archetype::Archetype). diff --git a/crates/bevy_ecs/src/world/world_cell.rs b/crates/bevy_ecs/src/world/world_cell.rs index e41954f394..af7858d256 100644 --- a/crates/bevy_ecs/src/world/world_cell.rs +++ b/crates/bevy_ecs/src/world/world_cell.rs @@ -90,12 +90,11 @@ impl<'w, T> WorldBorrow<'w, T> { archetype_component_id: ArchetypeComponentId, access: Rc>, ) -> Self { - if !access.borrow_mut().read(archetype_component_id) { - panic!( - "Attempted to immutably access {}, but it is already mutably borrowed", - std::any::type_name::() - ) - } + assert!( + access.borrow_mut().read(archetype_component_id), + "Attempted to immutably access {}, but it is already mutably borrowed", + std::any::type_name::(), + ); Self { value, archetype_component_id, @@ -132,12 +131,11 @@ impl<'w, T> WorldBorrowMut<'w, T> { archetype_component_id: ArchetypeComponentId, access: Rc>, ) -> Self { - if !access.borrow_mut().write(archetype_component_id) { - panic!( - "Attempted to mutably access {}, but it is already mutably borrowed", - std::any::type_name::() - ) - } + assert!( + access.borrow_mut().write(archetype_component_id), + "Attempted to mutably access {}, but it is already mutably borrowed", + std::any::type_name::(), + ); Self { value, archetype_component_id, diff --git a/crates/bevy_gltf/src/loader.rs b/crates/bevy_gltf/src/loader.rs index a91c1beaf9..1e85d483fd 100644 --- a/crates/bevy_gltf/src/loader.rs +++ b/crates/bevy_gltf/src/loader.rs @@ -349,18 +349,17 @@ async fn load_texture<'a>( .decode_utf8() .unwrap(); let uri = uri.as_ref(); - let (bytes, image_type) = match DataUri::parse(uri) { - Ok(data_uri) => (data_uri.decode()?, ImageType::MimeType(data_uri.mime_type)), - Err(()) => { - let parent = load_context.path().parent().unwrap(); - let image_path = parent.join(uri); - let bytes = load_context.read_asset_bytes(image_path.clone()).await?; + let (bytes, image_type) = if let Ok(data_uri) = DataUri::parse(uri) { + (data_uri.decode()?, ImageType::MimeType(data_uri.mime_type)) + } else { + let parent = load_context.path().parent().unwrap(); + let image_path = parent.join(uri); + let bytes = load_context.read_asset_bytes(image_path.clone()).await?; - let extension = Path::new(uri).extension().unwrap().to_str().unwrap(); - let image_type = ImageType::Extension(extension); + let extension = Path::new(uri).extension().unwrap().to_str().unwrap(); + let image_type = ImageType::Extension(extension); - (bytes, image_type) - } + (bytes, image_type) }; Image::from_buffer( @@ -776,7 +775,7 @@ fn resolve_node_hierarchy( .into_iter() .enumerate() .map(|(i, (label, node, children))| { - for child in children.iter() { + for child in &children { if let Some(parent) = parents.get_mut(*child) { *parent = Some(i); } else if !has_errored { @@ -802,7 +801,7 @@ fn resolve_node_hierarchy( assert!(parent_children.remove(&index)); if let Some((_, child_node)) = nodes.get(&index) { - parent_node.children.push(child_node.clone()) + parent_node.children.push(child_node.clone()); } if parent_children.is_empty() { empty_children.push_back(parent_index); diff --git a/crates/bevy_input/src/gamepad.rs b/crates/bevy_input/src/gamepad.rs index b71457983d..76b904ce29 100644 --- a/crates/bevy_input/src/gamepad.rs +++ b/crates/bevy_input/src/gamepad.rs @@ -279,23 +279,23 @@ pub fn gamepad_event_system( match event { GamepadEventType::Connected => { events.send(GamepadEvent(gamepad, event.clone())); - for button_type in ALL_BUTTON_TYPES.iter() { + for button_type in &ALL_BUTTON_TYPES { let gamepad_button = GamepadButton(gamepad, *button_type); button_input.reset(gamepad_button); button_axis.set(gamepad_button, 0.0); } - for axis_type in ALL_AXIS_TYPES.iter() { + for axis_type in &ALL_AXIS_TYPES { axis.set(GamepadAxis(gamepad, *axis_type), 0.0); } } GamepadEventType::Disconnected => { events.send(GamepadEvent(gamepad, event.clone())); - for button_type in ALL_BUTTON_TYPES.iter() { + for button_type in &ALL_BUTTON_TYPES { let gamepad_button = GamepadButton(gamepad, *button_type); button_input.reset(gamepad_button); button_axis.remove(gamepad_button); } - for axis_type in ALL_AXIS_TYPES.iter() { + for axis_type in &ALL_AXIS_TYPES { axis.remove(GamepadAxis(gamepad, *axis_type)); } } @@ -309,7 +309,7 @@ pub fn gamepad_event_system( events.send(GamepadEvent( gamepad, GamepadEventType::AxisChanged(*axis_type, filtered_value), - )) + )); } } GamepadEventType::ButtonChanged(button_type, value) => { @@ -322,7 +322,7 @@ pub fn gamepad_event_system( events.send(GamepadEvent( gamepad, GamepadEventType::ButtonChanged(*button_type, filtered_value), - )) + )); } let button_property = settings.get_button_settings(gamepad_button); diff --git a/crates/bevy_macro_utils/src/lib.rs b/crates/bevy_macro_utils/src/lib.rs index 03a0aa11a0..4f360a3bd3 100644 --- a/crates/bevy_macro_utils/src/lib.rs +++ b/crates/bevy_macro_utils/src/lib.rs @@ -76,7 +76,7 @@ impl BevyManifest { /// /// - `input`: The [`syn::DeriveInput`] for struct that is deriving the label trait /// - `trait_path`: The path [`syn::Path`] to the label trait -pub fn derive_label(input: syn::DeriveInput, trait_path: syn::Path) -> TokenStream { +pub fn derive_label(input: syn::DeriveInput, trait_path: &syn::Path) -> TokenStream { let ident = input.ident; let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl(); diff --git a/crates/bevy_pbr/src/light.rs b/crates/bevy_pbr/src/light.rs index 2246b48111..61f416913e 100644 --- a/crates/bevy_pbr/src/light.rs +++ b/crates/bevy_pbr/src/light.rs @@ -604,7 +604,7 @@ pub fn assign_lights_to_clusters( } } - for cluster_lights in clusters_lights.iter_mut() { + for cluster_lights in &mut clusters_lights { cluster_lights.entities.shrink_to_fit(); } @@ -821,7 +821,7 @@ pub fn check_light_mesh_visibility( } else { computed_visibility.is_visible = true; for visible_entities in cubemap_visible_entities.iter_mut() { - visible_entities.entities.push(entity) + visible_entities.entities.push(entity); } } } diff --git a/crates/bevy_pbr/src/material.rs b/crates/bevy_pbr/src/material.rs index d1c5213975..d9ee95446a 100644 --- a/crates/bevy_pbr/src/material.rs +++ b/crates/bevy_pbr/src/material.rs @@ -324,7 +324,7 @@ pub fn queue_material_meshes( } let alpha_mode = M::alpha_mode(material); if let AlphaMode::Blend = alpha_mode { - mesh_key |= MeshPipelineKey::TRANSPARENT_MAIN_PASS + mesh_key |= MeshPipelineKey::TRANSPARENT_MAIN_PASS; } let specialized_key = M::key(material); diff --git a/crates/bevy_pbr/src/pbr_material.rs b/crates/bevy_pbr/src/pbr_material.rs index 26ed132faf..6be68dfdd3 100644 --- a/crates/bevy_pbr/src/pbr_material.rs +++ b/crates/bevy_pbr/src/pbr_material.rs @@ -241,7 +241,7 @@ impl RenderAsset for StandardMaterial { AlphaMode::Opaque => flags |= StandardMaterialFlags::ALPHA_MODE_OPAQUE, AlphaMode::Mask(c) => { alpha_cutoff = c; - flags |= StandardMaterialFlags::ALPHA_MODE_MASK + flags |= StandardMaterialFlags::ALPHA_MODE_MASK; } AlphaMode::Blend => flags |= StandardMaterialFlags::ALPHA_MODE_BLEND, }; diff --git a/crates/bevy_pbr/src/render/light.rs b/crates/bevy_pbr/src/render/light.rs index d939be0b59..4d2b05b47a 100644 --- a/crates/bevy_pbr/src/render/light.rs +++ b/crates/bevy_pbr/src/render/light.rs @@ -1237,7 +1237,7 @@ impl Node for ShadowPassNode { .begin_render_pass(&pass_descriptor); let mut draw_functions = draw_functions.write(); let mut tracked_pass = TrackedRenderPass::new(render_pass); - for item in shadow_phase.items.iter() { + for item in &shadow_phase.items { let draw_function = draw_functions.get_mut(item.draw_function).unwrap(); draw_function.draw(world, &mut tracked_pass, view_light_entity, item); } diff --git a/crates/bevy_reflect/bevy_reflect_derive/src/lib.rs b/crates/bevy_reflect/bevy_reflect_derive/src/lib.rs index 55201bff91..9a8962cace 100644 --- a/crates/bevy_reflect/bevy_reflect_derive/src/lib.rs +++ b/crates/bevy_reflect/bevy_reflect_derive/src/lib.rs @@ -138,7 +138,7 @@ pub fn derive_reflect(input: TokenStream) -> TokenStream { DeriveType::Struct | DeriveType::UnitStruct => impl_struct( type_name, &ast.generics, - get_type_registration_impl, + &get_type_registration_impl, &bevy_reflect_path, &reflect_attrs, &active_fields, @@ -164,7 +164,7 @@ pub fn derive_reflect(input: TokenStream) -> TokenStream { fn impl_struct( struct_name: &Ident, generics: &Generics, - get_type_registration_impl: proc_macro2::TokenStream, + get_type_registration_impl: &proc_macro2::TokenStream, bevy_reflect_path: &Path, reflect_attrs: &ReflectAttrs, active_fields: &[(&Field, usize)], @@ -619,15 +619,15 @@ impl ReflectAttrs { match ident.as_str() { "PartialEq" => { attrs.reflect_partial_eq = - TraitImpl::Custom(segment.ident.clone()) + TraitImpl::Custom(segment.ident.clone()); } "Hash" => { attrs.reflect_hash = - TraitImpl::Custom(segment.ident.clone()) + TraitImpl::Custom(segment.ident.clone()); } "Serialize" => { attrs.serialize = - TraitImpl::Custom(segment.ident.clone()) + TraitImpl::Custom(segment.ident.clone()); } _ => {} } @@ -739,7 +739,7 @@ pub fn external_type_uuid(tokens: proc_macro::TokenStream) -> proc_macro::TokenS #[proc_macro_attribute] pub fn reflect_trait(args: TokenStream, input: TokenStream) -> TokenStream { - reflect_trait::reflect_trait(args, input) + reflect_trait::reflect_trait(&args, input) } #[proc_macro_derive(FromReflect)] diff --git a/crates/bevy_reflect/bevy_reflect_derive/src/reflect_trait.rs b/crates/bevy_reflect/bevy_reflect_derive/src/reflect_trait.rs index 64b0aea378..403dcd870d 100644 --- a/crates/bevy_reflect/bevy_reflect_derive/src/reflect_trait.rs +++ b/crates/bevy_reflect/bevy_reflect_derive/src/reflect_trait.rs @@ -22,7 +22,7 @@ impl Parse for TraitInfo { } } -pub fn reflect_trait(_args: TokenStream, input: TokenStream) -> TokenStream { +pub fn reflect_trait(_args: &TokenStream, input: TokenStream) -> TokenStream { let trait_info = parse_macro_input!(input as TraitInfo); let item_trait = &trait_info.item_trait; let trait_ident = &item_trait.ident; diff --git a/crates/bevy_reflect/bevy_reflect_derive/src/type_uuid.rs b/crates/bevy_reflect/bevy_reflect_derive/src/type_uuid.rs index 16d13bb207..dcba913fb1 100644 --- a/crates/bevy_reflect/bevy_reflect_derive/src/type_uuid.rs +++ b/crates/bevy_reflect/bevy_reflect_derive/src/type_uuid.rs @@ -15,9 +15,10 @@ pub fn type_uuid_derive(input: proc_macro::TokenStream) -> proc_macro::TokenStre let name = &ast.ident; let (impl_generics, type_generics, _) = &ast.generics.split_for_impl(); - if !impl_generics.to_token_stream().is_empty() || !type_generics.to_token_stream().is_empty() { - panic!("#[derive(TypeUuid)] is not supported for generics."); - } + assert!( + impl_generics.to_token_stream().is_empty() && type_generics.to_token_stream().is_empty(), + "#[derive(TypeUuid)] is not supported for generics.", + ); let mut uuid = None; for attribute in ast.attrs.iter().filter_map(|attr| attr.parse_meta().ok()) { diff --git a/crates/bevy_reflect/src/impls/std.rs b/crates/bevy_reflect/src/impls/std.rs index 801ce2c032..1f600abcef 100644 --- a/crates/bevy_reflect/src/impls/std.rs +++ b/crates/bevy_reflect/src/impls/std.rs @@ -186,7 +186,7 @@ impl Map for HashMap { } fn len(&self) -> usize { - HashMap::len(self) + Self::len(self) } fn iter(&self) -> MapIter { @@ -199,7 +199,7 @@ impl Map for HashMap { fn clone_dynamic(&self) -> DynamicMap { let mut dynamic_map = DynamicMap::default(); dynamic_map.set_name(self.type_name().to_string()); - for (k, v) in HashMap::iter(self) { + for (k, v) in self { dynamic_map.insert_boxed(k.clone_value(), v.clone_value()); } dynamic_map @@ -268,8 +268,8 @@ where V: Reflect + Clone + for<'de> Deserialize<'de>, { fn get_type_registration() -> TypeRegistration { - let mut registration = TypeRegistration::of::>(); - registration.insert::(FromType::>::from_type()); + let mut registration = TypeRegistration::of::(); + registration.insert::(FromType::::from_type()); registration } } @@ -371,6 +371,6 @@ mod tests { #[test] fn can_serialize_duration() { - assert!(std::time::Duration::ZERO.serializable().is_some()) + assert!(std::time::Duration::ZERO.serializable().is_some()); } } diff --git a/crates/bevy_reflect/src/map.rs b/crates/bevy_reflect/src/map.rs index f2ad17d667..a123df1737 100644 --- a/crates/bevy_reflect/src/map.rs +++ b/crates/bevy_reflect/src/map.rs @@ -151,7 +151,7 @@ unsafe impl Reflect for DynamicMap { if let ReflectRef::Map(map_value) = value.reflect_ref() { for (key, value) in map_value.iter() { if let Some(v) = self.get_mut(key) { - v.apply(value) + v.apply(value); } } } else { diff --git a/crates/bevy_reflect/src/struct_trait.rs b/crates/bevy_reflect/src/struct_trait.rs index 40d3ed3d19..f85c46cbcf 100644 --- a/crates/bevy_reflect/src/struct_trait.rs +++ b/crates/bevy_reflect/src/struct_trait.rs @@ -289,7 +289,7 @@ unsafe impl Reflect for DynamicStruct { for (i, value) in struct_value.iter_fields().enumerate() { let name = struct_value.name_at(i).unwrap(); if let Some(v) = self.field_mut(name) { - v.apply(value) + v.apply(value); } } } else { diff --git a/crates/bevy_reflect/src/tuple.rs b/crates/bevy_reflect/src/tuple.rs index 44423c3099..1ebec67fdb 100644 --- a/crates/bevy_reflect/src/tuple.rs +++ b/crates/bevy_reflect/src/tuple.rs @@ -269,7 +269,7 @@ pub fn tuple_apply(a: &mut T, b: &dyn Reflect) { if let ReflectRef::Tuple(tuple) = b.reflect_ref() { for (i, value) in tuple.iter_fields().enumerate() { if let Some(v) = a.field_mut(i) { - v.apply(value) + v.apply(value); } } } else { diff --git a/crates/bevy_reflect/src/tuple_struct.rs b/crates/bevy_reflect/src/tuple_struct.rs index dd053932ca..00e478f5f3 100644 --- a/crates/bevy_reflect/src/tuple_struct.rs +++ b/crates/bevy_reflect/src/tuple_struct.rs @@ -228,7 +228,7 @@ unsafe impl Reflect for DynamicTupleStruct { if let ReflectRef::TupleStruct(tuple_struct) = value.reflect_ref() { for (i, value) in tuple_struct.iter_fields().enumerate() { if let Some(v) = self.field_mut(i) { - v.apply(value) + v.apply(value); } } } else { diff --git a/crates/bevy_reflect/src/type_registry.rs b/crates/bevy_reflect/src/type_registry.rs index d0ae8c412b..bd31383620 100644 --- a/crates/bevy_reflect/src/type_registry.rs +++ b/crates/bevy_reflect/src/type_registry.rs @@ -276,7 +276,7 @@ impl TypeRegistration { impl Clone for TypeRegistration { fn clone(&self) -> Self { let mut data = HashMap::default(); - for (id, type_data) in self.data.iter() { + for (id, type_data) in &self.data { data.insert(*id, (*type_data).clone_type_data()); } diff --git a/crates/bevy_render/src/camera/active_cameras.rs b/crates/bevy_render/src/camera/active_cameras.rs index 8f7af81f12..42cebc65a6 100644 --- a/crates/bevy_render/src/camera/active_cameras.rs +++ b/crates/bevy_render/src/camera/active_cameras.rs @@ -52,7 +52,7 @@ pub fn active_cameras_system( mut active_cameras: ResMut, query: Query<(Entity, &Camera)>, ) { - for (name, active_camera) in active_cameras.cameras.iter_mut() { + for (name, active_camera) in &mut active_cameras.cameras { if active_camera .entity .map_or(false, |entity| query.get(entity).is_err()) diff --git a/crates/bevy_render/src/camera/mod.rs b/crates/bevy_render/src/camera/mod.rs index 4df498f0bf..5be7298689 100644 --- a/crates/bevy_render/src/camera/mod.rs +++ b/crates/bevy_render/src/camera/mod.rs @@ -105,5 +105,5 @@ fn extract_cameras( } } - commands.insert_resource(ExtractedCameraNames { entities }) + commands.insert_resource(ExtractedCameraNames { entities }); } diff --git a/crates/bevy_render/src/color/mod.rs b/crates/bevy_render/src/color/mod.rs index 14cb8e8dba..bdfe03dd44 100644 --- a/crates/bevy_render/src/color/mod.rs +++ b/crates/bevy_render/src/color/mod.rs @@ -592,7 +592,7 @@ impl Add for Color { impl AddAssign for Color { fn add_assign(&mut self, rhs: Vec4) { let rhs: Color = rhs.into(); - *self += rhs + *self += rhs; } } diff --git a/crates/bevy_render/src/mesh/mesh/mod.rs b/crates/bevy_render/src/mesh/mesh/mod.rs index faba4b3a17..317ce49a30 100644 --- a/crates/bevy_render/src/mesh/mesh/mod.rs +++ b/crates/bevy_render/src/mesh/mesh/mod.rs @@ -162,7 +162,7 @@ impl Mesh { /// Panics if the attributes have different vertex counts. pub fn count_vertices(&self) -> usize { let mut vertex_count: Option = None; - for (attribute_name, attribute_data) in self.attributes.iter() { + for (attribute_name, attribute_data) in &self.attributes { let attribute_len = attribute_data.len(); if let Some(previous_vertex_count) = vertex_count { assert_eq!(previous_vertex_count, attribute_len, @@ -230,7 +230,7 @@ impl Mesh { Some(indices) => indices, None => return, }; - for (_, attributes) in self.attributes.iter_mut() { + for attributes in self.attributes.values_mut() { let indices = indices.iter(); match attributes { VertexAttributeValues::Float32(vec) => *vec = duplicate(vec, indices), @@ -271,9 +271,7 @@ impl Mesh { /// Panics if [`Indices`] are set or [`Mesh::ATTRIBUTE_POSITION`] is not of type `float3`. /// Consider calling [`Mesh::duplicate_vertices`] or export your mesh with normal attributes. pub fn compute_flat_normals(&mut self) { - if self.indices().is_some() { - panic!("`compute_flat_normals` can't work on indexed geometry. Consider calling `Mesh::duplicate_vertices`."); - } + assert!(self.indices().is_none(), "`compute_flat_normals` can't work on indexed geometry. Consider calling `Mesh::duplicate_vertices`."); let positions = self .attribute(Mesh::ATTRIBUTE_POSITION) diff --git a/crates/bevy_render/src/mesh/shape/mod.rs b/crates/bevy_render/src/mesh/shape/mod.rs index 10dc5a7136..9f128d2ac4 100644 --- a/crates/bevy_render/src/mesh/shape/mod.rs +++ b/crates/bevy_render/src/mesh/shape/mod.rs @@ -163,7 +163,7 @@ impl From for Mesh { let mut positions = Vec::<[f32; 3]>::new(); let mut normals = Vec::<[f32; 3]>::new(); let mut uvs = Vec::<[f32; 2]>::new(); - for (position, normal, uv) in vertices.iter() { + for (position, normal, uv) in &vertices { positions.push(*position); normals.push(*normal); uvs.push(*uv); @@ -207,7 +207,7 @@ impl From for Mesh { let mut positions = Vec::new(); let mut normals = Vec::new(); let mut uvs = Vec::new(); - for (position, normal, uv) in vertices.iter() { + for (position, normal, uv) in &vertices { positions.push(*position); normals.push(*normal); uvs.push(*uv); diff --git a/crates/bevy_render/src/render_asset.rs b/crates/bevy_render/src/render_asset.rs index 2140365207..12861ae6f4 100644 --- a/crates/bevy_render/src/render_asset.rs +++ b/crates/bevy_render/src/render_asset.rs @@ -119,7 +119,7 @@ fn extract_render_asset( commands.insert_resource(ExtractedAssets { extracted: extracted_assets, removed, - }) + }); } /// Specifies all ECS data required by [`PrepareAssetSystem`]. diff --git a/crates/bevy_render/src/render_graph/graph.rs b/crates/bevy_render/src/render_graph/graph.rs index fe4ded9fe7..54b6b106d8 100644 --- a/crates/bevy_render/src/render_graph/graph.rs +++ b/crates/bevy_render/src/render_graph/graph.rs @@ -71,9 +71,7 @@ impl RenderGraph { /// Creates an [`GraphInputNode`] with the specified slots if not already present. pub fn set_input(&mut self, inputs: Vec) -> NodeId { - if self.input_node.is_some() { - panic!("Graph already has an input node"); - } + assert!(self.input_node.is_none(), "Graph already has an input node"); let id = self.add_node("GraphInputNode", GraphInputNode { inputs }); self.input_node = Some(id); diff --git a/crates/bevy_render/src/render_phase/draw_state.rs b/crates/bevy_render/src/render_phase/draw_state.rs index ec17b2902a..7b17c63277 100644 --- a/crates/bevy_render/src/render_phase/draw_state.rs +++ b/crates/bevy_render/src/render_phase/draw_state.rs @@ -257,7 +257,7 @@ impl<'a> TrackedRenderPass<'a> { offset, data.len() ); - self.pass.set_push_constants(stages, offset, data) + self.pass.set_push_constants(stages, offset, data); } /// Set the rendering viewport. @@ -282,7 +282,7 @@ impl<'a> TrackedRenderPass<'a> { max_depth ); self.pass - .set_viewport(x, y, width, height, min_depth, max_depth) + .set_viewport(x, y, width, height, min_depth, max_depth); } /// Insert a single debug marker. @@ -290,7 +290,7 @@ impl<'a> TrackedRenderPass<'a> { /// This is a GPU debugging feature. This has no effect on the rendering itself. pub fn insert_debug_marker(&mut self, label: &str) { trace!("insert debug marker: {}", label); - self.pass.insert_debug_marker(label) + self.pass.insert_debug_marker(label); } /// Start a new debug group. @@ -315,7 +315,7 @@ impl<'a> TrackedRenderPass<'a> { /// [`pop_debug_group`]: TrackedRenderPass::pop_debug_group pub fn push_debug_group(&mut self, label: &str) { trace!("push_debug_group marker: {}", label); - self.pass.push_debug_group(label) + self.pass.push_debug_group(label); } /// End the current debug group. @@ -332,11 +332,11 @@ impl<'a> TrackedRenderPass<'a> { /// [`pop_debug_group`]: TrackedRenderPass::pop_debug_group pub fn pop_debug_group(&mut self) { trace!("pop_debug_group"); - self.pass.pop_debug_group() + self.pass.pop_debug_group(); } pub fn set_blend_constant(&mut self, color: Color) { trace!("set blend constant: {:?}", color); - self.pass.set_blend_constant(wgpu::Color::from(color)) + self.pass.set_blend_constant(wgpu::Color::from(color)); } } diff --git a/crates/bevy_render/src/render_resource/buffer.rs b/crates/bevy_render/src/render_resource/buffer.rs index a902af5834..084a3290c2 100644 --- a/crates/bevy_render/src/render_resource/buffer.rs +++ b/crates/bevy_render/src/render_resource/buffer.rs @@ -34,7 +34,7 @@ impl Buffer { #[inline] pub fn unmap(&self) { - self.value.unmap() + self.value.unmap(); } } diff --git a/crates/bevy_render/src/render_resource/shader.rs b/crates/bevy_render/src/render_resource/shader.rs index 7f71488aef..3e08b76a96 100644 --- a/crates/bevy_render/src/render_resource/shader.rs +++ b/crates/bevy_render/src/render_resource/shader.rs @@ -73,6 +73,7 @@ impl Shader { self.import_path = Some(ShaderImport::Custom(import_path.into())); } + #[must_use] pub fn with_import_path>(mut self, import_path: P) -> Self { self.set_import_path(import_path); self diff --git a/crates/bevy_render/src/renderer/render_device.rs b/crates/bevy_render/src/renderer/render_device.rs index 9135498bb0..e5659cacd8 100644 --- a/crates/bevy_render/src/renderer/render_device.rs +++ b/crates/bevy_render/src/renderer/render_device.rs @@ -46,7 +46,7 @@ impl RenderDevice { /// no-op on the web, device is automatically polled. #[inline] pub fn poll(&self, maintain: wgpu::Maintain) { - self.device.poll(maintain) + self.device.poll(maintain); } /// Creates an empty [`CommandEncoder`](wgpu::CommandEncoder). @@ -144,7 +144,7 @@ impl RenderDevice { /// - A old [`SurfaceTexture`](wgpu::SurfaceTexture) is still alive referencing an old surface. /// - Texture format requested is unsupported on the surface. pub fn configure_surface(&self, surface: &wgpu::Surface, config: &wgpu::SurfaceConfiguration) { - surface.configure(&self.device, config) + surface.configure(&self.device, config); } /// Returns the wgpu [`Device`](wgpu::Device). @@ -155,9 +155,10 @@ impl RenderDevice { pub fn map_buffer(&self, buffer: &wgpu::BufferSlice, map_mode: wgpu::MapMode) { let data = buffer.map_async(map_mode); self.poll(wgpu::Maintain::Wait); - if future::block_on(data).is_err() { - panic!("Failed to map buffer to host."); - } + assert!( + future::block_on(data).is_ok(), + "Failed to map buffer to host." + ); } pub fn align_copy_bytes_per_row(row_bytes: usize) -> usize { diff --git a/crates/bevy_render/src/texture/image_texture_loader.rs b/crates/bevy_render/src/texture/image_texture_loader.rs index 14848be25a..b7f715ccbc 100644 --- a/crates/bevy_render/src/texture/image_texture_loader.rs +++ b/crates/bevy_render/src/texture/image_texture_loader.rs @@ -74,7 +74,7 @@ mod tests { #[test] fn test_supported_file_extensions() { for ext in FILE_EXTENSIONS { - assert!(image::ImageFormat::from_extension(ext).is_some()) + assert!(image::ImageFormat::from_extension(ext).is_some()); } } } diff --git a/crates/bevy_render/src/view/visibility/render_layers.rs b/crates/bevy_render/src/view/visibility/render_layers.rs index 59cc40e41c..3315beed33 100644 --- a/crates/bevy_render/src/view/visibility/render_layers.rs +++ b/crates/bevy_render/src/view/visibility/render_layers.rs @@ -75,6 +75,7 @@ impl RenderLayers { /// /// # Panics /// Panics when called with a layer greater than `TOTAL_LAYERS - 1`. + #[must_use] pub fn with(mut self, layer: Layer) -> Self { assert!(usize::from(layer) < Self::TOTAL_LAYERS); self.0 |= 1 << layer; @@ -85,6 +86,7 @@ impl RenderLayers { /// /// # Panics /// Panics when called with a layer greater than `TOTAL_LAYERS - 1`. + #[must_use] pub fn without(mut self, layer: Layer) -> Self { assert!(usize::from(layer) < Self::TOTAL_LAYERS); self.0 &= !(1 << layer); @@ -173,6 +175,6 @@ mod rendering_mask_tests { RenderLayers::from_layers(&[0, 1, 2]), >::from_iter(vec![0, 1, 2]), "from_layers and from_iter are equivalent" - ) + ); } } diff --git a/crates/bevy_scene/src/dynamic_scene.rs b/crates/bevy_scene/src/dynamic_scene.rs index ab15cbd61d..ad0d36fb0d 100644 --- a/crates/bevy_scene/src/dynamic_scene.rs +++ b/crates/bevy_scene/src/dynamic_scene.rs @@ -82,7 +82,7 @@ impl DynamicScene { let registry = world.get_resource::().unwrap().clone(); let type_registry = registry.read(); - for scene_entity in self.entities.iter() { + for scene_entity in &self.entities { // Fetch the entity with the given entity id from the `entity_map` // or spawn a new entity with a transiently unique id if there is // no corresponding entry. @@ -91,7 +91,7 @@ impl DynamicScene { .or_insert_with(|| world.spawn().id()); // Apply/ add each component to the given entity. - for component in scene_entity.components.iter() { + for component in &scene_entity.components { let registration = type_registry .get_with_name(component.type_name()) .ok_or_else(|| SceneSpawnError::UnregisteredType { diff --git a/crates/bevy_scene/src/scene_loader.rs b/crates/bevy_scene/src/scene_loader.rs index 06c7fb9192..be8286c954 100644 --- a/crates/bevy_scene/src/scene_loader.rs +++ b/crates/bevy_scene/src/scene_loader.rs @@ -15,7 +15,7 @@ impl FromWorld for SceneLoader { fn from_world(world: &mut World) -> Self { let type_registry = world.get_resource::().unwrap(); SceneLoader { - type_registry: (&*type_registry).clone(), + type_registry: (*type_registry).clone(), } } } diff --git a/crates/bevy_scene/src/scene_spawner.rs b/crates/bevy_scene/src/scene_spawner.rs index bbab80a96e..20962f9fb2 100644 --- a/crates/bevy_scene/src/scene_spawner.rs +++ b/crates/bevy_scene/src/scene_spawner.rs @@ -242,7 +242,7 @@ impl SceneSpawner { match self.spawn_dynamic_sync(world, &scene_handle) { Ok(_) => {} Err(SceneSpawnError::NonExistentScene { .. }) => { - self.dynamic_scenes_to_spawn.push(scene_handle) + self.dynamic_scenes_to_spawn.push(scene_handle); } Err(err) => return Err(err), } @@ -254,7 +254,7 @@ impl SceneSpawner { match self.spawn_sync_internal(world, scene_handle, instance_id) { Ok(_) => {} Err(SceneSpawnError::NonExistentRealScene { handle }) => { - self.scenes_to_spawn.push((handle, instance_id)) + self.scenes_to_spawn.push((handle, instance_id)); } Err(err) => return Err(err), } diff --git a/crates/bevy_scene/src/serde.rs b/crates/bevy_scene/src/serde.rs index 38af618510..95336b1b98 100644 --- a/crates/bevy_scene/src/serde.rs +++ b/crates/bevy_scene/src/serde.rs @@ -27,7 +27,7 @@ impl<'a> Serialize for SceneSerializer<'a> { S: serde::Serializer, { let mut state = serializer.serialize_seq(Some(self.scene.entities.len()))?; - for entity in self.scene.entities.iter() { + for entity in &self.scene.entities { state.serialize_element(&EntitySerializer { entity, registry: self.registry, diff --git a/crates/bevy_sprite/src/texture_atlas.rs b/crates/bevy_sprite/src/texture_atlas.rs index 7f0991c118..5eae1350fa 100644 --- a/crates/bevy_sprite/src/texture_atlas.rs +++ b/crates/bevy_sprite/src/texture_atlas.rs @@ -107,7 +107,7 @@ impl TextureAtlas { sprites.push(Rect { min: rect_min, max: Vec2::new(rect_min.x + tile_size.x, rect_min.y + tile_size.y), - }) + }); } } diff --git a/crates/bevy_sprite/src/texture_atlas_builder.rs b/crates/bevy_sprite/src/texture_atlas_builder.rs index bb5d6ca5af..7aa87141be 100644 --- a/crates/bevy_sprite/src/texture_atlas_builder.rs +++ b/crates/bevy_sprite/src/texture_atlas_builder.rs @@ -23,6 +23,7 @@ pub enum TextureAtlasBuilderError { } #[derive(Debug)] +#[must_use] /// A builder which is used to create a texture atlas from many individual /// sprites. pub struct TextureAtlasBuilder { @@ -88,7 +89,7 @@ impl TextureAtlasBuilder { texture.texture_descriptor.size.height, 1, ), - ) + ); } fn copy_texture_to_atlas( diff --git a/crates/bevy_tasks/examples/busy_behavior.rs b/crates/bevy_tasks/examples/busy_behavior.rs index fa4b002537..8a74034e0c 100644 --- a/crates/bevy_tasks/examples/busy_behavior.rs +++ b/crates/bevy_tasks/examples/busy_behavior.rs @@ -24,7 +24,7 @@ fn main() { std::thread::current().id(), i ); - }) + }); } }); diff --git a/crates/bevy_tasks/examples/idle_behavior.rs b/crates/bevy_tasks/examples/idle_behavior.rs index f6dda57a4f..daa2eaf2e2 100644 --- a/crates/bevy_tasks/examples/idle_behavior.rs +++ b/crates/bevy_tasks/examples/idle_behavior.rs @@ -23,7 +23,7 @@ fn main() { std::thread::current().id(), i ); - }) + }); } }); diff --git a/crates/bevy_tasks/src/countdown_event.rs b/crates/bevy_tasks/src/countdown_event.rs index eceef9697c..e9c9c66401 100644 --- a/crates/bevy_tasks/src/countdown_event.rs +++ b/crates/bevy_tasks/src/countdown_event.rs @@ -100,7 +100,7 @@ mod tests { countdown_event.decrement(); let countdown_event_clone = countdown_event.clone(); let handle = std::thread::spawn(move || { - futures_lite::future::block_on(countdown_event_clone.listen()) + futures_lite::future::block_on(countdown_event_clone.listen()); }); // Pause to give the new thread time to start blocking (ugly hack) diff --git a/crates/bevy_tasks/src/iter/adapters.rs b/crates/bevy_tasks/src/iter/adapters.rs index d05da201ad..c880167a62 100644 --- a/crates/bevy_tasks/src/iter/adapters.rs +++ b/crates/bevy_tasks/src/iter/adapters.rs @@ -129,13 +129,10 @@ where { fn next_batch(&mut self) -> Option { match &mut self.iter { - Some(iter) => match iter.next_batch() { - b @ Some(_) => b, - None => { - self.iter = None; - None - } - }, + Some(iter) => iter.next_batch().or_else(|| { + self.iter = None; + None + }), None => None, } } @@ -202,12 +199,9 @@ where P: ParallelIterator + Clone, { fn next_batch(&mut self) -> Option { - match self.curr.as_mut().and_then(|c| c.next_batch()) { - batch @ Some(_) => batch, - None => { - self.curr = Some(self.iter.clone()); - self.next_batch() - } - } + self.curr.as_mut().and_then(|c| c.next_batch()).or_else(|| { + self.curr = Some(self.iter.clone()); + self.next_batch() + }) } } diff --git a/crates/bevy_tasks/src/iter/mod.rs b/crates/bevy_tasks/src/iter/mod.rs index 02f6cd8528..952bc53075 100644 --- a/crates/bevy_tasks/src/iter/mod.rs +++ b/crates/bevy_tasks/src/iter/mod.rs @@ -36,7 +36,7 @@ where fn count(mut self, pool: &TaskPool) -> usize { pool.scope(|s| { while let Some(batch) = self.next_batch() { - s.spawn(async move { batch.count() }) + s.spawn(async move { batch.count() }); } }) .iter() @@ -219,7 +219,7 @@ where pool.scope(|s| { while let Some(batch) = self.next_batch() { let newf = f.clone(); - s.spawn(async move { batch.partition::, F>(newf) }) + s.spawn(async move { batch.partition::, F>(newf) }); } }) .into_iter() diff --git a/crates/bevy_tasks/src/task_pool.rs b/crates/bevy_tasks/src/task_pool.rs index 4d50555f92..597ebc334c 100644 --- a/crates/bevy_tasks/src/task_pool.rs +++ b/crates/bevy_tasks/src/task_pool.rs @@ -12,6 +12,7 @@ use crate::Task; /// Used to create a [`TaskPool`] #[derive(Debug, Default, Clone)] +#[must_use] pub struct TaskPoolBuilder { /// If set, we'll set up the thread pool to use at most n threads. Otherwise use /// the logical core count of the system diff --git a/crates/bevy_text/src/font.rs b/crates/bevy_text/src/font.rs index fced2cbc1a..56fe1e60fc 100644 --- a/crates/bevy_text/src/font.rs +++ b/crates/bevy_text/src/font.rs @@ -37,8 +37,7 @@ impl Font { TextureDimension::D2, alpha .iter() - .map(|a| vec![255, 255, 255, (*a * 255.0) as u8]) - .flatten() + .flat_map(|a| vec![255, 255, 255, (*a * 255.0) as u8]) .collect::>(), TextureFormat::Rgba8UnormSrgb, ) diff --git a/crates/bevy_text/src/glyph_brush.rs b/crates/bevy_text/src/glyph_brush.rs index fc9d5fffc7..6d11b07ad1 100644 --- a/crates/bevy_text/src/glyph_brush.rs +++ b/crates/bevy_text/src/glyph_brush.rs @@ -73,7 +73,7 @@ impl GlyphBrush { let mut max_y = std::f32::MIN; let mut min_x = std::f32::MAX; - for sg in glyphs.iter() { + for sg in &glyphs { let glyph = &sg.glyph; let scaled_font = sections_data[sg.section_index].3; max_y = max_y.max(glyph.position.y - scaled_font.descent()); diff --git a/crates/bevy_text/src/pipeline.rs b/crates/bevy_text/src/pipeline.rs index 4a13ecffdf..5539a4e1d0 100644 --- a/crates/bevy_text/src/pipeline.rs +++ b/crates/bevy_text/src/pipeline.rs @@ -103,7 +103,7 @@ impl TextPipeline { let mut max_x: f32 = std::f32::MIN; let mut max_y: f32 = std::f32::MIN; - for sg in section_glyphs.iter() { + for sg in §ion_glyphs { let scaled_font = scaled_fonts[sg.section_index]; let glyph = &sg.glyph; min_x = min_x.min(glyph.position.x); diff --git a/crates/bevy_transform/src/components/global_transform.rs b/crates/bevy_transform/src/components/global_transform.rs index f66afde173..c13ce7ea92 100644 --- a/crates/bevy_transform/src/components/global_transform.rs +++ b/crates/bevy_transform/src/components/global_transform.rs @@ -94,6 +94,7 @@ impl GlobalTransform { #[doc(hidden)] #[inline] + #[must_use] pub fn looking_at(mut self, target: Vec3, up: Vec3) -> Self { self.look_at(target, up); self @@ -197,11 +198,12 @@ impl GlobalTransform { /// Multiplies `self` with `transform` component by component, returning the /// resulting [`GlobalTransform`] #[inline] - pub fn mul_transform(&self, transform: Transform) -> GlobalTransform { + #[must_use] + pub fn mul_transform(&self, transform: Transform) -> Self { let translation = self.mul_vec3(transform.translation); let rotation = self.rotation * transform.rotation; let scale = self.scale * transform.scale; - GlobalTransform { + Self { translation, rotation, scale, diff --git a/crates/bevy_transform/src/components/transform.rs b/crates/bevy_transform/src/components/transform.rs index 80787df319..1e9a364cd8 100644 --- a/crates/bevy_transform/src/components/transform.rs +++ b/crates/bevy_transform/src/components/transform.rs @@ -103,6 +103,7 @@ impl Transform { /// local z direction is toward `target` and its unit vector in the local y direction /// is toward `up`. #[inline] + #[must_use] pub fn looking_at(mut self, target: Vec3, up: Vec3) -> Self { self.look_at(target, up); self @@ -207,6 +208,7 @@ impl Transform { /// Multiplies `self` with `transform` component by component, returning the /// resulting [`Transform`] #[inline] + #[must_use] pub fn mul_transform(&self, transform: Transform) -> Self { let translation = self.mul_vec3(transform.translation); let rotation = self.rotation * transform.rotation; diff --git a/crates/bevy_ui/src/render/mod.rs b/crates/bevy_ui/src/render/mod.rs index e632b4eee1..947eda82c7 100644 --- a/crates/bevy_ui/src/render/mod.rs +++ b/crates/bevy_ui/src/render/mod.rs @@ -292,7 +292,7 @@ pub fn prepare_uinodes( let mut end = 0; let mut current_batch_handle = Default::default(); let mut last_z = 0.0; - for extracted_uinode in extracted_uinodes.uinodes.iter() { + for extracted_uinode in &extracted_uinodes.uinodes { if current_batch_handle != extracted_uinode.image { if start != end { commands.spawn_bundle((UiBatch { diff --git a/crates/bevy_ui/src/render/render_pass.rs b/crates/bevy_ui/src/render/render_pass.rs index 81ef4af8ec..831b6dee9f 100644 --- a/crates/bevy_ui/src/render/render_pass.rs +++ b/crates/bevy_ui/src/render/render_pass.rs @@ -92,7 +92,7 @@ impl bevy_render::render_graph::Node for UiPassNode { let mut draw_functions = draw_functions.write(); let mut tracked_pass = TrackedRenderPass::new(render_pass); - for item in transparent_phase.items.iter() { + for item in &transparent_phase.items { let draw_function = draw_functions.get_mut(item.draw_function).unwrap(); draw_function.draw(world, &mut tracked_pass, view_entity, item); } diff --git a/crates/bevy_ui/src/update.rs b/crates/bevy_ui/src/update.rs index f1bc965584..9fe0fc446e 100644 --- a/crates/bevy_ui/src/update.rs +++ b/crates/bevy_ui/src/update.rs @@ -76,7 +76,7 @@ pub fn update_clipping_system( &mut node_query, root_node, None, - ) + ); } } diff --git a/crates/bevy_window/src/window.rs b/crates/bevy_window/src/window.rs index b9da4eda9d..47c03d085c 100644 --- a/crates/bevy_window/src/window.rs +++ b/crates/bevy_window/src/window.rs @@ -95,7 +95,8 @@ impl Default for WindowResizeConstraints { } impl WindowResizeConstraints { - pub fn check_constraints(&self) -> WindowResizeConstraints { + #[must_use] + pub fn check_constraints(&self) -> Self { let WindowResizeConstraints { mut min_width, mut min_height, @@ -365,7 +366,7 @@ impl Window { #[inline] pub fn set_position(&mut self, position: IVec2) { self.command_queue - .push(WindowCommand::SetPosition { position }) + .push(WindowCommand::SetPosition { position }); } /// Modifies the minimum and maximum window bounds for resizing in logical pixels. diff --git a/crates/bevy_winit/src/lib.rs b/crates/bevy_winit/src/lib.rs index 9ff666d376..c58c9e4fc8 100644 --- a/crates/bevy_winit/src/lib.rs +++ b/crates/bevy_winit/src/lib.rs @@ -57,12 +57,13 @@ fn change_window(world: &mut World) { let window = winit_windows.get_window(id).unwrap(); match mode { bevy_window::WindowMode::BorderlessFullscreen => { - window.set_fullscreen(Some(winit::window::Fullscreen::Borderless(None))) + window + .set_fullscreen(Some(winit::window::Fullscreen::Borderless(None))); } bevy_window::WindowMode::Fullscreen => { window.set_fullscreen(Some(winit::window::Fullscreen::Exclusive( get_best_videomode(&window.current_monitor().unwrap()), - ))) + ))); } bevy_window::WindowMode::SizedFullscreen => window.set_fullscreen(Some( winit::window::Fullscreen::Exclusive(get_fitting_videomode( @@ -129,11 +130,11 @@ fn change_window(world: &mut World) { } bevy_window::WindowCommand::SetMaximized { maximized } => { let window = winit_windows.get_window(id).unwrap(); - window.set_maximized(maximized) + window.set_maximized(maximized); } bevy_window::WindowCommand::SetMinimized { minimized } => { let window = winit_windows.get_window(id).unwrap(); - window.set_minimized(minimized) + window.set_minimized(minimized); } bevy_window::WindowCommand::SetPosition { position } => { let window = winit_windows.get_window(id).unwrap(); @@ -385,7 +386,7 @@ pub fn winit_runner_with(mut app: App) { char_input_events.send(ReceivedCharacter { id: window_id, char: c, - }) + }); } WindowEvent::ScaleFactorChanged { scale_factor, diff --git a/examples/2d/many_sprites.rs b/examples/2d/many_sprites.rs index 24349a4199..d4f4dd5c3e 100644 --- a/examples/2d/many_sprites.rs +++ b/examples/2d/many_sprites.rs @@ -19,7 +19,7 @@ fn main() { .add_startup_system(setup) .add_system(print_sprite_count.label("Tick")) .add_system(move_camera.after("Tick")) - .run() + .run(); } fn setup(mut commands: Commands, assets: Res) { diff --git a/examples/2d/texture_atlas.rs b/examples/2d/texture_atlas.rs index 409fc4f76d..3ce4fd75f9 100644 --- a/examples/2d/texture_atlas.rs +++ b/examples/2d/texture_atlas.rs @@ -48,7 +48,7 @@ fn setup( mut textures: ResMut>, ) { let mut texture_atlas_builder = TextureAtlasBuilder::default(); - for handle in rpg_sprite_handles.handles.iter() { + for handle in &rpg_sprite_handles.handles { let texture = textures.get(handle).unwrap(); texture_atlas_builder.add_texture(handle.clone_weak().typed::(), texture); } diff --git a/examples/async_tasks/external_source_external_thread.rs b/examples/async_tasks/external_source_external_thread.rs index 7c3cd01cf3..943a8e9d8a 100644 --- a/examples/async_tasks/external_source_external_thread.rs +++ b/examples/async_tasks/external_source_external_thread.rs @@ -44,7 +44,7 @@ fn setup(mut commands: Commands, asset_server: Res) { // This system reads from the receiver and sends events to Bevy fn read_stream(receiver: ResMut, mut events: EventWriter) { for from_stream in receiver.0.try_iter() { - events.send(StreamEvent(from_stream)) + events.send(StreamEvent(from_stream)); } } diff --git a/examples/ecs/timers.rs b/examples/ecs/timers.rs index 67e5ba69af..65c0ec37c4 100644 --- a/examples/ecs/timers.rs +++ b/examples/ecs/timers.rs @@ -45,7 +45,7 @@ fn setup(mut commands: Commands) { fn print_when_completed(time: Res