From f000c2b951f4c519416ffda70281b2284d37f9f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Lescaudey=20de=20Maneville?= Date: Tue, 31 May 2022 01:38:07 +0000 Subject: [PATCH] Clippy improvements (#4665) # Objective Follow up to my previous MR #3718 to add new clippy warnings to bevy: - [x] [~~option_if_let_else~~](https://rust-lang.github.io/rust-clippy/master/#option_if_let_else) (reverted) - [x] [redundant_else](https://rust-lang.github.io/rust-clippy/master/#redundant_else) - [x] [match_same_arms](https://rust-lang.github.io/rust-clippy/master/#match_same_arms) - [x] [semicolon_if_nothing_returned](https://rust-lang.github.io/rust-clippy/master/#semicolon_if_nothing_returned) - [x] [explicit_iter_loop](https://rust-lang.github.io/rust-clippy/master/#explicit_iter_loop) - [x] [map_flatten](https://rust-lang.github.io/rust-clippy/master/#map_flatten) There is one commit per clippy warning, and the matching flags are added to the CI execution. To test the CI execution you may run `cargo run -p ci -- clippy` at the root. I choose the add the flags in the `ci` tool crate to avoid having them in every `lib.rs` but I guess it could become an issue with suprise warnings coming up after a commit/push Co-authored-by: Carter Anderson --- crates/bevy_animation/src/lib.rs | 2 +- crates/bevy_app/src/plugin_group.rs | 14 +- crates/bevy_asset/src/debug_asset_server.rs | 3 +- crates/bevy_audio/src/audio_output.rs | 8 +- crates/bevy_ecs/src/component.rs | 2 +- crates/bevy_ecs/src/query/access.rs | 17 +- crates/bevy_ecs/src/query/filter.rs | 2 + crates/bevy_ecs/src/query/iter.rs | 2 +- crates/bevy_ecs/src/query/mod.rs | 2 +- crates/bevy_ecs/src/schedule/stage.rs | 7 +- crates/bevy_ecs/src/schedule/state.rs | 9 +- crates/bevy_ecs/src/storage/blob_vec.rs | 2 +- crates/bevy_ecs/src/system/function_system.rs | 1 - crates/bevy_ecs/src/system/query.rs | 2 +- crates/bevy_ecs/src/system/system_param.rs | 4 +- crates/bevy_gltf/src/loader.rs | 40 +- crates/bevy_pbr/src/light.rs | 5 +- crates/bevy_pbr/src/pbr_material.rs | 2 +- crates/bevy_pbr/src/render/mesh.rs | 2 +- crates/bevy_pbr/src/wireframe.rs | 1 - crates/bevy_ptr/src/lib.rs | 2 +- .../bevy_reflect_derive/src/type_uuid.rs | 2 +- crates/bevy_reflect/src/array.rs | 2 +- crates/bevy_reflect/src/impls/std.rs | 2 +- crates/bevy_reflect/src/type_registry.rs | 1 - crates/bevy_render/src/camera/camera.rs | 3 +- crates/bevy_render/src/color/mod.rs | 32 +- .../bevy_render/src/mesh/mesh/conversions.rs | 40 +- crates/bevy_render/src/mesh/mesh/mod.rs | 8 +- crates/bevy_render/src/render_asset.rs | 5 +- crates/bevy_render/src/render_graph/edge.rs | 6 +- crates/bevy_render/src/render_graph/graph.rs | 19 +- .../src/render_phase/draw_state.rs | 31 +- .../bevy_render/src/render_resource/shader.rs | 3 +- .../bevy_render/src/renderer/graph_runner.rs | 3 +- crates/bevy_render/src/texture/basis.rs | 6 +- crates/bevy_render/src/texture/dds.rs | 165 ++------- crates/bevy_render/src/texture/image.rs | 118 +++--- crates/bevy_render/src/texture/ktx2.rs | 342 +++--------------- crates/bevy_render/src/view/mod.rs | 6 +- crates/bevy_sprite/src/render/mod.rs | 17 +- crates/bevy_text/src/text2d.rs | 2 +- crates/bevy_ui/src/flex/mod.rs | 2 +- crates/bevy_ui/src/focus.rs | 1 - crates/bevy_ui/src/render/mod.rs | 5 +- crates/bevy_ui/src/ui_node.rs | 3 +- crates/bevy_ui/src/widget/text.rs | 7 +- crates/bevy_winit/src/winit_windows.rs | 3 +- examples/3d/shapes.rs | 2 +- examples/audio/audio_control.rs | 4 +- examples/games/breakout.rs | 10 +- examples/games/game_menu.rs | 3 +- examples/reflection/reflection_types.rs | 1 + .../shader/compute_shader_game_of_life.rs | 4 +- examples/stress_tests/transform_hierarchy.rs | 2 +- tools/ci/src/main.rs | 16 +- 56 files changed, 302 insertions(+), 703 deletions(-) diff --git a/crates/bevy_animation/src/lib.rs b/crates/bevy_animation/src/lib.rs index b65debcaf3..7882ad4d2f 100644 --- a/crates/bevy_animation/src/lib.rs +++ b/crates/bevy_animation/src/lib.rs @@ -230,7 +230,7 @@ pub fn animation_player( match &curve.keyframes { Keyframes::Rotation(keyframes) => transform.rotation = keyframes[0], Keyframes::Translation(keyframes) => { - transform.translation = keyframes[0] + transform.translation = keyframes[0]; } Keyframes::Scale(keyframes) => transform.scale = keyframes[0], } diff --git a/crates/bevy_app/src/plugin_group.rs b/crates/bevy_app/src/plugin_group.rs index 75d450032a..d707634fd8 100644 --- a/crates/bevy_app/src/plugin_group.rs +++ b/crates/bevy_app/src/plugin_group.rs @@ -128,7 +128,7 @@ impl PluginGroupBuilder { /// Consumes the [`PluginGroupBuilder`] and [builds](Plugin::build) the contained [`Plugin`]s /// in the order specified. pub fn finish(self, app: &mut App) { - for ty in self.order.iter() { + for ty in &self.order { if let Some(entry) = self.plugins.get(ty) { if entry.enabled { debug!("added plugin: {}", entry.plugin.name()); @@ -173,7 +173,7 @@ mod tests { std::any::TypeId::of::(), std::any::TypeId::of::(), ] - ) + ); } #[test] @@ -190,7 +190,7 @@ mod tests { std::any::TypeId::of::(), std::any::TypeId::of::(), ] - ) + ); } #[test] @@ -207,7 +207,7 @@ mod tests { std::any::TypeId::of::(), std::any::TypeId::of::(), ] - ) + ); } #[test] @@ -225,7 +225,7 @@ mod tests { std::any::TypeId::of::(), std::any::TypeId::of::(), ] - ) + ); } #[test] @@ -243,7 +243,7 @@ mod tests { std::any::TypeId::of::(), std::any::TypeId::of::(), ] - ) + ); } #[test] @@ -261,6 +261,6 @@ mod tests { std::any::TypeId::of::(), std::any::TypeId::of::(), ] - ) + ); } } diff --git a/crates/bevy_asset/src/debug_asset_server.rs b/crates/bevy_asset/src/debug_asset_server.rs index d4970dabcc..e53646de95 100644 --- a/crates/bevy_asset/src/debug_asset_server.rs +++ b/crates/bevy_asset/src/debug_asset_server.rs @@ -93,8 +93,7 @@ pub(crate) fn sync_debug_assets( let (changed_shaders, handle_map, debug_assets) = state.get_mut(world); for changed in changed_shaders.iter_current_update_events() { let debug_handle = match changed { - AssetEvent::Created { handle } => handle, - AssetEvent::Modified { handle } => handle, + AssetEvent::Created { handle } | AssetEvent::Modified { handle } => handle, AssetEvent::Removed { .. } => continue, }; if let Some(handle) = handle_map.handles.get(debug_handle) { diff --git a/crates/bevy_audio/src/audio_output.rs b/crates/bevy_audio/src/audio_output.rs index f7010f2c7d..e378a2c43f 100644 --- a/crates/bevy_audio/src/audio_output.rs +++ b/crates/bevy_audio/src/audio_output.rs @@ -43,17 +43,15 @@ where Source: Asset + Decodable, { fn play_source(&self, audio_source: &Source, repeat: bool) -> Option { - if let Some(stream_handle) = &self.stream_handle { + self.stream_handle.as_ref().map(|stream_handle| { let sink = Sink::try_new(stream_handle).unwrap(); if repeat { sink.append(audio_source.decoder().repeat_infinite()); } else { sink.append(audio_source.decoder()); } - Some(sink) - } else { - None - } + sink + }) } fn try_play_queued( diff --git a/crates/bevy_ecs/src/component.rs b/crates/bevy_ecs/src/component.rs index 319c418528..fdcb2a0d0d 100644 --- a/crates/bevy_ecs/src/component.rs +++ b/crates/bevy_ecs/src/component.rs @@ -196,7 +196,7 @@ impl std::fmt::Debug for 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: OwningPtr<'_>) { - x.drop_as::() + x.drop_as::(); } /// Create a new `ComponentDescriptor` for the type `T`. diff --git a/crates/bevy_ecs/src/query/access.rs b/crates/bevy_ecs/src/query/access.rs index 5567075015..8b3dd275d4 100644 --- a/crates/bevy_ecs/src/query/access.rs +++ b/crates/bevy_ecs/src/query/access.rs @@ -294,12 +294,11 @@ impl FilteredAccessSet { pub fn is_compatible(&self, other: &FilteredAccessSet) -> bool { if self.combined_access.is_compatible(other.combined_access()) { return true; - } else { - for filtered in self.filtered_accesses.iter() { - for other_filtered in other.filtered_accesses.iter() { - if !filtered.is_compatible(other_filtered) { - return false; - } + } + for filtered in &self.filtered_accesses { + for other_filtered in &other.filtered_accesses { + if !filtered.is_compatible(other_filtered) { + return false; } } } @@ -312,8 +311,8 @@ impl FilteredAccessSet { // if the unfiltered access is incompatible, must check each pair let mut conflicts = HashSet::new(); if !self.combined_access.is_compatible(other.combined_access()) { - for filtered in self.filtered_accesses.iter() { - for other_filtered in other.filtered_accesses.iter() { + for filtered in &self.filtered_accesses { + for other_filtered in &other.filtered_accesses { conflicts.extend(filtered.get_conflicts(other_filtered).into_iter()); } } @@ -326,7 +325,7 @@ impl FilteredAccessSet { // if the unfiltered access is incompatible, must check each pair let mut conflicts = HashSet::new(); if !self.combined_access.is_compatible(filtered_access.access()) { - for filtered in self.filtered_accesses.iter() { + for filtered in &self.filtered_accesses { conflicts.extend(filtered.get_conflicts(filtered_access).into_iter()); } } diff --git a/crates/bevy_ecs/src/query/filter.rs b/crates/bevy_ecs/src/query/filter.rs index c973765be6..f7ef292d6b 100644 --- a/crates/bevy_ecs/src/query/filter.rs +++ b/crates/bevy_ecs/src/query/filter.rs @@ -47,6 +47,7 @@ pub struct With(PhantomData); impl WorldQuery for With { type State = WithState; + #[allow(clippy::semicolon_if_nothing_returned)] fn shrink<'wlong: 'wshort, 'wshort>( item: super::QueryItem<'wlong, Self>, ) -> super::QueryItem<'wshort, Self> { @@ -186,6 +187,7 @@ pub struct Without(PhantomData); impl WorldQuery for Without { type State = WithoutState; + #[allow(clippy::semicolon_if_nothing_returned)] fn shrink<'wlong: 'wshort, 'wshort>( item: super::QueryItem<'wlong, Self>, ) -> super::QueryItem<'wshort, Self> { diff --git a/crates/bevy_ecs/src/query/iter.rs b/crates/bevy_ecs/src/query/iter.rs index 4b222d2bb4..6f12ea557d 100644 --- a/crates/bevy_ecs/src/query/iter.rs +++ b/crates/bevy_ecs/src/query/iter.rs @@ -162,7 +162,7 @@ impl<'w, 's, Q: WorldQuery, F: WorldQuery, const K: usize> QueryCombinationIter< let ptr = values.as_mut_ptr().cast::>(); for (offset, cursor) in self.cursors.iter_mut().enumerate() { - ptr.add(offset).write(cursor.peek_last().unwrap()) + ptr.add(offset).write(cursor.peek_last().unwrap()); } Some(values.assume_init()) diff --git a/crates/bevy_ecs/src/query/mod.rs b/crates/bevy_ecs/src/query/mod.rs index 0be28ee2cf..4e01c9e20d 100644 --- a/crates/bevy_ecs/src/query/mod.rs +++ b/crates/bevy_ecs/src/query/mod.rs @@ -455,7 +455,7 @@ mod tests { ) }) .collect::>(); - assert_eq!(custom_param_data, normal_data) + assert_eq!(custom_param_data, normal_data); } { diff --git a/crates/bevy_ecs/src/schedule/stage.rs b/crates/bevy_ecs/src/schedule/stage.rs index 210ac514c2..f92cb2d818 100644 --- a/crates/bevy_ecs/src/schedule/stage.rs +++ b/crates/bevy_ecs/src/schedule/stage.rs @@ -925,10 +925,9 @@ impl Stage for SystemStage { } } match criteria.should_run { - ShouldRun::Yes => { - run_system_loop = true; - } - ShouldRun::YesAndCheckAgain | ShouldRun::NoAndCheckAgain => { + ShouldRun::Yes + | ShouldRun::YesAndCheckAgain + | ShouldRun::NoAndCheckAgain => { run_system_loop = true; } ShouldRun::No => (), diff --git a/crates/bevy_ecs/src/schedule/state.rs b/crates/bevy_ecs/src/schedule/state.rs index 3c9ddb3752..3d6ae137ad 100644 --- a/crates/bevy_ecs/src/schedule/state.rs +++ b/crates/bevy_ecs/src/schedule/state.rs @@ -133,13 +133,8 @@ where let pred_clone = pred.clone(); (move |state: Res>, mut is_in_stack: Local| match &state.transition { Some(StateTransition::Entering(ref relevant, _)) - | Some(StateTransition::ExitingToResume(_, ref relevant)) => { - if relevant == &pred { - *is_in_stack = !*is_in_stack; - } - false - } - Some(StateTransition::ExitingFull(_, ref relevant)) => { + | Some(StateTransition::ExitingToResume(_, ref relevant)) + | Some(StateTransition::ExitingFull(_, ref relevant)) => { if relevant == &pred { *is_in_stack = !*is_in_stack; } diff --git a/crates/bevy_ecs/src/storage/blob_vec.rs b/crates/bevy_ecs/src/storage/blob_vec.rs index f7b989de0e..7a3991d35e 100644 --- a/crates/bevy_ecs/src/storage/blob_vec.rs +++ b/crates/bevy_ecs/src/storage/blob_vec.rs @@ -357,7 +357,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: OwningPtr<'_>) { - x.drop_as::() + x.drop_as::(); } /// # Safety diff --git a/crates/bevy_ecs/src/system/function_system.rs b/crates/bevy_ecs/src/system/function_system.rs index 6a3f5e10c7..9dec1b5f84 100644 --- a/crates/bevy_ecs/src/system/function_system.rs +++ b/crates/bevy_ecs/src/system/function_system.rs @@ -319,7 +319,6 @@ where world_id: Option, archetype_generation: ArchetypeGeneration, // NOTE: PhantomData T> gives this safe Send/Sync impls - #[allow(clippy::type_complexity)] marker: PhantomData (In, Out, Marker)>, } diff --git a/crates/bevy_ecs/src/system/query.rs b/crates/bevy_ecs/src/system/query.rs index 42e77e8461..4fbab3b47f 100644 --- a/crates/bevy_ecs/src/system/query.rs +++ b/crates/bevy_ecs/src/system/query.rs @@ -561,7 +561,7 @@ impl<'w, 's, Q: WorldQuery, F: WorldQuery> Query<'w, 's, Q, F> { 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 87757c91fe..60c9c56ac7 100644 --- a/crates/bevy_ecs/src/system/system_param.rs +++ b/crates/bevy_ecs/src/system/system_param.rs @@ -1445,11 +1445,11 @@ unsafe impl SystemParamState } fn new_archetype(&mut self, archetype: &Archetype, system_meta: &mut SystemMeta) { - self.0.new_archetype(archetype, system_meta) + self.0.new_archetype(archetype, system_meta); } fn apply(&mut self, world: &mut World) { - self.0.apply(world) + self.0.apply(world); } } diff --git a/crates/bevy_gltf/src/loader.rs b/crates/bevy_gltf/src/loader.rs index 5965109062..35025aded6 100644 --- a/crates/bevy_gltf/src/loader.rs +++ b/crates/bevy_gltf/src/loader.rs @@ -613,55 +613,45 @@ fn load_material(material: &Material, load_context: &mut LoadContext) -> Handle< let pbr = material.pbr_metallic_roughness(); let color = pbr.base_color_factor(); - let base_color_texture = if let Some(info) = pbr.base_color_texture() { + let base_color_texture = pbr.base_color_texture().map(|info| { // TODO: handle info.tex_coord() (the *set* index for the right texcoords) let label = texture_label(&info.texture()); let path = AssetPath::new_ref(load_context.path(), Some(&label)); - Some(load_context.get_handle(path)) - } else { - None - }; + load_context.get_handle(path) + }); let normal_map_texture: Option> = - if let Some(normal_texture) = material.normal_texture() { + material.normal_texture().map(|normal_texture| { // TODO: handle normal_texture.scale // TODO: handle normal_texture.tex_coord() (the *set* index for the right texcoords) let label = texture_label(&normal_texture.texture()); let path = AssetPath::new_ref(load_context.path(), Some(&label)); - Some(load_context.get_handle(path)) - } else { - None - }; + load_context.get_handle(path) + }); - let metallic_roughness_texture = if let Some(info) = pbr.metallic_roughness_texture() { + let metallic_roughness_texture = pbr.metallic_roughness_texture().map(|info| { // TODO: handle info.tex_coord() (the *set* index for the right texcoords) let label = texture_label(&info.texture()); let path = AssetPath::new_ref(load_context.path(), Some(&label)); - Some(load_context.get_handle(path)) - } else { - None - }; + load_context.get_handle(path) + }); - let occlusion_texture = if let Some(occlusion_texture) = material.occlusion_texture() { + let occlusion_texture = material.occlusion_texture().map(|occlusion_texture| { // TODO: handle occlusion_texture.tex_coord() (the *set* index for the right texcoords) // TODO: handle occlusion_texture.strength() (a scalar multiplier for occlusion strength) let label = texture_label(&occlusion_texture.texture()); let path = AssetPath::new_ref(load_context.path(), Some(&label)); - Some(load_context.get_handle(path)) - } else { - None - }; + load_context.get_handle(path) + }); let emissive = material.emissive_factor(); - let emissive_texture = if let Some(info) = material.emissive_texture() { + let emissive_texture = material.emissive_texture().map(|info| { // TODO: handle occlusion_texture.tex_coord() (the *set* index for the right texcoords) // TODO: handle occlusion_texture.strength() (a scalar multiplier for occlusion strength) let label = texture_label(&info.texture()); let path = AssetPath::new_ref(load_context.path(), Some(&label)); - Some(load_context.get_handle(path)) - } else { - None - }; + load_context.get_handle(path) + }); load_context.set_labeled_asset( &material_label, diff --git a/crates/bevy_pbr/src/light.rs b/crates/bevy_pbr/src/light.rs index c8e58b31db..d72546efac 100644 --- a/crates/bevy_pbr/src/light.rs +++ b/crates/bevy_pbr/src/light.rs @@ -328,8 +328,7 @@ impl ClusterConfig { fn first_slice_depth(&self) -> f32 { match self { - ClusterConfig::None => 0.0, - ClusterConfig::Single => 0.0, + ClusterConfig::None | ClusterConfig::Single => 0.0, ClusterConfig::XYZ { z_config, .. } | ClusterConfig::FixedZ { z_config, .. } => { z_config.first_slice_depth } @@ -880,7 +879,7 @@ pub(crate) fn assign_lights_to_clusters( let inverse_projection = camera.projection_matrix.inverse(); - for lights in clusters.lights.iter_mut() { + for lights in &mut clusters.lights { lights.entities.clear(); } clusters.lights.resize_with( diff --git a/crates/bevy_pbr/src/pbr_material.rs b/crates/bevy_pbr/src/pbr_material.rs index 14e02c8b6c..cfca9a613a 100644 --- a/crates/bevy_pbr/src/pbr_material.rs +++ b/crates/bevy_pbr/src/pbr_material.rs @@ -265,7 +265,7 @@ impl RenderAsset for StandardMaterial { | TextureFormat::Rg16Unorm | TextureFormat::Bc5RgUnorm | TextureFormat::EacRg11Unorm => { - flags |= StandardMaterialFlags::TWO_COMPONENT_NORMAL_MAP + flags |= StandardMaterialFlags::TWO_COMPONENT_NORMAL_MAP; } _ => {} } diff --git a/crates/bevy_pbr/src/render/mesh.rs b/crates/bevy_pbr/src/render/mesh.rs index 857b2b9fbe..c946720b6f 100644 --- a/crates/bevy_pbr/src/render/mesh.rs +++ b/crates/bevy_pbr/src/render/mesh.rs @@ -741,7 +741,7 @@ pub fn prepare_skinned_meshes( skinned_mesh_uniform .buffer .reserve(extracted_joints.buffer.len(), &render_device); - for joint in extracted_joints.buffer.iter() { + for joint in &extracted_joints.buffer { skinned_mesh_uniform.buffer.push(*joint); } skinned_mesh_uniform diff --git a/crates/bevy_pbr/src/wireframe.rs b/crates/bevy_pbr/src/wireframe.rs index e2abbec39e..b6bf1646a2 100644 --- a/crates/bevy_pbr/src/wireframe.rs +++ b/crates/bevy_pbr/src/wireframe.rs @@ -97,7 +97,6 @@ impl SpecializedMeshPipeline for WireframePipeline { } #[allow(clippy::too_many_arguments)] -#[allow(clippy::type_complexity)] fn queue_wireframes( opaque_3d_draw_functions: Res>, render_meshes: Res>, diff --git a/crates/bevy_ptr/src/lib.rs b/crates/bevy_ptr/src/lib.rs index 075751a449..e8173f674c 100644 --- a/crates/bevy_ptr/src/lib.rs +++ b/crates/bevy_ptr/src/lib.rs @@ -180,7 +180,7 @@ impl<'a> OwningPtr<'a> { /// Must point to a valid `T`. #[inline] pub unsafe fn drop_as(self) { - self.as_ptr().cast::().drop_in_place() + self.as_ptr().cast::().drop_in_place(); } /// Gets the underlying pointer, erasing the associated lifetime. 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 8adb2dbcda..a8017dc30e 100644 --- a/crates/bevy_reflect/bevy_reflect_derive/src/type_uuid.rs +++ b/crates/bevy_reflect/bevy_reflect_derive/src/type_uuid.rs @@ -17,7 +17,7 @@ pub(crate) fn type_uuid_derive(input: proc_macro::TokenStream) -> proc_macro::To ast.generics.type_params_mut().for_each(|param| { param .bounds - .push(syn::parse_quote!(#bevy_reflect_path::TypeUuid)) + .push(syn::parse_quote!(#bevy_reflect_path::TypeUuid)); }); let (impl_generics, type_generics, where_clause) = &ast.generics.split_for_impl(); diff --git a/crates/bevy_reflect/src/array.rs b/crates/bevy_reflect/src/array.rs index 93fc045036..45271d5ddc 100644 --- a/crates/bevy_reflect/src/array.rs +++ b/crates/bevy_reflect/src/array.rs @@ -217,7 +217,7 @@ pub fn array_hash(array: &A) -> Option { std::any::Any::type_id(array).hash(&mut hasher); array.len().hash(&mut hasher); for value in array.iter() { - hasher.write_u64(value.reflect_hash()?) + hasher.write_u64(value.reflect_hash()?); } Some(hasher.finish()) } diff --git a/crates/bevy_reflect/src/impls/std.rs b/crates/bevy_reflect/src/impls/std.rs index a0d1679660..6b465a05b7 100644 --- a/crates/bevy_reflect/src/impls/std.rs +++ b/crates/bevy_reflect/src/impls/std.rs @@ -248,7 +248,7 @@ unsafe impl Reflect for HashMap { if let ReflectRef::Map(map_value) = value.reflect_ref() { for (key, value) in map_value.iter() { if let Some(v) = Map::get_mut(self, key) { - 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 15e2002725..5155895178 100644 --- a/crates/bevy_reflect/src/type_registry.rs +++ b/crates/bevy_reflect/src/type_registry.rs @@ -349,7 +349,6 @@ pub trait FromType { /// [`FromType::from_type`]. #[derive(Clone)] pub struct ReflectDeserialize { - #[allow(clippy::type_complexity)] pub func: fn( deserializer: &mut dyn erased_serde::Deserializer, ) -> Result, erased_serde::Error>, diff --git a/crates/bevy_render/src/camera/camera.rs b/crates/bevy_render/src/camera/camera.rs index 852f355364..be5ce81e46 100644 --- a/crates/bevy_render/src/camera/camera.rs +++ b/crates/bevy_render/src/camera/camera.rs @@ -164,7 +164,6 @@ impl Camera { } } -#[allow(clippy::type_complexity)] pub fn camera_system( mut window_resized_events: EventReader, mut window_created_events: EventReader, @@ -339,5 +338,5 @@ pub fn extract_cameras( } } - commands.insert_resource(active_camera.clone()) + commands.insert_resource(active_camera.clone()); } diff --git a/crates/bevy_render/src/color/mod.rs b/crates/bevy_render/src/color/mod.rs index 14c9adf4f2..20bedac8ad 100644 --- a/crates/bevy_render/src/color/mod.rs +++ b/crates/bevy_render/src/color/mod.rs @@ -835,12 +835,8 @@ impl MulAssign for Color { match self { Color::Rgba { red, green, blue, .. - } => { - *red *= rhs; - *green *= rhs; - *blue *= rhs; } - Color::RgbaLinear { + | Color::RgbaLinear { red, green, blue, .. } => { *red *= rhs; @@ -911,13 +907,8 @@ impl MulAssign for Color { green, blue, alpha, - } => { - *red *= rhs.x; - *green *= rhs.y; - *blue *= rhs.z; - *alpha *= rhs.w; } - Color::RgbaLinear { + | Color::RgbaLinear { red, green, blue, @@ -990,12 +981,8 @@ impl MulAssign for Color { match self { Color::Rgba { red, green, blue, .. - } => { - *red *= rhs.x; - *green *= rhs.y; - *blue *= rhs.z; } - Color::RgbaLinear { + | Color::RgbaLinear { red, green, blue, .. } => { *red *= rhs.x; @@ -1066,13 +1053,8 @@ impl MulAssign<[f32; 4]> for Color { green, blue, alpha, - } => { - *red *= rhs[0]; - *green *= rhs[1]; - *blue *= rhs[2]; - *alpha *= rhs[3]; } - Color::RgbaLinear { + | Color::RgbaLinear { red, green, blue, @@ -1145,12 +1127,8 @@ impl MulAssign<[f32; 3]> for Color { match self { Color::Rgba { red, green, blue, .. - } => { - *red *= rhs[0]; - *green *= rhs[1]; - *blue *= rhs[2]; } - Color::RgbaLinear { + | Color::RgbaLinear { red, green, blue, .. } => { *red *= rhs[0]; diff --git a/crates/bevy_render/src/mesh/mesh/conversions.rs b/crates/bevy_render/src/mesh/mesh/conversions.rs index 6270389432..cb4c85db89 100644 --- a/crates/bevy_render/src/mesh/mesh/conversions.rs +++ b/crates/bevy_render/src/mesh/mesh/conversions.rs @@ -134,8 +134,9 @@ impl TryFrom for Vec<[u8; 4]> { fn try_from(value: VertexAttributeValues) -> Result { match value { - VertexAttributeValues::Uint8x4(value) => Ok(value), - VertexAttributeValues::Unorm8x4(value) => Ok(value), + VertexAttributeValues::Uint8x4(value) | VertexAttributeValues::Unorm8x4(value) => { + Ok(value) + } _ => Err(FromVertexAttributeError::new::(value)), } } @@ -146,8 +147,9 @@ impl TryFrom for Vec<[i8; 4]> { fn try_from(value: VertexAttributeValues) -> Result { match value { - VertexAttributeValues::Sint8x4(value) => Ok(value), - VertexAttributeValues::Snorm8x4(value) => Ok(value), + VertexAttributeValues::Sint8x4(value) | VertexAttributeValues::Snorm8x4(value) => { + Ok(value) + } _ => Err(FromVertexAttributeError::new::(value)), } } @@ -158,8 +160,9 @@ impl TryFrom for Vec<[u8; 2]> { fn try_from(value: VertexAttributeValues) -> Result { match value { - VertexAttributeValues::Uint8x2(value) => Ok(value), - VertexAttributeValues::Unorm8x2(value) => Ok(value), + VertexAttributeValues::Uint8x2(value) | VertexAttributeValues::Unorm8x2(value) => { + Ok(value) + } _ => Err(FromVertexAttributeError::new::(value)), } } @@ -170,8 +173,9 @@ impl TryFrom for Vec<[i8; 2]> { fn try_from(value: VertexAttributeValues) -> Result { match value { - VertexAttributeValues::Sint8x2(value) => Ok(value), - VertexAttributeValues::Snorm8x2(value) => Ok(value), + VertexAttributeValues::Sint8x2(value) | VertexAttributeValues::Snorm8x2(value) => { + Ok(value) + } _ => Err(FromVertexAttributeError::new::(value)), } } @@ -182,8 +186,9 @@ impl TryFrom for Vec<[i16; 4]> { fn try_from(value: VertexAttributeValues) -> Result { match value { - VertexAttributeValues::Sint16x4(value) => Ok(value), - VertexAttributeValues::Snorm16x4(value) => Ok(value), + VertexAttributeValues::Sint16x4(value) | VertexAttributeValues::Snorm16x4(value) => { + Ok(value) + } _ => Err(FromVertexAttributeError::new::(value)), } } @@ -194,8 +199,9 @@ impl TryFrom for Vec<[u16; 4]> { fn try_from(value: VertexAttributeValues) -> Result { match value { - VertexAttributeValues::Uint16x4(value) => Ok(value), - VertexAttributeValues::Unorm16x4(value) => Ok(value), + VertexAttributeValues::Uint16x4(value) | VertexAttributeValues::Unorm16x4(value) => { + Ok(value) + } _ => Err(FromVertexAttributeError::new::(value)), } } @@ -206,8 +212,9 @@ impl TryFrom for Vec<[u16; 2]> { fn try_from(value: VertexAttributeValues) -> Result { match value { - VertexAttributeValues::Uint16x2(value) => Ok(value), - VertexAttributeValues::Unorm16x2(value) => Ok(value), + VertexAttributeValues::Uint16x2(value) | VertexAttributeValues::Unorm16x2(value) => { + Ok(value) + } _ => Err(FromVertexAttributeError::new::(value)), } } @@ -218,8 +225,9 @@ impl TryFrom for Vec<[i16; 2]> { fn try_from(value: VertexAttributeValues) -> Result { match value { - VertexAttributeValues::Sint16x2(value) => Ok(value), - VertexAttributeValues::Snorm16x2(value) => Ok(value), + VertexAttributeValues::Sint16x2(value) | VertexAttributeValues::Snorm16x2(value) => { + Ok(value) + } _ => Err(FromVertexAttributeError::new::(value)), } } diff --git a/crates/bevy_render/src/mesh/mesh/mod.rs b/crates/bevy_render/src/mesh/mesh/mod.rs index 12623a27be..f430da709a 100644 --- a/crates/bevy_render/src/mesh/mesh/mod.rs +++ b/crates/bevy_render/src/mesh/mesh/mod.rs @@ -203,7 +203,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_id, attribute_data) in self.attributes.iter() { + for (attribute_id, attribute_data) in &self.attributes { let attribute_len = attribute_data.values.len(); if let Some(previous_vertex_count) = vertex_count { assert_eq!(previous_vertex_count, attribute_len, @@ -253,6 +253,7 @@ impl Mesh { /// /// This can dramatically increase the vertex count, so make sure this is what you want. /// Does nothing if no [Indices] are set. + #[allow(clippy::match_same_arms)] pub fn duplicate_vertices(&mut self) { fn duplicate(values: &[T], indices: impl Iterator) -> Vec { indices.map(|i| values[i]).collect() @@ -430,7 +431,7 @@ impl InnerMeshVertexBufferLayout { format: layout_attribute.format, offset: layout_attribute.offset, shader_location: attribute_descriptor.shader_location, - }) + }); } else { return Err(MissingVertexAttributeError { id: attribute_descriptor.id, @@ -491,6 +492,7 @@ pub trait VertexFormatSize { } impl VertexFormatSize for wgpu::VertexFormat { + #[allow(clippy::match_same_arms)] fn get_size(self) -> u64 { match self { VertexFormat::Uint8x2 => 2, @@ -568,6 +570,7 @@ pub enum VertexAttributeValues { impl VertexAttributeValues { /// Returns the number of vertices in this [`VertexAttributeValues`]. For a single /// mesh, all of the [`VertexAttributeValues`] must have the same length. + #[allow(clippy::match_same_arms)] pub fn len(&self) -> usize { match *self { VertexAttributeValues::Float32(ref values) => values.len(), @@ -617,6 +620,7 @@ impl VertexAttributeValues { // TODO: add vertex format as parameter here and perform type conversions /// Flattens the [`VertexAttributeValues`] into a sequence of bytes. This is /// useful for serialization and sending to the GPU. + #[allow(clippy::match_same_arms)] pub fn get_bytes(&self) -> &[u8] { match self { VertexAttributeValues::Float32(values) => cast_slice(&values[..]), diff --git a/crates/bevy_render/src/render_asset.rs b/crates/bevy_render/src/render_asset.rs index 3ee311ffda..22936f3e67 100644 --- a/crates/bevy_render/src/render_asset.rs +++ b/crates/bevy_render/src/render_asset.rs @@ -135,10 +135,7 @@ fn extract_render_asset( let mut removed = Vec::new(); for event in events.iter() { match event { - AssetEvent::Created { handle } => { - changed_assets.insert(handle); - } - AssetEvent::Modified { handle } => { + AssetEvent::Created { handle } | AssetEvent::Modified { handle } => { changed_assets.insert(handle); } AssetEvent::Removed { handle } => { diff --git a/crates/bevy_render/src/render_graph/edge.rs b/crates/bevy_render/src/render_graph/edge.rs index 0b3fe5432e..88bfe24f9c 100644 --- a/crates/bevy_render/src/render_graph/edge.rs +++ b/crates/bevy_render/src/render_graph/edge.rs @@ -35,16 +35,14 @@ impl Edge { /// Returns the id of the `input_node`. pub fn get_input_node(&self) -> NodeId { match self { - Edge::SlotEdge { input_node, .. } => *input_node, - Edge::NodeEdge { input_node, .. } => *input_node, + Edge::SlotEdge { input_node, .. } | Edge::NodeEdge { input_node, .. } => *input_node, } } /// Returns the id of the `output_node`. pub fn get_output_node(&self) -> NodeId { match self { - Edge::SlotEdge { output_node, .. } => *output_node, - Edge::NodeEdge { output_node, .. } => *output_node, + Edge::SlotEdge { output_node, .. } | Edge::NodeEdge { output_node, .. } => *output_node, } } } diff --git a/crates/bevy_render/src/render_graph/graph.rs b/crates/bevy_render/src/render_graph/graph.rs index 145e6cd917..c93e513cfc 100644 --- a/crates/bevy_render/src/render_graph/graph.rs +++ b/crates/bevy_render/src/render_graph/graph.rs @@ -114,17 +114,8 @@ impl RenderGraph { // node, we don't need to remove its input edges for input_edge in node_state.edges.input_edges().iter() { match input_edge { - Edge::SlotEdge { - output_node, - output_index: _, - input_node: _, - input_index: _, - } => { - if let Ok(output_node) = self.get_node_state_mut(*output_node) { - output_node.edges.remove_output_edge(input_edge.clone())?; - } - } - Edge::NodeEdge { + Edge::SlotEdge { output_node, .. } + | Edge::NodeEdge { input_node: _, output_node, } => { @@ -143,12 +134,8 @@ impl RenderGraph { output_index: _, input_node, input_index: _, - } => { - if let Ok(input_node) = self.get_node_state_mut(*input_node) { - input_node.edges.remove_input_edge(output_edge.clone())?; - } } - Edge::NodeEdge { + | Edge::NodeEdge { output_node: _, input_node, } => { diff --git a/crates/bevy_render/src/render_phase/draw_state.rs b/crates/bevy_render/src/render_phase/draw_state.rs index 81a5f9590d..5668d06a59 100644 --- a/crates/bevy_render/src/render_phase/draw_state.rs +++ b/crates/bevy_render/src/render_phase/draw_state.rs @@ -135,14 +135,14 @@ impl<'a> TrackedRenderPass<'a> { dynamic_uniform_indices ); return; - } else { - trace!( - "set bind_group {}: {:?} ({:?})", - index, - bind_group, - dynamic_uniform_indices - ); } + trace!( + "set bind_group {}: {:?} ({:?})", + index, + bind_group, + dynamic_uniform_indices + ); + self.pass .set_bind_group(index as u32, bind_group, dynamic_uniform_indices); self.state @@ -169,14 +169,14 @@ impl<'a> TrackedRenderPass<'a> { offset ); return; - } else { - trace!( - "set vertex buffer {}: {:?} ({})", - slot_index, - buffer_slice.id(), - offset - ); } + trace!( + "set vertex buffer {}: {:?} ({})", + slot_index, + buffer_slice.id(), + offset + ); + self.pass .set_vertex_buffer(slot_index as u32, *buffer_slice); self.state @@ -203,9 +203,8 @@ impl<'a> TrackedRenderPass<'a> { offset ); return; - } else { - trace!("set index buffer: {:?} ({})", buffer_slice.id(), offset); } + trace!("set index buffer: {:?} ({})", buffer_slice.id(), offset); self.pass.set_index_buffer(*buffer_slice, index_format); self.state .set_index_buffer(buffer_slice.id(), offset, index_format); diff --git a/crates/bevy_render/src/render_resource/shader.rs b/crates/bevy_render/src/render_resource/shader.rs index 38b8843258..dd0699992a 100644 --- a/crates/bevy_render/src/render_resource/shader.rs +++ b/crates/bevy_render/src/render_resource/shader.rs @@ -379,9 +379,8 @@ impl ShaderProcessor { Source::SpirV(source) => { if shader_defs.is_empty() { return Ok(ProcessedShader::SpirV(source.clone())); - } else { - return Err(ProcessShaderError::ShaderFormatDoesNotSupportShaderDefs); } + return Err(ProcessShaderError::ShaderFormatDoesNotSupportShaderDefs); } }; diff --git a/crates/bevy_render/src/renderer/graph_runner.rs b/crates/bevy_render/src/renderer/graph_runner.rs index 413642bc3c..12d6384d20 100644 --- a/crates/bevy_render/src/renderer/graph_runner.rs +++ b/crates/bevy_render/src/renderer/graph_runner.rs @@ -101,9 +101,8 @@ impl RenderGraphRunner { expected: input_slot.slot_type, label: input_slot.name.clone().into(), }); - } else { - input_values.push(input_value.clone()); } + input_values.push(input_value.clone()); } else { return Err(RenderGraphRunnerError::MissingInput { slot_index: i, diff --git a/crates/bevy_render/src/texture/basis.rs b/crates/bevy_render/src/texture/basis.rs index 34e817c95e..256bbf8d79 100644 --- a/crates/bevy_render/src/texture/basis.rs +++ b/crates/bevy_render/src/texture/basis.rs @@ -114,9 +114,9 @@ pub fn basis_buffer_to_image( image.texture_descriptor.mip_level_count = image0_mip_level_count; image.texture_descriptor.format = texture_format; image.texture_descriptor.dimension = match texture_type { - BasisTextureType::TextureType2D => TextureDimension::D2, - BasisTextureType::TextureType2DArray => TextureDimension::D2, - BasisTextureType::TextureTypeCubemapArray => TextureDimension::D2, + BasisTextureType::TextureType2D + | BasisTextureType::TextureType2DArray + | BasisTextureType::TextureTypeCubemapArray => TextureDimension::D2, BasisTextureType::TextureTypeVolume => TextureDimension::D3, basis_texture_type => { return Err(TextureError::UnsupportedTextureFormat(format!( diff --git a/crates/bevy_render/src/texture/dds.rs b/crates/bevy_render/src/texture/dds.rs index 49db9d090c..e320591885 100644 --- a/crates/bevy_render/src/texture/dds.rs +++ b/crates/bevy_render/src/texture/dds.rs @@ -74,14 +74,14 @@ pub fn dds_format_to_texture_format( TextureFormat::Bc1RgbaUnorm } } - D3DFormat::DXT3 => { + D3DFormat::DXT3 | D3DFormat::DXT2 => { if is_srgb { TextureFormat::Bc2RgbaUnormSrgb } else { TextureFormat::Bc2RgbaUnorm } } - D3DFormat::DXT5 => { + D3DFormat::DXT5 | D3DFormat::DXT4 => { if is_srgb { TextureFormat::Bc3RgbaUnormSrgb } else { @@ -96,20 +96,6 @@ pub fn dds_format_to_texture_format( D3DFormat::R32F => TextureFormat::R32Float, D3DFormat::G32R32F => TextureFormat::Rg32Float, D3DFormat::A32B32G32R32F => TextureFormat::Rgba32Float, - D3DFormat::DXT2 => { - if is_srgb { - TextureFormat::Bc2RgbaUnormSrgb - } else { - TextureFormat::Bc2RgbaUnorm - } - } - D3DFormat::DXT4 => { - if is_srgb { - TextureFormat::Bc3RgbaUnormSrgb - } else { - TextureFormat::Bc3RgbaUnorm - } - } D3DFormat::A1R5G5B5 | D3DFormat::R5G6B5 // FIXME: Map to argb format and user has to know to ignore the alpha channel? @@ -136,38 +122,28 @@ pub fn dds_format_to_texture_format( } } else if let Some(dxgi_format) = dds.get_dxgi_format() { match dxgi_format { - DxgiFormat::R32G32B32A32_Typeless => TextureFormat::Rgba32Float, - DxgiFormat::R32G32B32A32_Float => TextureFormat::Rgba32Float, + DxgiFormat::R32G32B32A32_Typeless | DxgiFormat::R32G32B32A32_Float => { + TextureFormat::Rgba32Float + } DxgiFormat::R32G32B32A32_UInt => TextureFormat::Rgba32Uint, DxgiFormat::R32G32B32A32_SInt => TextureFormat::Rgba32Sint, - DxgiFormat::R16G16B16A16_Typeless => TextureFormat::Rgba16Float, - DxgiFormat::R16G16B16A16_Float => TextureFormat::Rgba16Float, + DxgiFormat::R16G16B16A16_Typeless | DxgiFormat::R16G16B16A16_Float => { + TextureFormat::Rgba16Float + } DxgiFormat::R16G16B16A16_UNorm => TextureFormat::Rgba16Unorm, DxgiFormat::R16G16B16A16_UInt => TextureFormat::Rgba16Uint, DxgiFormat::R16G16B16A16_SNorm => TextureFormat::Rgba16Snorm, DxgiFormat::R16G16B16A16_SInt => TextureFormat::Rgba16Sint, - DxgiFormat::R32G32_Typeless => TextureFormat::Rg32Float, - DxgiFormat::R32G32_Float => TextureFormat::Rg32Float, + DxgiFormat::R32G32_Typeless | DxgiFormat::R32G32_Float => TextureFormat::Rg32Float, DxgiFormat::R32G32_UInt => TextureFormat::Rg32Uint, DxgiFormat::R32G32_SInt => TextureFormat::Rg32Sint, - DxgiFormat::R10G10B10A2_Typeless => TextureFormat::Rgb10a2Unorm, - DxgiFormat::R10G10B10A2_UNorm => TextureFormat::Rgb10a2Unorm, + DxgiFormat::R10G10B10A2_Typeless | DxgiFormat::R10G10B10A2_UNorm => { + TextureFormat::Rgb10a2Unorm + } DxgiFormat::R11G11B10_Float => TextureFormat::Rg11b10Float, - DxgiFormat::R8G8B8A8_Typeless => { - if is_srgb { - TextureFormat::Rgba8UnormSrgb - } else { - TextureFormat::Rgba8Unorm - } - } - DxgiFormat::R8G8B8A8_UNorm => { - if is_srgb { - TextureFormat::Rgba8UnormSrgb - } else { - TextureFormat::Rgba8Unorm - } - } - DxgiFormat::R8G8B8A8_UNorm_sRGB => { + DxgiFormat::R8G8B8A8_Typeless + | DxgiFormat::R8G8B8A8_UNorm + | DxgiFormat::R8G8B8A8_UNorm_sRGB => { if is_srgb { TextureFormat::Rgba8UnormSrgb } else { @@ -177,121 +153,61 @@ pub fn dds_format_to_texture_format( DxgiFormat::R8G8B8A8_UInt => TextureFormat::Rgba8Uint, DxgiFormat::R8G8B8A8_SNorm => TextureFormat::Rgba8Snorm, DxgiFormat::R8G8B8A8_SInt => TextureFormat::Rgba8Sint, - DxgiFormat::R16G16_Typeless => TextureFormat::Rg16Float, - DxgiFormat::R16G16_Float => TextureFormat::Rg16Float, + DxgiFormat::R16G16_Typeless | DxgiFormat::R16G16_Float => TextureFormat::Rg16Float, DxgiFormat::R16G16_UNorm => TextureFormat::Rg16Unorm, DxgiFormat::R16G16_UInt => TextureFormat::Rg16Uint, DxgiFormat::R16G16_SNorm => TextureFormat::Rg16Snorm, DxgiFormat::R16G16_SInt => TextureFormat::Rg16Sint, - DxgiFormat::R32_Typeless => TextureFormat::R32Float, + DxgiFormat::R32_Typeless | DxgiFormat::R32_Float => TextureFormat::R32Float, DxgiFormat::D32_Float => TextureFormat::Depth32Float, - DxgiFormat::R32_Float => TextureFormat::R32Float, DxgiFormat::R32_UInt => TextureFormat::R32Uint, DxgiFormat::R32_SInt => TextureFormat::R32Sint, - DxgiFormat::R24G8_Typeless => TextureFormat::Depth24PlusStencil8, - DxgiFormat::D24_UNorm_S8_UInt => TextureFormat::Depth24PlusStencil8, + DxgiFormat::R24G8_Typeless | DxgiFormat::D24_UNorm_S8_UInt => { + TextureFormat::Depth24PlusStencil8 + } DxgiFormat::R24_UNorm_X8_Typeless => TextureFormat::Depth24Plus, - DxgiFormat::R8G8_Typeless => TextureFormat::Rg8Unorm, - DxgiFormat::R8G8_UNorm => TextureFormat::Rg8Unorm, + DxgiFormat::R8G8_Typeless | DxgiFormat::R8G8_UNorm => TextureFormat::Rg8Unorm, DxgiFormat::R8G8_UInt => TextureFormat::Rg8Uint, DxgiFormat::R8G8_SNorm => TextureFormat::Rg8Snorm, DxgiFormat::R8G8_SInt => TextureFormat::Rg8Sint, - DxgiFormat::R16_Typeless => TextureFormat::R16Float, - DxgiFormat::R16_Float => TextureFormat::R16Float, + DxgiFormat::R16_Typeless | DxgiFormat::R16_Float => TextureFormat::R16Float, DxgiFormat::R16_UNorm => TextureFormat::R16Unorm, DxgiFormat::R16_UInt => TextureFormat::R16Uint, DxgiFormat::R16_SNorm => TextureFormat::R16Snorm, DxgiFormat::R16_SInt => TextureFormat::R16Sint, - DxgiFormat::R8_Typeless => TextureFormat::R8Unorm, - DxgiFormat::R8_UNorm => TextureFormat::R8Unorm, + DxgiFormat::R8_Typeless | DxgiFormat::R8_UNorm => TextureFormat::R8Unorm, DxgiFormat::R8_UInt => TextureFormat::R8Uint, DxgiFormat::R8_SNorm => TextureFormat::R8Snorm, DxgiFormat::R8_SInt => TextureFormat::R8Sint, DxgiFormat::R9G9B9E5_SharedExp => TextureFormat::Rgb9e5Ufloat, - DxgiFormat::BC1_Typeless => { + DxgiFormat::BC1_Typeless | DxgiFormat::BC1_UNorm | DxgiFormat::BC1_UNorm_sRGB => { if is_srgb { TextureFormat::Bc1RgbaUnormSrgb } else { TextureFormat::Bc1RgbaUnorm } } - DxgiFormat::BC1_UNorm => { - if is_srgb { - TextureFormat::Bc1RgbaUnormSrgb - } else { - TextureFormat::Bc1RgbaUnorm - } - } - DxgiFormat::BC1_UNorm_sRGB => { - if is_srgb { - TextureFormat::Bc1RgbaUnormSrgb - } else { - TextureFormat::Bc1RgbaUnorm - } - } - DxgiFormat::BC2_Typeless => { + DxgiFormat::BC2_Typeless | DxgiFormat::BC2_UNorm | DxgiFormat::BC2_UNorm_sRGB => { if is_srgb { TextureFormat::Bc2RgbaUnormSrgb } else { TextureFormat::Bc2RgbaUnorm } } - DxgiFormat::BC2_UNorm => { - if is_srgb { - TextureFormat::Bc2RgbaUnormSrgb - } else { - TextureFormat::Bc2RgbaUnorm - } - } - DxgiFormat::BC2_UNorm_sRGB => { - if is_srgb { - TextureFormat::Bc2RgbaUnormSrgb - } else { - TextureFormat::Bc2RgbaUnorm - } - } - DxgiFormat::BC3_Typeless => { + DxgiFormat::BC3_Typeless | DxgiFormat::BC3_UNorm | DxgiFormat::BC3_UNorm_sRGB => { if is_srgb { TextureFormat::Bc3RgbaUnormSrgb } else { TextureFormat::Bc3RgbaUnorm } } - DxgiFormat::BC3_UNorm => { - if is_srgb { - TextureFormat::Bc3RgbaUnormSrgb - } else { - TextureFormat::Bc3RgbaUnorm - } - } - DxgiFormat::BC3_UNorm_sRGB => { - if is_srgb { - TextureFormat::Bc3RgbaUnormSrgb - } else { - TextureFormat::Bc3RgbaUnorm - } - } - DxgiFormat::BC4_Typeless => TextureFormat::Bc4RUnorm, - DxgiFormat::BC4_UNorm => TextureFormat::Bc4RUnorm, + DxgiFormat::BC4_Typeless | DxgiFormat::BC4_UNorm => TextureFormat::Bc4RUnorm, DxgiFormat::BC4_SNorm => TextureFormat::Bc4RSnorm, - DxgiFormat::BC5_Typeless => TextureFormat::Bc5RgUnorm, - DxgiFormat::BC5_UNorm => TextureFormat::Bc5RgUnorm, + DxgiFormat::BC5_Typeless | DxgiFormat::BC5_UNorm => TextureFormat::Bc5RgUnorm, DxgiFormat::BC5_SNorm => TextureFormat::Bc5RgSnorm, - DxgiFormat::B8G8R8A8_UNorm => { - if is_srgb { - TextureFormat::Bgra8UnormSrgb - } else { - TextureFormat::Bgra8Unorm - } - } - DxgiFormat::B8G8R8A8_Typeless => { - if is_srgb { - TextureFormat::Bgra8UnormSrgb - } else { - TextureFormat::Bgra8Unorm - } - } - DxgiFormat::B8G8R8A8_UNorm_sRGB => { + DxgiFormat::B8G8R8A8_UNorm + | DxgiFormat::B8G8R8A8_Typeless + | DxgiFormat::B8G8R8A8_UNorm_sRGB => { if is_srgb { TextureFormat::Bgra8UnormSrgb } else { @@ -299,24 +215,9 @@ pub fn dds_format_to_texture_format( } } - DxgiFormat::BC6H_Typeless => TextureFormat::Bc6hRgbUfloat, - DxgiFormat::BC6H_UF16 => TextureFormat::Bc6hRgbUfloat, + DxgiFormat::BC6H_Typeless | DxgiFormat::BC6H_UF16 => TextureFormat::Bc6hRgbUfloat, DxgiFormat::BC6H_SF16 => TextureFormat::Bc6hRgbSfloat, - DxgiFormat::BC7_Typeless => { - if is_srgb { - TextureFormat::Bc7RgbaUnormSrgb - } else { - TextureFormat::Bc7RgbaUnorm - } - } - DxgiFormat::BC7_UNorm => { - if is_srgb { - TextureFormat::Bc7RgbaUnormSrgb - } else { - TextureFormat::Bc7RgbaUnorm - } - } - DxgiFormat::BC7_UNorm_sRGB => { + DxgiFormat::BC7_Typeless | DxgiFormat::BC7_UNorm | DxgiFormat::BC7_UNorm_sRGB => { if is_srgb { TextureFormat::Bc7RgbaUnormSrgb } else { diff --git a/crates/bevy_render/src/texture/image.rs b/crates/bevy_render/src/texture/image.rs index b355fc43c0..6253913d7f 100644 --- a/crates/bevy_render/src/texture/image.rs +++ b/crates/bevy_render/src/texture/image.rs @@ -49,14 +49,12 @@ pub enum ImageFormat { impl ImageFormat { pub fn from_mime_type(mime_type: &str) -> Option { Some(match mime_type.to_ascii_lowercase().as_str() { - "image/bmp" => ImageFormat::Bmp, - "image/x-bmp" => ImageFormat::Bmp, + "image/bmp" | "image/x-bmp" => ImageFormat::Bmp, "image/vnd-ms.dds" => ImageFormat::Dds, "image/jpeg" => ImageFormat::Jpeg, "image/ktx2" => ImageFormat::Ktx2, "image/png" => ImageFormat::Png, - "image/x-targa" => ImageFormat::Tga, - "image/x-tga" => ImageFormat::Tga, + "image/x-targa" | "image/x-tga" => ImageFormat::Tga, _ => return None, }) } @@ -85,7 +83,6 @@ impl ImageFormat { pub fn as_image_crate_format(&self) -> Option { Some(match self { ImageFormat::Avif => image::ImageFormat::Avif, - ImageFormat::Basis => return None, ImageFormat::Bmp => image::ImageFormat::Bmp, ImageFormat::Dds => image::ImageFormat::Dds, ImageFormat::Farbfeld => image::ImageFormat::Farbfeld, @@ -93,12 +90,12 @@ impl ImageFormat { ImageFormat::Hdr => image::ImageFormat::Hdr, ImageFormat::Ico => image::ImageFormat::Ico, ImageFormat::Jpeg => image::ImageFormat::Jpeg, - ImageFormat::Ktx2 => return None, ImageFormat::Png => image::ImageFormat::Png, ImageFormat::Pnm => image::ImageFormat::Pnm, ImageFormat::Tga => image::ImageFormat::Tga, ImageFormat::Tiff => image::ImageFormat::Tiff, ImageFormat::WebP => image::ImageFormat::WebP, + ImageFormat::Basis | ImageFormat::Ktx2 => return None, }) } } @@ -423,6 +420,7 @@ pub trait TextureFormatPixelInfo { } impl TextureFormatPixelInfo for TextureFormat { + #[allow(clippy::match_same_arms)] fn pixel_info(&self) -> PixelInfo { let type_size = match self { // 8bit @@ -634,62 +632,58 @@ impl CompressedImageFormats { pub fn supports(&self, format: TextureFormat) -> bool { match format { - TextureFormat::Bc1RgbaUnorm => self.contains(CompressedImageFormats::BC), - TextureFormat::Bc1RgbaUnormSrgb => self.contains(CompressedImageFormats::BC), - TextureFormat::Bc2RgbaUnorm => self.contains(CompressedImageFormats::BC), - TextureFormat::Bc2RgbaUnormSrgb => self.contains(CompressedImageFormats::BC), - TextureFormat::Bc3RgbaUnorm => self.contains(CompressedImageFormats::BC), - TextureFormat::Bc3RgbaUnormSrgb => self.contains(CompressedImageFormats::BC), - TextureFormat::Bc4RUnorm => self.contains(CompressedImageFormats::BC), - TextureFormat::Bc4RSnorm => self.contains(CompressedImageFormats::BC), - TextureFormat::Bc5RgUnorm => self.contains(CompressedImageFormats::BC), - TextureFormat::Bc5RgSnorm => self.contains(CompressedImageFormats::BC), - TextureFormat::Bc6hRgbUfloat => self.contains(CompressedImageFormats::BC), - TextureFormat::Bc6hRgbSfloat => self.contains(CompressedImageFormats::BC), - TextureFormat::Bc7RgbaUnorm => self.contains(CompressedImageFormats::BC), - TextureFormat::Bc7RgbaUnormSrgb => self.contains(CompressedImageFormats::BC), - TextureFormat::Etc2Rgb8Unorm => self.contains(CompressedImageFormats::ETC2), - TextureFormat::Etc2Rgb8UnormSrgb => self.contains(CompressedImageFormats::ETC2), - TextureFormat::Etc2Rgb8A1Unorm => self.contains(CompressedImageFormats::ETC2), - TextureFormat::Etc2Rgb8A1UnormSrgb => self.contains(CompressedImageFormats::ETC2), - TextureFormat::Etc2Rgba8Unorm => self.contains(CompressedImageFormats::ETC2), - TextureFormat::Etc2Rgba8UnormSrgb => self.contains(CompressedImageFormats::ETC2), - TextureFormat::EacR11Unorm => self.contains(CompressedImageFormats::ETC2), - TextureFormat::EacR11Snorm => self.contains(CompressedImageFormats::ETC2), - TextureFormat::EacRg11Unorm => self.contains(CompressedImageFormats::ETC2), - TextureFormat::EacRg11Snorm => self.contains(CompressedImageFormats::ETC2), - TextureFormat::Astc4x4RgbaUnorm => self.contains(CompressedImageFormats::ASTC_LDR), - TextureFormat::Astc4x4RgbaUnormSrgb => self.contains(CompressedImageFormats::ASTC_LDR), - TextureFormat::Astc5x4RgbaUnorm => self.contains(CompressedImageFormats::ASTC_LDR), - TextureFormat::Astc5x4RgbaUnormSrgb => self.contains(CompressedImageFormats::ASTC_LDR), - TextureFormat::Astc5x5RgbaUnorm => self.contains(CompressedImageFormats::ASTC_LDR), - TextureFormat::Astc5x5RgbaUnormSrgb => self.contains(CompressedImageFormats::ASTC_LDR), - TextureFormat::Astc6x5RgbaUnorm => self.contains(CompressedImageFormats::ASTC_LDR), - TextureFormat::Astc6x5RgbaUnormSrgb => self.contains(CompressedImageFormats::ASTC_LDR), - TextureFormat::Astc6x6RgbaUnorm => self.contains(CompressedImageFormats::ASTC_LDR), - TextureFormat::Astc6x6RgbaUnormSrgb => self.contains(CompressedImageFormats::ASTC_LDR), - TextureFormat::Astc8x5RgbaUnorm => self.contains(CompressedImageFormats::ASTC_LDR), - TextureFormat::Astc8x5RgbaUnormSrgb => self.contains(CompressedImageFormats::ASTC_LDR), - TextureFormat::Astc8x6RgbaUnorm => self.contains(CompressedImageFormats::ASTC_LDR), - TextureFormat::Astc8x6RgbaUnormSrgb => self.contains(CompressedImageFormats::ASTC_LDR), - TextureFormat::Astc10x5RgbaUnorm => self.contains(CompressedImageFormats::ASTC_LDR), - TextureFormat::Astc10x5RgbaUnormSrgb => self.contains(CompressedImageFormats::ASTC_LDR), - TextureFormat::Astc10x6RgbaUnorm => self.contains(CompressedImageFormats::ASTC_LDR), - TextureFormat::Astc10x6RgbaUnormSrgb => self.contains(CompressedImageFormats::ASTC_LDR), - TextureFormat::Astc8x8RgbaUnorm => self.contains(CompressedImageFormats::ASTC_LDR), - TextureFormat::Astc8x8RgbaUnormSrgb => self.contains(CompressedImageFormats::ASTC_LDR), - TextureFormat::Astc10x8RgbaUnorm => self.contains(CompressedImageFormats::ASTC_LDR), - TextureFormat::Astc10x8RgbaUnormSrgb => self.contains(CompressedImageFormats::ASTC_LDR), - TextureFormat::Astc10x10RgbaUnorm => self.contains(CompressedImageFormats::ASTC_LDR), - TextureFormat::Astc10x10RgbaUnormSrgb => { - self.contains(CompressedImageFormats::ASTC_LDR) - } - TextureFormat::Astc12x10RgbaUnorm => self.contains(CompressedImageFormats::ASTC_LDR), - TextureFormat::Astc12x10RgbaUnormSrgb => { - self.contains(CompressedImageFormats::ASTC_LDR) - } - TextureFormat::Astc12x12RgbaUnorm => self.contains(CompressedImageFormats::ASTC_LDR), - TextureFormat::Astc12x12RgbaUnormSrgb => { + TextureFormat::Bc1RgbaUnorm + | TextureFormat::Bc1RgbaUnormSrgb + | TextureFormat::Bc2RgbaUnorm + | TextureFormat::Bc2RgbaUnormSrgb + | TextureFormat::Bc3RgbaUnorm + | TextureFormat::Bc3RgbaUnormSrgb + | TextureFormat::Bc4RUnorm + | TextureFormat::Bc4RSnorm + | TextureFormat::Bc5RgUnorm + | TextureFormat::Bc5RgSnorm + | TextureFormat::Bc6hRgbUfloat + | TextureFormat::Bc6hRgbSfloat + | TextureFormat::Bc7RgbaUnorm + | TextureFormat::Bc7RgbaUnormSrgb => self.contains(CompressedImageFormats::BC), + TextureFormat::Etc2Rgb8Unorm + | TextureFormat::Etc2Rgb8UnormSrgb + | TextureFormat::Etc2Rgb8A1Unorm + | TextureFormat::Etc2Rgb8A1UnormSrgb + | TextureFormat::Etc2Rgba8Unorm + | TextureFormat::Etc2Rgba8UnormSrgb + | TextureFormat::EacR11Unorm + | TextureFormat::EacR11Snorm + | TextureFormat::EacRg11Unorm + | TextureFormat::EacRg11Snorm => self.contains(CompressedImageFormats::ETC2), + TextureFormat::Astc4x4RgbaUnorm + | TextureFormat::Astc4x4RgbaUnormSrgb + | TextureFormat::Astc5x4RgbaUnorm + | TextureFormat::Astc5x4RgbaUnormSrgb + | TextureFormat::Astc5x5RgbaUnorm + | TextureFormat::Astc5x5RgbaUnormSrgb + | TextureFormat::Astc6x5RgbaUnorm + | TextureFormat::Astc6x5RgbaUnormSrgb + | TextureFormat::Astc6x6RgbaUnorm + | TextureFormat::Astc6x6RgbaUnormSrgb + | TextureFormat::Astc8x5RgbaUnorm + | TextureFormat::Astc8x5RgbaUnormSrgb + | TextureFormat::Astc8x6RgbaUnorm + | TextureFormat::Astc8x6RgbaUnormSrgb + | TextureFormat::Astc10x5RgbaUnorm + | TextureFormat::Astc10x5RgbaUnormSrgb + | TextureFormat::Astc10x6RgbaUnorm + | TextureFormat::Astc10x6RgbaUnormSrgb + | TextureFormat::Astc8x8RgbaUnorm + | TextureFormat::Astc8x8RgbaUnormSrgb + | TextureFormat::Astc10x8RgbaUnorm + | TextureFormat::Astc10x8RgbaUnormSrgb + | TextureFormat::Astc10x10RgbaUnorm + | TextureFormat::Astc10x10RgbaUnormSrgb + | TextureFormat::Astc12x10RgbaUnorm + | TextureFormat::Astc12x10RgbaUnormSrgb + | TextureFormat::Astc12x12RgbaUnorm + | TextureFormat::Astc12x12RgbaUnormSrgb => { self.contains(CompressedImageFormats::ASTC_LDR) } _ => true, diff --git a/crates/bevy_render/src/texture/ktx2.rs b/crates/bevy_render/src/texture/ktx2.rs index 0bc9eb71c6..94830d7ac4 100644 --- a/crates/bevy_render/src/texture/ktx2.rs +++ b/crates/bevy_render/src/texture/ktx2.rs @@ -85,7 +85,7 @@ pub fn ktx2_buffer_to_image( TranscodeFormat::Rgb8 => { let (mut original_width, mut original_height) = (width, height); - for level_data in levels.iter() { + for level_data in &levels { let n_pixels = (original_width * original_height) as usize; let mut rgba = vec![255u8; n_pixels * 4]; @@ -766,25 +766,19 @@ pub fn ktx2_dfd_to_texture_format( } } } - Some(ColorModel::YUVSDA) => { - return Err(TextureError::UnsupportedTextureFormat(format!( - "{:?}", - data_format_descriptor.color_model - ))); - } - Some(ColorModel::YIQSDA) => { - return Err(TextureError::UnsupportedTextureFormat(format!( - "{:?}", - data_format_descriptor.color_model - ))); - } - Some(ColorModel::LabSDA) => { - return Err(TextureError::UnsupportedTextureFormat(format!( - "{:?}", - data_format_descriptor.color_model - ))); - } - Some(ColorModel::CMYKA) => { + Some(ColorModel::YUVSDA) + | Some(ColorModel::YIQSDA) + | Some(ColorModel::LabSDA) + | Some(ColorModel::CMYKA) + | Some(ColorModel::HSVAAng) + | Some(ColorModel::HSLAAng) + | Some(ColorModel::HSVAHex) + | Some(ColorModel::HSLAHex) + | Some(ColorModel::YCgCoA) + | Some(ColorModel::YcCbcCrc) + | Some(ColorModel::ICtCp) + | Some(ColorModel::CIEXYZ) + | Some(ColorModel::CIEXYY) => { return Err(TextureError::UnsupportedTextureFormat(format!( "{:?}", data_format_descriptor.color_model @@ -897,60 +891,6 @@ pub fn ktx2_dfd_to_texture_format( } } } - Some(ColorModel::HSVAAng) => { - return Err(TextureError::UnsupportedTextureFormat(format!( - "{:?}", - data_format_descriptor.color_model - ))); - } - Some(ColorModel::HSLAAng) => { - return Err(TextureError::UnsupportedTextureFormat(format!( - "{:?}", - data_format_descriptor.color_model - ))); - } - Some(ColorModel::HSVAHex) => { - return Err(TextureError::UnsupportedTextureFormat(format!( - "{:?}", - data_format_descriptor.color_model - ))); - } - Some(ColorModel::HSLAHex) => { - return Err(TextureError::UnsupportedTextureFormat(format!( - "{:?}", - data_format_descriptor.color_model - ))); - } - Some(ColorModel::YCgCoA) => { - return Err(TextureError::UnsupportedTextureFormat(format!( - "{:?}", - data_format_descriptor.color_model - ))); - } - Some(ColorModel::YcCbcCrc) => { - return Err(TextureError::UnsupportedTextureFormat(format!( - "{:?}", - data_format_descriptor.color_model - ))); - } - Some(ColorModel::ICtCp) => { - return Err(TextureError::UnsupportedTextureFormat(format!( - "{:?}", - data_format_descriptor.color_model - ))); - } - Some(ColorModel::CIEXYZ) => { - return Err(TextureError::UnsupportedTextureFormat(format!( - "{:?}", - data_format_descriptor.color_model - ))); - } - Some(ColorModel::CIEXYY) => { - return Err(TextureError::UnsupportedTextureFormat(format!( - "{:?}", - data_format_descriptor.color_model - ))); - } Some(ColorModel::BC1A) => { if is_srgb { TextureFormat::Bc1RgbaUnormSrgb @@ -1281,53 +1221,31 @@ pub fn ktx2_format_to_texture_format( is_srgb: bool, ) -> Result { Ok(match ktx2_format { - ktx2::Format::R8_UNORM => { + ktx2::Format::R8_UNORM | ktx2::Format::R8_SRGB => { if is_srgb { return Err(TextureError::UnsupportedTextureFormat(format!( "{:?}", ktx2_format ))); - } else { - TextureFormat::R8Unorm } + TextureFormat::R8Unorm } ktx2::Format::R8_SNORM => TextureFormat::R8Snorm, ktx2::Format::R8_UINT => TextureFormat::R8Uint, ktx2::Format::R8_SINT => TextureFormat::R8Sint, - ktx2::Format::R8_SRGB => { + ktx2::Format::R8G8_UNORM | ktx2::Format::R8G8_SRGB => { if is_srgb { return Err(TextureError::UnsupportedTextureFormat(format!( "{:?}", ktx2_format ))); - } else { - TextureFormat::R8Unorm - } - } - ktx2::Format::R8G8_UNORM => { - if is_srgb { - return Err(TextureError::UnsupportedTextureFormat(format!( - "{:?}", - ktx2_format - ))); - } else { - TextureFormat::Rg8Unorm } + TextureFormat::Rg8Unorm } ktx2::Format::R8G8_SNORM => TextureFormat::Rg8Snorm, ktx2::Format::R8G8_UINT => TextureFormat::Rg8Uint, ktx2::Format::R8G8_SINT => TextureFormat::Rg8Sint, - ktx2::Format::R8G8_SRGB => { - if is_srgb { - return Err(TextureError::UnsupportedTextureFormat(format!( - "{:?}", - ktx2_format - ))); - } else { - TextureFormat::Rg8Unorm - } - } - ktx2::Format::R8G8B8A8_UNORM => { + ktx2::Format::R8G8B8A8_UNORM | ktx2::Format::R8G8B8A8_SRGB => { if is_srgb { TextureFormat::Rgba8UnormSrgb } else { @@ -1337,21 +1255,7 @@ pub fn ktx2_format_to_texture_format( ktx2::Format::R8G8B8A8_SNORM => TextureFormat::Rgba8Snorm, ktx2::Format::R8G8B8A8_UINT => TextureFormat::Rgba8Uint, ktx2::Format::R8G8B8A8_SINT => TextureFormat::Rgba8Sint, - ktx2::Format::R8G8B8A8_SRGB => { - if is_srgb { - TextureFormat::Rgba8UnormSrgb - } else { - TextureFormat::Rgba8Unorm - } - } - ktx2::Format::B8G8R8A8_UNORM => { - if is_srgb { - TextureFormat::Bgra8UnormSrgb - } else { - TextureFormat::Bgra8Unorm - } - } - ktx2::Format::B8G8R8A8_SRGB => { + ktx2::Format::B8G8R8A8_UNORM | ktx2::Format::B8G8R8A8_SRGB => { if is_srgb { TextureFormat::Bgra8UnormSrgb } else { @@ -1395,56 +1299,24 @@ pub fn ktx2_format_to_texture_format( ktx2::Format::D24_UNORM_S8_UINT => TextureFormat::Depth24PlusStencil8, - ktx2::Format::BC1_RGB_UNORM_BLOCK => { + ktx2::Format::BC1_RGB_UNORM_BLOCK + | ktx2::Format::BC1_RGB_SRGB_BLOCK + | ktx2::Format::BC1_RGBA_UNORM_BLOCK + | ktx2::Format::BC1_RGBA_SRGB_BLOCK => { if is_srgb { TextureFormat::Bc1RgbaUnormSrgb } else { TextureFormat::Bc1RgbaUnorm } } - ktx2::Format::BC1_RGB_SRGB_BLOCK => { - if is_srgb { - TextureFormat::Bc1RgbaUnormSrgb - } else { - TextureFormat::Bc1RgbaUnorm - } - } - ktx2::Format::BC1_RGBA_UNORM_BLOCK => { - if is_srgb { - TextureFormat::Bc1RgbaUnormSrgb - } else { - TextureFormat::Bc1RgbaUnorm - } - } - ktx2::Format::BC1_RGBA_SRGB_BLOCK => { - if is_srgb { - TextureFormat::Bc1RgbaUnormSrgb - } else { - TextureFormat::Bc1RgbaUnorm - } - } - ktx2::Format::BC2_UNORM_BLOCK => { + ktx2::Format::BC2_UNORM_BLOCK | ktx2::Format::BC2_SRGB_BLOCK => { if is_srgb { TextureFormat::Bc2RgbaUnormSrgb } else { TextureFormat::Bc2RgbaUnorm } } - ktx2::Format::BC2_SRGB_BLOCK => { - if is_srgb { - TextureFormat::Bc2RgbaUnormSrgb - } else { - TextureFormat::Bc2RgbaUnorm - } - } - ktx2::Format::BC3_UNORM_BLOCK => { - if is_srgb { - TextureFormat::Bc3RgbaUnormSrgb - } else { - TextureFormat::Bc3RgbaUnorm - } - } - ktx2::Format::BC3_SRGB_BLOCK => { + ktx2::Format::BC3_UNORM_BLOCK | ktx2::Format::BC3_SRGB_BLOCK => { if is_srgb { TextureFormat::Bc3RgbaUnormSrgb } else { @@ -1457,56 +1329,28 @@ pub fn ktx2_format_to_texture_format( ktx2::Format::BC5_SNORM_BLOCK => TextureFormat::Bc5RgSnorm, ktx2::Format::BC6H_UFLOAT_BLOCK => TextureFormat::Bc6hRgbUfloat, ktx2::Format::BC6H_SFLOAT_BLOCK => TextureFormat::Bc6hRgbSfloat, - ktx2::Format::BC7_UNORM_BLOCK => { + ktx2::Format::BC7_UNORM_BLOCK | ktx2::Format::BC7_SRGB_BLOCK => { if is_srgb { TextureFormat::Bc7RgbaUnormSrgb } else { TextureFormat::Bc7RgbaUnorm } } - ktx2::Format::BC7_SRGB_BLOCK => { - if is_srgb { - TextureFormat::Bc7RgbaUnormSrgb - } else { - TextureFormat::Bc7RgbaUnorm - } - } - ktx2::Format::ETC2_R8G8B8_UNORM_BLOCK => { + ktx2::Format::ETC2_R8G8B8_UNORM_BLOCK | ktx2::Format::ETC2_R8G8B8_SRGB_BLOCK => { if is_srgb { TextureFormat::Etc2Rgb8UnormSrgb } else { TextureFormat::Etc2Rgb8Unorm } } - ktx2::Format::ETC2_R8G8B8_SRGB_BLOCK => { - if is_srgb { - TextureFormat::Etc2Rgb8UnormSrgb - } else { - TextureFormat::Etc2Rgb8Unorm - } - } - ktx2::Format::ETC2_R8G8B8A1_UNORM_BLOCK => { + ktx2::Format::ETC2_R8G8B8A1_UNORM_BLOCK | ktx2::Format::ETC2_R8G8B8A1_SRGB_BLOCK => { if is_srgb { TextureFormat::Etc2Rgb8A1UnormSrgb } else { TextureFormat::Etc2Rgb8A1Unorm } } - ktx2::Format::ETC2_R8G8B8A1_SRGB_BLOCK => { - if is_srgb { - TextureFormat::Etc2Rgb8A1UnormSrgb - } else { - TextureFormat::Etc2Rgb8A1Unorm - } - } - ktx2::Format::ETC2_R8G8B8A8_UNORM_BLOCK => { - if is_srgb { - TextureFormat::Etc2Rgba8UnormSrgb - } else { - TextureFormat::Etc2Rgba8Unorm - } - } - ktx2::Format::ETC2_R8G8B8A8_SRGB_BLOCK => { + ktx2::Format::ETC2_R8G8B8A8_UNORM_BLOCK | ktx2::Format::ETC2_R8G8B8A8_SRGB_BLOCK => { if is_srgb { TextureFormat::Etc2Rgba8UnormSrgb } else { @@ -1517,196 +1361,98 @@ pub fn ktx2_format_to_texture_format( ktx2::Format::EAC_R11_SNORM_BLOCK => TextureFormat::EacR11Snorm, ktx2::Format::EAC_R11G11_UNORM_BLOCK => TextureFormat::EacRg11Unorm, ktx2::Format::EAC_R11G11_SNORM_BLOCK => TextureFormat::EacRg11Snorm, - ktx2::Format::ASTC_4x4_UNORM_BLOCK => { + ktx2::Format::ASTC_4x4_UNORM_BLOCK | ktx2::Format::ASTC_4x4_SRGB_BLOCK => { if is_srgb { TextureFormat::Astc4x4RgbaUnormSrgb } else { TextureFormat::Astc4x4RgbaUnorm } } - ktx2::Format::ASTC_4x4_SRGB_BLOCK => { - if is_srgb { - TextureFormat::Astc4x4RgbaUnormSrgb - } else { - TextureFormat::Astc4x4RgbaUnorm - } - } - ktx2::Format::ASTC_5x4_UNORM_BLOCK => { + ktx2::Format::ASTC_5x4_UNORM_BLOCK | ktx2::Format::ASTC_5x4_SRGB_BLOCK => { if is_srgb { TextureFormat::Astc5x4RgbaUnormSrgb } else { TextureFormat::Astc5x4RgbaUnorm } } - ktx2::Format::ASTC_5x4_SRGB_BLOCK => { - if is_srgb { - TextureFormat::Astc5x4RgbaUnormSrgb - } else { - TextureFormat::Astc5x4RgbaUnorm - } - } - ktx2::Format::ASTC_5x5_UNORM_BLOCK => { + ktx2::Format::ASTC_5x5_UNORM_BLOCK | ktx2::Format::ASTC_5x5_SRGB_BLOCK => { if is_srgb { TextureFormat::Astc5x5RgbaUnormSrgb } else { TextureFormat::Astc5x5RgbaUnorm } } - ktx2::Format::ASTC_5x5_SRGB_BLOCK => { - if is_srgb { - TextureFormat::Astc5x5RgbaUnormSrgb - } else { - TextureFormat::Astc5x5RgbaUnorm - } - } - ktx2::Format::ASTC_6x5_UNORM_BLOCK => { + ktx2::Format::ASTC_6x5_UNORM_BLOCK | ktx2::Format::ASTC_6x5_SRGB_BLOCK => { if is_srgb { TextureFormat::Astc6x5RgbaUnormSrgb } else { TextureFormat::Astc6x5RgbaUnorm } } - ktx2::Format::ASTC_6x5_SRGB_BLOCK => { - if is_srgb { - TextureFormat::Astc6x5RgbaUnormSrgb - } else { - TextureFormat::Astc6x5RgbaUnorm - } - } - ktx2::Format::ASTC_6x6_UNORM_BLOCK => { + ktx2::Format::ASTC_6x6_UNORM_BLOCK | ktx2::Format::ASTC_6x6_SRGB_BLOCK => { if is_srgb { TextureFormat::Astc6x6RgbaUnormSrgb } else { TextureFormat::Astc6x6RgbaUnorm } } - ktx2::Format::ASTC_6x6_SRGB_BLOCK => { - if is_srgb { - TextureFormat::Astc6x6RgbaUnormSrgb - } else { - TextureFormat::Astc6x6RgbaUnorm - } - } - ktx2::Format::ASTC_8x5_UNORM_BLOCK => { + ktx2::Format::ASTC_8x5_UNORM_BLOCK | ktx2::Format::ASTC_8x5_SRGB_BLOCK => { if is_srgb { TextureFormat::Astc8x5RgbaUnormSrgb } else { TextureFormat::Astc8x5RgbaUnorm } } - ktx2::Format::ASTC_8x5_SRGB_BLOCK => { - if is_srgb { - TextureFormat::Astc8x5RgbaUnormSrgb - } else { - TextureFormat::Astc8x5RgbaUnorm - } - } - ktx2::Format::ASTC_8x6_UNORM_BLOCK => { + ktx2::Format::ASTC_8x6_UNORM_BLOCK | ktx2::Format::ASTC_8x6_SRGB_BLOCK => { if is_srgb { TextureFormat::Astc8x6RgbaUnormSrgb } else { TextureFormat::Astc8x6RgbaUnorm } } - ktx2::Format::ASTC_8x6_SRGB_BLOCK => { - if is_srgb { - TextureFormat::Astc8x6RgbaUnormSrgb - } else { - TextureFormat::Astc8x6RgbaUnorm - } - } - ktx2::Format::ASTC_8x8_UNORM_BLOCK => { + ktx2::Format::ASTC_8x8_UNORM_BLOCK | ktx2::Format::ASTC_8x8_SRGB_BLOCK => { if is_srgb { TextureFormat::Astc8x8RgbaUnormSrgb } else { TextureFormat::Astc8x8RgbaUnorm } } - ktx2::Format::ASTC_8x8_SRGB_BLOCK => { - if is_srgb { - TextureFormat::Astc8x8RgbaUnormSrgb - } else { - TextureFormat::Astc8x8RgbaUnorm - } - } - ktx2::Format::ASTC_10x5_UNORM_BLOCK => { + ktx2::Format::ASTC_10x5_UNORM_BLOCK | ktx2::Format::ASTC_10x5_SRGB_BLOCK => { if is_srgb { TextureFormat::Astc10x5RgbaUnormSrgb } else { TextureFormat::Astc10x5RgbaUnorm } } - ktx2::Format::ASTC_10x5_SRGB_BLOCK => { - if is_srgb { - TextureFormat::Astc10x5RgbaUnormSrgb - } else { - TextureFormat::Astc10x5RgbaUnorm - } - } - ktx2::Format::ASTC_10x6_UNORM_BLOCK => { + ktx2::Format::ASTC_10x6_UNORM_BLOCK | ktx2::Format::ASTC_10x6_SRGB_BLOCK => { if is_srgb { TextureFormat::Astc10x6RgbaUnormSrgb } else { TextureFormat::Astc10x6RgbaUnorm } } - ktx2::Format::ASTC_10x6_SRGB_BLOCK => { - if is_srgb { - TextureFormat::Astc10x6RgbaUnormSrgb - } else { - TextureFormat::Astc10x6RgbaUnorm - } - } - ktx2::Format::ASTC_10x8_UNORM_BLOCK => { + ktx2::Format::ASTC_10x8_UNORM_BLOCK | ktx2::Format::ASTC_10x8_SRGB_BLOCK => { if is_srgb { TextureFormat::Astc10x8RgbaUnormSrgb } else { TextureFormat::Astc10x8RgbaUnorm } } - ktx2::Format::ASTC_10x8_SRGB_BLOCK => { - if is_srgb { - TextureFormat::Astc10x8RgbaUnormSrgb - } else { - TextureFormat::Astc10x8RgbaUnorm - } - } - ktx2::Format::ASTC_10x10_UNORM_BLOCK => { + ktx2::Format::ASTC_10x10_UNORM_BLOCK | ktx2::Format::ASTC_10x10_SRGB_BLOCK => { if is_srgb { TextureFormat::Astc10x10RgbaUnormSrgb } else { TextureFormat::Astc10x10RgbaUnorm } } - ktx2::Format::ASTC_10x10_SRGB_BLOCK => { - if is_srgb { - TextureFormat::Astc10x10RgbaUnormSrgb - } else { - TextureFormat::Astc10x10RgbaUnorm - } - } - ktx2::Format::ASTC_12x10_UNORM_BLOCK => { + ktx2::Format::ASTC_12x10_UNORM_BLOCK | ktx2::Format::ASTC_12x10_SRGB_BLOCK => { if is_srgb { TextureFormat::Astc12x10RgbaUnormSrgb } else { TextureFormat::Astc12x10RgbaUnorm } } - ktx2::Format::ASTC_12x10_SRGB_BLOCK => { - if is_srgb { - TextureFormat::Astc12x10RgbaUnormSrgb - } else { - TextureFormat::Astc12x10RgbaUnorm - } - } - ktx2::Format::ASTC_12x12_UNORM_BLOCK => { - if is_srgb { - TextureFormat::Astc12x12RgbaUnormSrgb - } else { - TextureFormat::Astc12x12RgbaUnorm - } - } - ktx2::Format::ASTC_12x12_SRGB_BLOCK => { + ktx2::Format::ASTC_12x12_UNORM_BLOCK | ktx2::Format::ASTC_12x12_SRGB_BLOCK => { if is_srgb { TextureFormat::Astc12x12RgbaUnormSrgb } else { diff --git a/crates/bevy_render/src/view/mod.rs b/crates/bevy_render/src/view/mod.rs index 80de0df937..2c415dcfcf 100644 --- a/crates/bevy_render/src/view/mod.rs +++ b/crates/bevy_render/src/view/mod.rs @@ -111,11 +111,7 @@ pub struct ViewTarget { impl ViewTarget { pub fn get_color_attachment(&self, ops: Operations) -> RenderPassColorAttachment { RenderPassColorAttachment { - view: if let Some(sampled_target) = &self.sampled_target { - sampled_target - } else { - &self.view - }, + view: self.sampled_target.as_ref().unwrap_or(&self.view), resolve_target: if self.sampled_target.is_some() { Some(&self.view) } else { diff --git a/crates/bevy_sprite/src/render/mod.rs b/crates/bevy_sprite/src/render/mod.rs index d41c502475..cf07b16e65 100644 --- a/crates/bevy_sprite/src/render/mod.rs +++ b/crates/bevy_sprite/src/render/mod.rs @@ -354,8 +354,9 @@ pub fn queue_sprites( for event in &events.images { match event { AssetEvent::Created { .. } => None, - AssetEvent::Modified { handle } => image_bind_groups.values.remove(handle), - AssetEvent::Removed { handle } => image_bind_groups.values.remove(handle), + AssetEvent::Modified { handle } | AssetEvent::Removed { handle } => { + image_bind_groups.values.remove(handle) + } }; } @@ -501,10 +502,10 @@ pub fn queue_sprites( // Store the vertex data and add the item to the render phase if current_batch.colored { - for i in QUAD_INDICES.iter() { + for i in QUAD_INDICES { sprite_meta.colored_vertices.push(ColoredSpriteVertex { - position: positions[*i], - uv: uvs[*i].into(), + position: positions[i], + uv: uvs[i].into(), color: extracted_sprite.color.as_linear_rgba_f32(), }); } @@ -520,10 +521,10 @@ pub fn queue_sprites( batch_range: Some(item_start..item_end), }); } else { - for i in QUAD_INDICES.iter() { + for i in QUAD_INDICES { sprite_meta.vertices.push(SpriteVertex { - position: positions[*i], - uv: uvs[*i].into(), + position: positions[i], + uv: uvs[i].into(), }); } let item_start = index; diff --git a/crates/bevy_text/src/text2d.rs b/crates/bevy_text/src/text2d.rs index 8043518361..8685c25230 100644 --- a/crates/bevy_text/src/text2d.rs +++ b/crates/bevy_text/src/text2d.rs @@ -127,7 +127,7 @@ pub fn extract_text2d_sprite( /// Updates the layout and size information whenever the text or style is changed. /// This information is computed by the `TextPipeline` on insertion, then stored. -#[allow(clippy::too_many_arguments, clippy::type_complexity)] +#[allow(clippy::too_many_arguments)] pub fn update_text2d_layout( // Text items which should be reprocessed again, generally when the font hasn't loaded yet. mut queue: Local>, diff --git a/crates/bevy_ui/src/flex/mod.rs b/crates/bevy_ui/src/flex/mod.rs index 8cb7fcd17a..607daaacbc 100644 --- a/crates/bevy_ui/src/flex/mod.rs +++ b/crates/bevy_ui/src/flex/mod.rs @@ -198,7 +198,7 @@ pub enum FlexError { StretchError(stretch::Error), } -#[allow(clippy::too_many_arguments, clippy::type_complexity)] +#[allow(clippy::too_many_arguments)] pub fn flex_node_system( windows: Res, mut scale_factor_events: EventReader, diff --git a/crates/bevy_ui/src/focus.rs b/crates/bevy_ui/src/focus.rs index 10df5b24d9..03a269c690 100644 --- a/crates/bevy_ui/src/focus.rs +++ b/crates/bevy_ui/src/focus.rs @@ -57,7 +57,6 @@ pub struct State { } /// The system that sets Interaction for all UI elements based on the mouse cursor activity -#[allow(clippy::type_complexity)] pub fn ui_focus_system( mut state: Local, windows: Res, diff --git a/crates/bevy_ui/src/render/mod.rs b/crates/bevy_ui/src/render/mod.rs index e9fa461263..e42d0a8334 100644 --- a/crates/bevy_ui/src/render/mod.rs +++ b/crates/bevy_ui/src/render/mod.rs @@ -408,8 +408,9 @@ pub fn queue_uinodes( for event in &events.images { match event { AssetEvent::Created { .. } => None, - AssetEvent::Modified { handle } => image_bind_groups.values.remove(handle), - AssetEvent::Removed { handle } => image_bind_groups.values.remove(handle), + AssetEvent::Modified { handle } | AssetEvent::Removed { handle } => { + image_bind_groups.values.remove(handle) + } }; } diff --git a/crates/bevy_ui/src/ui_node.rs b/crates/bevy_ui/src/ui_node.rs index 3d7996139c..56390d4a46 100644 --- a/crates/bevy_ui/src/ui_node.rs +++ b/crates/bevy_ui/src/ui_node.rs @@ -56,8 +56,7 @@ impl AddAssign for Val { fn add_assign(&mut self, rhs: f32) { match self { Val::Undefined | Val::Auto => {} - Val::Px(value) => *value += rhs, - Val::Percent(value) => *value += rhs, + Val::Px(value) | Val::Percent(value) => *value += rhs, } } } diff --git a/crates/bevy_ui/src/widget/text.rs b/crates/bevy_ui/src/widget/text.rs index cb35dd2794..895c4a6fde 100644 --- a/crates/bevy_ui/src/widget/text.rs +++ b/crates/bevy_ui/src/widget/text.rs @@ -27,15 +27,16 @@ pub fn text_constraint(min_size: Val, size: Val, max_size: Val, scale_factor: f6 match (min_size, size, max_size) { (_, _, Val::Px(max)) => scale_value(max, scale_factor), (Val::Px(min), _, _) => scale_value(min, scale_factor), - (Val::Undefined, Val::Px(size), Val::Undefined) => scale_value(size, scale_factor), - (Val::Auto, Val::Px(size), Val::Auto) => scale_value(size, scale_factor), + (Val::Undefined, Val::Px(size), Val::Undefined) | (Val::Auto, Val::Px(size), Val::Auto) => { + scale_value(size, scale_factor) + } _ => f32::MAX, } } /// Updates the layout and size information whenever the text or style is changed. /// This information is computed by the `TextPipeline` on insertion, then stored. -#[allow(clippy::too_many_arguments, clippy::type_complexity)] +#[allow(clippy::too_many_arguments)] pub fn text_system( mut queued_text: Local, mut last_scale_factor: Local, diff --git a/crates/bevy_winit/src/winit_windows.rs b/crates/bevy_winit/src/winit_windows.rs index 020b474650..e556509270 100644 --- a/crates/bevy_winit/src/winit_windows.rs +++ b/crates/bevy_winit/src/winit_windows.rs @@ -126,8 +126,7 @@ impl WinitWindows { if window_descriptor.cursor_locked { match winit_window.set_cursor_grab(true) { - Ok(_) => {} - Err(winit::error::ExternalError::NotSupported(_)) => {} + Ok(_) | Err(winit::error::ExternalError::NotSupported(_)) => {} Err(err) => Err(err).unwrap(), } } diff --git a/examples/3d/shapes.rs b/examples/3d/shapes.rs index 3c0c55a30d..b099508a12 100644 --- a/examples/3d/shapes.rs +++ b/examples/3d/shapes.rs @@ -87,7 +87,7 @@ fn setup( fn rotate(mut query: Query<&mut Transform, With>, time: Res