From 631f3ab8eeff0b885d2316aaeea582cbd64bc6fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=A4rtens?= Date: Thu, 5 Oct 2023 20:03:24 +0200 Subject: [PATCH] fix clippy issues, WITHOUT clippy::needless_pass_by_ref_mut as we are still unsure how to proceed with it. we want to keep the &mut ref where we are actually writing. maybe we need another method support --- common/src/store.rs | 2 +- server-cli/src/cli.rs | 4 +++ server/agent/src/attack.rs | 6 +--- server/agent/src/lib.rs | 3 ++ server/src/lib.rs | 5 +++- server/src/persistence/character.rs | 2 +- voxygen/egui/src/lib.rs | 3 ++ voxygen/src/cmd.rs | 2 +- voxygen/src/hud/bag.rs | 6 ++-- voxygen/src/hud/crafting.rs | 4 +-- voxygen/src/hud/mod.rs | 24 +++++++-------- voxygen/src/hud/quest.rs | 2 +- voxygen/src/lib.rs | 6 +++- voxygen/src/mesh/terrain.rs | 4 +-- voxygen/src/scene/figure/load.rs | 29 +++++++++---------- voxygen/src/scene/figure/mod.rs | 4 +-- voxygen/src/scene/simple.rs | 2 +- voxygen/src/scene/terrain.rs | 4 +-- voxygen/src/session/interactable.rs | 2 +- voxygen/src/ui/ice/renderer/mod.rs | 2 +- voxygen/src/window.rs | 2 ++ world/src/layer/mod.rs | 1 - world/src/lib.rs | 3 +- world/src/site/namegen.rs | 2 +- .../settlement/building/archetype/house.rs | 2 +- world/src/site/settlement/mod.rs | 2 +- world/src/site2/plot/gnarling.rs | 7 ++--- 27 files changed, 73 insertions(+), 62 deletions(-) diff --git a/common/src/store.rs b/common/src/store.rs index 99b2f37d36..d2740aa7d6 100644 --- a/common/src/store.rs +++ b/common/src/store.rs @@ -16,7 +16,7 @@ impl Id { impl Copy for Id {} impl Clone for Id { - fn clone(&self) -> Self { Self(self.0, PhantomData) } + fn clone(&self) -> Self { *self } } impl Eq for Id {} impl PartialEq for Id { diff --git a/server-cli/src/cli.rs b/server-cli/src/cli.rs index 239e40967c..ec8b6f71c1 100644 --- a/server-cli/src/cli.rs +++ b/server-cli/src/cli.rs @@ -1,3 +1,7 @@ +#![allow( + clippy::needless_pass_by_ref_mut //until we find a better way for specs +)] + use clap::Parser; use common::comp; use server::persistence::SqlLogMode; diff --git a/server/agent/src/attack.rs b/server/agent/src/attack.rs index d6e640e1e8..46c09f65ab 100644 --- a/server/agent/src/attack.rs +++ b/server/agent/src/attack.rs @@ -2924,11 +2924,7 @@ impl<'a> AgentData<'a> { { agent.action_state.counters[FCounters::SummonThreshold as usize] -= SUMMON_THRESHOLD; - if !agent.action_state.conditions[Conditions::AttackToggle as usize] { - agent.action_state.conditions[Conditions::AttackToggle as usize] = true; - } else { - agent.action_state.conditions[Conditions::AttackToggle as usize] = false; - } + agent.action_state.conditions[Conditions::AttackToggle as usize] = !agent.action_state.conditions[Conditions::AttackToggle as usize]; } } else { // If target is in melee range use flamecrush diff --git a/server/agent/src/lib.rs b/server/agent/src/lib.rs index f0a61862f0..420bd5ff07 100644 --- a/server/agent/src/lib.rs +++ b/server/agent/src/lib.rs @@ -1,4 +1,7 @@ #![feature(exclusive_range_pattern, let_chains)] +#![allow( + clippy::needless_pass_by_ref_mut //until we find a better way for specs +)] #[cfg(all(feature = "be-dyn-lib", feature = "use-dyn-lib"))] compile_error!("Can't use both \"be-dyn-lib\" and \"use-dyn-lib\" features at once"); diff --git a/server/src/lib.rs b/server/src/lib.rs index 0cba9d93be..7e3fc5758b 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -1,5 +1,8 @@ #![deny(unsafe_code)] -#![allow(clippy::option_map_unit_fn)] +#![allow( + clippy::option_map_unit_fn, + clippy::needless_pass_by_ref_mut //until we find a better way for specs +)] #![deny(clippy::clone_on_ref_ptr)] #![feature( box_patterns, diff --git a/server/src/persistence/character.rs b/server/src/persistence/character.rs index 3758dbd7dc..5535e6d085 100644 --- a/server/src/persistence/character.rs +++ b/server/src/persistence/character.rs @@ -1062,7 +1062,7 @@ pub fn update( // The `defer_foreign_keys` pragma treats the foreign key // constraints as deferred for the next transaction (it turns itself // off at the commit boundary). https://sqlite.org/foreignkeys.html#fk_deferred - transaction.pragma_update(None, "defer_foreign_keys", &"ON".to_string())?; + transaction.pragma_update(None, "defer_foreign_keys", "ON")?; let mut stmt = transaction.prepare_cached( " diff --git a/voxygen/egui/src/lib.rs b/voxygen/egui/src/lib.rs index d9037349ba..923e43dc21 100644 --- a/voxygen/egui/src/lib.rs +++ b/voxygen/egui/src/lib.rs @@ -1,4 +1,7 @@ #![feature(stmt_expr_attributes)] +#![allow( + clippy::needless_pass_by_ref_mut //until we find a better way for specs +)] #[cfg(all(feature = "be-dyn-lib", feature = "use-dyn-lib"))] compile_error!("Can't use both \"be-dyn-lib\" and \"use-dyn-lib\" features at once"); diff --git a/voxygen/src/cmd.rs b/voxygen/src/cmd.rs index 3800b79a7e..7b052ed9dc 100644 --- a/voxygen/src/cmd.rs +++ b/voxygen/src/cmd.rs @@ -407,7 +407,7 @@ impl TabComplete for ArgumentSpec { .filter(|string| string.starts_with(part)) .map(|c| c.to_string()) .collect(), - ArgumentSpec::Boolean(_, part, _) => vec!["true", "false"] + ArgumentSpec::Boolean(_, part, _) => ["true", "false"] .iter() .filter(|string| string.starts_with(part)) .map(|c| c.to_string()) diff --git a/voxygen/src/hud/bag.rs b/voxygen/src/hud/bag.rs index 4ad354a3b2..83c16f5f9e 100644 --- a/voxygen/src/hud/bag.rs +++ b/voxygen/src/hud/bag.rs @@ -196,7 +196,7 @@ impl<'a> InventoryScroller<'a> { .set(self.bg_ids.bg_frame, ui); } - fn title(&mut self, state: &mut ConrodState<'_, InventoryScrollerState>, ui: &mut UiCell<'_>) { + fn title(&mut self, state: &ConrodState<'_, InventoryScrollerState>, ui: &mut UiCell<'_>) { Text::new( &self .localized_strings @@ -371,7 +371,7 @@ impl<'a> InventoryScroller<'a> { }); } for (pos, item) in items.into_iter() { - if self.details_mode && !self.is_us && matches!(item, None) { + if self.details_mode && !self.is_us && item.is_none() { continue; } let (x, y) = if self.details_mode { @@ -488,7 +488,7 @@ impl<'a> InventoryScroller<'a> { fn footer_metrics( &mut self, - state: &mut ConrodState<'_, InventoryScrollerState>, + state: &ConrodState<'_, InventoryScrollerState>, ui: &mut UiCell<'_>, ) { let space_used = self.inventory.populated_slots(); diff --git a/voxygen/src/hud/crafting.rs b/voxygen/src/hud/crafting.rs index c631fc9cbe..0b4d52b15f 100644 --- a/voxygen/src/hud/crafting.rs +++ b/voxygen/src/hud/crafting.rs @@ -1479,7 +1479,7 @@ impl<'a> Widget for Crafting<'a> { }); self.inventory .slots_with_id() - .filter(|(_, item)| item.as_ref().map_or(false, |i| can_repair(i))) + .filter(|(_, item)| item.as_ref().map_or(false, can_repair)) .for_each(|(slot, _)| { events.push(Event::RepairItem { slot: Slot::Inventory(slot), @@ -1489,7 +1489,7 @@ impl<'a> Widget for Crafting<'a> { let can_perform = repair_slot .item(self.inventory) - .map_or(false, |item| can_repair(item)); + .map_or(false, can_repair); (repair_slot.slot, None, can_perform) }, diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index 8f1b4106df..ce2eb7906c 100755 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -516,30 +516,28 @@ impl BuffIconKind { impl PartialOrd for BuffIconKind { fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +impl Ord for BuffIconKind { + fn cmp(&self, other: &Self) -> Ordering { match (self, other) { ( BuffIconKind::Buff { kind, .. }, BuffIconKind::Buff { kind: other_kind, .. }, - ) => Some(kind.cmp(other_kind)), - (BuffIconKind::Buff { .. }, BuffIconKind::Stance(_)) => Some(Ordering::Greater), - (BuffIconKind::Stance(_), BuffIconKind::Buff { .. }) => Some(Ordering::Less), + ) => kind.cmp(other_kind), + (BuffIconKind::Buff { .. }, BuffIconKind::Stance(_)) => Ordering::Greater, + (BuffIconKind::Stance(_), BuffIconKind::Buff { .. }) => Ordering::Less, (BuffIconKind::Stance(stance), BuffIconKind::Stance(stance_other)) => { - Some(stance.cmp(stance_other)) + stance.cmp(stance_other) }, } } } -impl Ord for BuffIconKind { - fn cmp(&self, other: &Self) -> Ordering { - // We know this is safe since we can look at the partialord implementation and - // see that every variant is wrapped in Some - self.partial_cmp(other).unwrap() - } -} - impl PartialEq for BuffIconKind { fn eq(&self, other: &Self) -> bool { match (self, other) { @@ -586,7 +584,7 @@ impl BuffIcon { buffs .iter_active() .filter_map(BuffIcon::from_buffs) - .chain(stance.and_then(BuffIcon::from_stance).into_iter()) + .chain(stance.and_then(BuffIcon::from_stance)) .collect::>() } diff --git a/voxygen/src/hud/quest.rs b/voxygen/src/hud/quest.rs index 332224df9f..342cb30649 100644 --- a/voxygen/src/hud/quest.rs +++ b/voxygen/src/hud/quest.rs @@ -223,7 +223,7 @@ impl<'a> Widget for Quest<'a> { // [amount, item_desc] //("common.items.weapons.sword.caladbolg"); - let rewards = vec![ + let rewards = [ (1, "common.items.weapons.dagger.starter_dagger", "Dagger"), (4, "common.items.crafting_ing.seashells", "Seashell"), ( diff --git a/voxygen/src/lib.rs b/voxygen/src/lib.rs index 1c7f41a909..17ec046081 100644 --- a/voxygen/src/lib.rs +++ b/voxygen/src/lib.rs @@ -1,6 +1,10 @@ #![deny(unsafe_code)] #![allow(incomplete_features)] -#![allow(clippy::identity_op, clippy::option_map_unit_fn)] +#![allow( + clippy::identity_op, + clippy::option_map_unit_fn, + clippy::needless_pass_by_ref_mut //until we find a better way for specs +)] #![deny(clippy::clone_on_ref_ptr)] #![feature( array_methods, diff --git a/voxygen/src/mesh/terrain.rs b/voxygen/src/mesh/terrain.rs index 54790aab4b..c571227102 100644 --- a/voxygen/src/mesh/terrain.rs +++ b/voxygen/src/mesh/terrain.rs @@ -529,8 +529,8 @@ pub fn generate_mesh<'a>( ( opaque_deep .into_iter() - .chain(opaque_shallow.into_iter()) - .chain(opaque_surface.into_iter()) + .chain(opaque_shallow) + .chain(opaque_surface) .collect(), fluid_mesh, Mesh::new(), diff --git a/voxygen/src/scene/figure/load.rs b/voxygen/src/scene/figure/load.rs index 5b6acc7ce6..3d987939f0 100644 --- a/voxygen/src/scene/figure/load.rs +++ b/voxygen/src/scene/figure/load.rs @@ -1069,7 +1069,7 @@ fn mesh_hold() -> BoneMeshes { ) } -///////// +////// #[derive(Deserialize)] struct QuadrupedSmallCentralSpec(HashMap<(QSSpecies, QSBodyType), SidedQSCentralVoxSpec>); @@ -1660,7 +1660,7 @@ impl QuadrupedMediumLateralSpec { } } -//// +////// #[derive(Deserialize)] struct BirdMediumCentralSpec(HashMap<(BMSpecies, BMBodyType), SidedBMCentralVoxSpec>); @@ -1914,7 +1914,7 @@ impl BirdMediumLateralSpec { } } -//// +////// #[derive(Deserialize)] struct TheropodCentralSpec(HashMap<(TSpecies, TBodyType), SidedTCentralVoxSpec>); @@ -2244,7 +2244,7 @@ impl TheropodLateralSpec { } } -//// +////// #[derive(Deserialize)] struct ArthropodCentralSpec(HashMap<(ASpecies, ABodyType), SidedACentralVoxSpec>); @@ -2644,7 +2644,7 @@ impl ArthropodLateralSpec { (lateral, Vec3::from(spec.leg_br.offset)) } } -//// +////// #[derive(Deserialize)] struct FishMediumCentralSpec(HashMap<(FMSpecies, FMBodyType), SidedFMCentralVoxSpec>); @@ -2850,7 +2850,7 @@ impl FishMediumLateralSpec { } } -//// +////// #[derive(Deserialize)] struct FishSmallCentralSpec(HashMap<(FSSpecies, FSBodyType), SidedFSCentralVoxSpec>); @@ -2994,7 +2994,7 @@ impl FishSmallLateralSpec { } } -//// +////// #[derive(Deserialize)] struct BipedSmallWeaponSpec(HashMap); @@ -3269,8 +3269,8 @@ impl BipedSmallWeaponSpec { (tool_kind_segment, offset) } } -//// +////// #[derive(Deserialize)] struct DragonCentralSpec(HashMap<(DSpecies, DBodyType), SidedDCentralVoxSpec>); @@ -3641,7 +3641,7 @@ impl DragonLateralSpec { } } -//// +////// #[derive(Deserialize)] struct BirdLargeCentralSpec(HashMap<(BLASpecies, BLABodyType), SidedBLACentralVoxSpec>); @@ -4044,7 +4044,7 @@ impl BirdLargeLateralSpec { } } -//// +////// #[derive(Deserialize)] struct BipedLargeCentralSpec(HashMap<(BLSpecies, BLBodyType), SidedBLCentralVoxSpec>); @@ -4462,7 +4462,8 @@ impl BipedLargeSecondSpec { (tool_kind_segment, offset) } } -//// + +////// #[derive(Deserialize)] struct GolemCentralSpec(HashMap<(GSpecies, GBodyType), SidedGCentralVoxSpec>); @@ -4772,8 +4773,7 @@ impl GolemLateralSpec { } } -///// - +////// #[derive(Deserialize)] struct QuadrupedLowCentralSpec(HashMap<(QLSpecies, QLBodyType), SidedQLCentralVoxSpec>); @@ -5050,8 +5050,7 @@ impl QuadrupedLowLateralSpec { } } -//// - +////// #[derive(Deserialize)] struct ObjectCentralSpec(HashMap); diff --git a/voxygen/src/scene/figure/mod.rs b/voxygen/src/scene/figure/mod.rs index 1eadad047b..baff501f36 100644 --- a/voxygen/src/scene/figure/mod.rs +++ b/voxygen/src/scene/figure/mod.rs @@ -1101,8 +1101,8 @@ impl FigureMgr { let holding_lantern = inventory .map_or(false, |i| i.equipped(EquipSlot::Lantern).is_some()) && light_emitter.is_some() - && !((matches!(second_tool_hand, Some(_)) - || matches!(active_tool_hand, Some(Hands::Two))) + && !(second_tool_hand.is_some() + || matches!(active_tool_hand, Some(Hands::Two)) && character.map_or(false, |c| c.is_wield())) && !character.map_or(false, |c| c.is_using_hands()) && physics.in_liquid().is_none(); diff --git a/voxygen/src/scene/simple.rs b/voxygen/src/scene/simple.rs index f7ae644869..4f0f5ee3e9 100644 --- a/voxygen/src/scene/simple.rs +++ b/voxygen/src/scene/simple.rs @@ -137,7 +137,7 @@ impl Scene { figure_state: None, backdrop: backdrop.map(|specifier| { - let mut state = FigureState::new(renderer, FixtureSkeleton::default(), ()); + let mut state = FigureState::new(renderer, FixtureSkeleton, ()); let mut greedy = FigureModel::make_greedy(); let mut opaque_mesh = Mesh::new(); let (segment, offset) = load_mesh(specifier, Vec3::new(-55.0, -49.5, -2.0)); diff --git a/voxygen/src/scene/terrain.rs b/voxygen/src/scene/terrain.rs index a7f526747d..7a7ebd0a00 100644 --- a/voxygen/src/scene/terrain.rs +++ b/voxygen/src/scene/terrain.rs @@ -437,8 +437,8 @@ fn mesh_worker( ( deep_level .into_iter() - .chain(shallow_level.into_iter()) - .chain(surface_level.into_iter()) + .chain(shallow_level) + .chain(surface_level) .collect(), alt_indices, ) diff --git a/voxygen/src/session/interactable.rs b/voxygen/src/session/interactable.rs index 9a35bf98ab..78f5f40ab8 100644 --- a/voxygen/src/session/interactable.rs +++ b/voxygen/src/session/interactable.rs @@ -59,7 +59,7 @@ impl Interactable { volume_pos: VolumePos, interaction: Interaction, ) -> Option { - let Some(block) = volume_pos.get_block(terrain, id_maps, colliders) else { return None }; + let block= volume_pos.get_block(terrain, id_maps, colliders)?; let block_interaction = match interaction { Interaction::Collect => { // Check if this is an unlockable sprite diff --git a/voxygen/src/ui/ice/renderer/mod.rs b/voxygen/src/ui/ice/renderer/mod.rs index cafa592aaa..cce446cd12 100644 --- a/voxygen/src/ui/ice/renderer/mod.rs +++ b/voxygen/src/ui/ice/renderer/mod.rs @@ -5,7 +5,7 @@ mod widget; pub use defaults::Defaults; -pub(self) use primitive::Primitive; +use primitive::Primitive; use super::{ super::graphic::{self, Graphic, TexId}, diff --git a/voxygen/src/window.rs b/voxygen/src/window.rs index dfefd0d6d8..c1cc1fb621 100644 --- a/voxygen/src/window.rs +++ b/voxygen/src/window.rs @@ -675,6 +675,7 @@ impl Window { .game_analog_button_map .get(&AnalogButton::from((button, code))) { + #[allow(clippy::never_loop)] for action in actions { match *action {} } @@ -684,6 +685,7 @@ impl Window { .menu_analog_button_map .get(&AnalogButton::from((button, code))) { + #[allow(clippy::never_loop)] for action in actions { match *action {} } diff --git a/world/src/layer/mod.rs b/world/src/layer/mod.rs index c1aa677732..5e9a8c1233 100644 --- a/world/src/layer/mod.rs +++ b/world/src/layer/mod.rs @@ -1036,7 +1036,6 @@ pub fn apply_caverns_to(canvas: &mut Canvas, dynamic_rng: &mut R) { } }; - let cavern_top = cavern_top; let mut last_kind = BlockKind::Rock; for z in cavern_bottom - 1..cavern_top { use SpriteKind::*; diff --git a/world/src/lib.rs b/world/src/lib.rs index ce8737d36a..e70a78ece2 100644 --- a/world/src/lib.rs +++ b/world/src/lib.rs @@ -2,7 +2,8 @@ #![allow( clippy::option_map_unit_fn, clippy::blocks_in_if_conditions, - clippy::identity_op + clippy::identity_op, + clippy::needless_pass_by_ref_mut //until we find a better way for specs )] #![allow(clippy::branches_sharing_code)] // TODO: evaluate #![deny(clippy::clone_on_ref_ptr)] diff --git a/world/src/site/namegen.rs b/world/src/site/namegen.rs index c36f2be241..7ffde99f91 100644 --- a/world/src/site/namegen.rs +++ b/world/src/site/namegen.rs @@ -31,7 +31,7 @@ impl<'a, R: Rng> NameGen<'a, R> { ]); let mut middle = cons.clone(); middle.extend(vec!["tt"]); - let vowel = vec!["o", "e", "a", "i", "u", "au", "ee", "ow", "ay", "ey", "oe"]; + let vowel = ["o", "e", "a", "i", "u", "au", "ee", "ow", "ay", "ey", "oe"]; let end = vec![ "et", "ige", "age", "ist", "en", "on", "og", "end", "ind", "ock", "een", "edge", "ist", "ed", "est", "eed", "ast", "olt", "ey", "ean", "ead", "onk", "ink", "eon", "er", "ow", diff --git a/world/src/site/settlement/building/archetype/house.rs b/world/src/site/settlement/building/archetype/house.rs index 6904f5093b..bcc5921115 100644 --- a/world/src/site/settlement/building/archetype/house.rs +++ b/world/src/site/settlement/building/archetype/house.rs @@ -641,7 +641,7 @@ impl Archetype for House { % 6 { 0 => SpriteKind::HangingSign, - 1 | 2 | 3 => SpriteKind::HangingBasket, + 1..=3 => SpriteKind::HangingBasket, 4 => SpriteKind::WallSconce, 5 => SpriteKind::WallLampSmall, _ => SpriteKind::DungeonWallDecor, diff --git a/world/src/site/settlement/mod.rs b/world/src/site/settlement/mod.rs index bd49b19e05..6ac38ebfa2 100644 --- a/world/src/site/settlement/mod.rs +++ b/world/src/site/settlement/mod.rs @@ -1414,7 +1414,7 @@ impl Land { } } - closed.into_iter().chain(open.into_iter()).collect() + closed.into_iter().chain(open).collect() } fn write_path( diff --git a/world/src/site2/plot/gnarling.rs b/world/src/site2/plot/gnarling.rs index 837390d8c6..f056084276 100644 --- a/world/src/site2/plot/gnarling.rs +++ b/world/src/site2/plot/gnarling.rs @@ -298,7 +298,7 @@ impl GnarlingFortification { wall_connections .iter() .copied() - .zip(inner_tower_locs.into_iter()), + .zip(inner_tower_locs), ) .collect::>(); @@ -454,7 +454,6 @@ impl Structure for GnarlingFortification { }) .for_each(|(point, next_point)| { // 2d world positions of each point in wall segment - let point = point; let start_wpos = point + self.origin; let end_wpos = next_point + self.origin; @@ -1829,7 +1828,7 @@ impl Structure for GnarlingFortification { } tunnels .into_iter() - .chain(rooms.into_iter()) + .chain(rooms) .chain(core::iter::once(boss_room)) .chain(core::iter::once(stump)) .for_each(|prim| prim.fill(wood.clone())); @@ -1839,7 +1838,7 @@ impl Structure for GnarlingFortification { let mut sprite_clear = Vec::new(); tunnels_clear .into_iter() - .chain(rooms_clear.into_iter()) + .chain(rooms_clear) .chain(core::iter::once(boss_room_clear)) .for_each(|prim| { sprite_clear.push(prim.translate(Vec3::new(0, 0, 1)).intersect(prim));