From e48fc4c2b235ceab3c1a551292c45c46d47e7130 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=A4rtens?= Date: Sat, 18 May 2024 21:33:30 +0200 Subject: [PATCH] additional cargo clippy for toolchain switch --- client/src/lib.rs | 4 ++-- common/net/src/sync/packet.rs | 8 ++++---- common/src/comp/admin.rs | 1 + common/src/comp/body/item_drop.rs | 10 ++++------ common/src/comp/inventory/item/mod.rs | 2 +- common/src/comp/player.rs | 1 + common/src/comp/skillset/mod.rs | 4 ++-- common/src/states/basic_beam.rs | 20 +++++++------------ common/src/states/leap_melee.rs | 1 - common/src/uid.rs | 2 +- network/examples/fileshare/main.rs | 2 +- network/examples/fileshare/server.rs | 2 +- server/src/lib.rs | 1 - server/src/persistence/character_updater.rs | 2 +- server/src/persistence/mod.rs | 1 + voxygen/src/ecs/sys/interpolation.rs | 7 +++---- voxygen/src/hud/chat.rs | 6 +++--- voxygen/src/hud/trade.rs | 2 +- voxygen/src/main.rs | 2 +- voxygen/src/menu/main/mod.rs | 4 ++-- voxygen/src/menu/main/ui/mod.rs | 2 +- voxygen/src/mesh/segment.rs | 20 +++++++++---------- voxygen/src/scene/figure/load.rs | 9 +++------ voxygen/src/scene/figure/mod.rs | 16 ++++++--------- .../src/singleplayer/singleplayer_world.rs | 2 +- 25 files changed, 58 insertions(+), 73 deletions(-) diff --git a/client/src/lib.rs b/client/src/lib.rs index abdbb3d48d..1453283df6 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -1987,9 +1987,9 @@ impl Client { self.state.terrain().get_key_arc(chunk_pos).cloned() } - pub fn current(&self) -> Option + pub fn current(&self) -> Option where - C: Clone, + C: Component + Clone, { self.state.read_storage::().get(self.entity()).cloned() } diff --git a/common/net/src/sync/packet.rs b/common/net/src/sync/packet.rs index 96f1cd5e6c..3e7d8d0659 100644 --- a/common/net/src/sync/packet.rs +++ b/common/net/src/sync/packet.rs @@ -168,7 +168,7 @@ impl CompSyncPackage

{ .push((uid.into(), CompUpdateKind::Removed(PhantomData::.into()))); } - pub fn add_component_updates<'a, C: Component + Clone + Send + Sync>( + pub fn add_component_updates<'a, C>( &mut self, uids: &ReadStorage<'a, Uid>, tracker: &UpdateTracker, @@ -176,7 +176,7 @@ impl CompSyncPackage

{ filter: impl Join + Copy, ) where P: From, - C: TryFrom

, + C: Component + Clone + Send + Sync + TryFrom

, P::Phantom: From>, P::Phantom: TryInto>, C::Storage: specs::storage::Tracked, @@ -186,7 +186,7 @@ impl CompSyncPackage

{ /// If there was an update to the component `C` on the provided entity this /// will add the update to this package. - pub fn add_component_update( + pub fn add_component_update( &mut self, tracker: &UpdateTracker, storage: &ReadStorage<'_, C>, @@ -194,7 +194,7 @@ impl CompSyncPackage

{ entity: Entity, ) where P: From, - C: TryFrom

, + C: Component + Clone + Send + Sync + TryFrom

, P::Phantom: From>, P::Phantom: TryInto>, C::Storage: specs::storage::Tracked, diff --git a/common/src/comp/admin.rs b/common/src/comp/admin.rs index 83141ea9c6..5109098320 100644 --- a/common/src/comp/admin.rs +++ b/common/src/comp/admin.rs @@ -24,6 +24,7 @@ impl core::str::FromStr for AdminRole { } } +#[allow(clippy::to_string_trait_impl)] impl ToString for AdminRole { fn to_string(&self) -> String { match self { diff --git a/common/src/comp/body/item_drop.rs b/common/src/comp/body/item_drop.rs index 97a7730068..26294bf979 100644 --- a/common/src/comp/body/item_drop.rs +++ b/common/src/comp/body/item_drop.rs @@ -139,12 +139,10 @@ impl Body { )) .unwrap_or_default(), ), - Body::Armor(kind) => match kind { - ItemDropArmorKind::Neck | ItemDropArmorKind::Back | ItemDropArmorKind::Tabard => { - default.yawed_left(random).pitched_down(PI / 2.0) - }, - _ => default.yawed_left(random), - }, + + Body::Armor( + ItemDropArmorKind::Neck | ItemDropArmorKind::Back | ItemDropArmorKind::Tabard, + ) => default.yawed_left(random).pitched_down(PI / 2.0), _ => default.yawed_left(random), } } diff --git a/common/src/comp/inventory/item/mod.rs b/common/src/comp/inventory/item/mod.rs index dfd08d59db..a2cd0024ce 100644 --- a/common/src/comp/inventory/item/mod.rs +++ b/common/src/comp/inventory/item/mod.rs @@ -578,7 +578,7 @@ impl Serialize for ItemBase { // Custom serialization for ItemDef, we only want to send the item_definition_id // over the network, the client will use deserialize_item_def to fetch the // ItemDef from assets. - fn serialize(&self, serializer: S) -> Result + fn serialize(&self, serializer: S) -> Result where S: Serializer, { diff --git a/common/src/comp/player.rs b/common/src/comp/player.rs index 93c2afcb25..7edc7826a5 100644 --- a/common/src/comp/player.rs +++ b/common/src/comp/player.rs @@ -87,6 +87,7 @@ pub enum AliasError { TooLong, } +#[allow(clippy::to_string_trait_impl)] impl ToString for AliasError { fn to_string(&self) -> String { match *self { diff --git a/common/src/comp/skillset/mod.rs b/common/src/comp/skillset/mod.rs index 2fff17d0b5..71f90acc8d 100644 --- a/common/src/comp/skillset/mod.rs +++ b/common/src/comp/skillset/mod.rs @@ -482,14 +482,14 @@ impl SkillSet { /// /// NOTE: Please don't use pathological or clever implementations of to_mut /// here. - pub fn unlock_skill_cow<'a, B, C: 'a>( + pub fn unlock_skill_cow<'a, B, C>( this_: &'a mut B, skill: Skill, to_mut: impl FnOnce(&'a mut B) -> &'a mut C, ) -> Result<(), SkillUnlockError> where B: Borrow, - C: BorrowMut, + C: BorrowMut + 'a, { if let Some(skill_group_kind) = skill.skill_group_kind() { let this = (*this_).borrow(); diff --git a/common/src/states/basic_beam.rs b/common/src/states/basic_beam.rs index eb7c936cd1..80887e27b8 100644 --- a/common/src/states/basic_beam.rs +++ b/common/src/states/basic_beam.rs @@ -101,20 +101,14 @@ impl CharacterBehavior for Data { timer: tick_attack_or_default(data, self.timer, None), ..*self }); - if let Body::Object(object) = data.body { - match object { - &Flamethrower | &Lavathrower => { - // Send local event used for frontend shenanigans - output_events.emit_local(LocalEvent::CreateOutcome( - Outcome::FlamethrowerCharge { - pos: data.pos.0 - + *data.ori.look_dir() * (data.body.max_radius()), - }, - )); + if matches!(data.body, Body::Object(Flamethrower | Lavathrower)) { + // Send local event used for frontend shenanigans + output_events.emit_local(LocalEvent::CreateOutcome( + Outcome::FlamethrowerCharge { + pos: data.pos.0 + *data.ori.look_dir() * (data.body.max_radius()), }, - _ => {}, - } - }; + )); + } } else { let attack = { let energy = AttackEffect::new( diff --git a/common/src/states/leap_melee.rs b/common/src/states/leap_melee.rs index 0e89f3f0e8..2a24a483ba 100644 --- a/common/src/states/leap_melee.rs +++ b/common/src/states/leap_melee.rs @@ -32,7 +32,6 @@ pub struct StaticData { pub vertical_leap_strength: f32, /// What key is used to press ability pub ability_info: AbilityInfo, - /// pub damage_effect: Option, } diff --git a/common/src/uid.rs b/common/src/uid.rs index 1adffcf0fa..a7849ef575 100644 --- a/common/src/uid.rs +++ b/common/src/uid.rs @@ -3,7 +3,7 @@ use core::hash::Hash; use hashbrown::HashMap; use serde::{Deserialize, Serialize}; use specs::{Component, Entity, FlaggedStorage, VecStorage}; -use std::{fmt, u64}; +use std::fmt; use tracing::error; // TODO: could we switch this to `NonZeroU64`? diff --git a/network/examples/fileshare/main.rs b/network/examples/fileshare/main.rs index 5e337bc4d1..015e46e9eb 100644 --- a/network/examples/fileshare/main.rs +++ b/network/examples/fileshare/main.rs @@ -1,4 +1,4 @@ -#![feature(async_closure, exclusive_range_pattern)] +#![feature(async_closure)] //!run with //! (cd network/examples/fileshare && RUST_BACKTRACE=1 cargo run //! --profile=release -Z unstable-options -- --trace=info --port 15006) diff --git a/network/examples/fileshare/server.rs b/network/examples/fileshare/server.rs index f6be103012..efe0b886af 100644 --- a/network/examples/fileshare/server.rs +++ b/network/examples/fileshare/server.rs @@ -123,7 +123,7 @@ impl Shared { async fn connect_manager(&self, network: Network) { trace!("Start connect_manager"); - let iter = futures_util::stream::unfold(network, async move |mut network| { + let iter = futures_util::stream::unfold(network, async move |mut network: Network| { network.connected().await.ok().map(|v| (v, network)) }); diff --git a/server/src/lib.rs b/server/src/lib.rs index 824256ff0a..ddcdd753c0 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -115,7 +115,6 @@ use specs::{ shred::SendDispatcher, Builder, Entity as EcsEntity, Entity, Join, LendJoin, WorldExt, }; use std::{ - i32, ops::{Deref, DerefMut}, sync::{Arc, Mutex}, time::{Duration, Instant}, diff --git a/server/src/persistence/character_updater.rs b/server/src/persistence/character_updater.rs index 8ee27875ac..456deedc1f 100644 --- a/server/src/persistence/character_updater.rs +++ b/server/src/persistence/character_updater.rs @@ -263,7 +263,7 @@ impl CharacterUpdater { } pub fn has_pending_database_action(&self, character_id: CharacterId) -> bool { - self.pending_database_actions.get(&character_id).is_some() + self.pending_database_actions.contains_key(&character_id) } pub fn process_batch_completion(&mut self, completed_batch_id: u64) { diff --git a/server/src/persistence/mod.rs b/server/src/persistence/mod.rs index 9b0e8f5e02..ceb69a148e 100644 --- a/server/src/persistence/mod.rs +++ b/server/src/persistence/mod.rs @@ -146,6 +146,7 @@ impl core::str::FromStr for SqlLogMode { } } +#[allow(clippy::to_string_trait_impl)] impl ToString for SqlLogMode { fn to_string(&self) -> String { match self { diff --git a/voxygen/src/ecs/sys/interpolation.rs b/voxygen/src/ecs/sys/interpolation.rs index ebcdbb295e..2cc6e0eef4 100644 --- a/voxygen/src/ecs/sys/interpolation.rs +++ b/voxygen/src/ecs/sys/interpolation.rs @@ -92,14 +92,13 @@ impl<'a> System<'a> for Sys { fn base_ori_interp(body: &Body) -> f32 { match body { - Body::Object(object) => match object { + Body::Object( object::Body::Crossbow | object::Body::Flamethrower | object::Body::Lavathrower | object::Body::HaniwaSentry - | object::Body::TerracottaStatue => 100.0, - _ => 10.0, - }, + | object::Body::TerracottaStatue, + ) => 100.0, _ => 10.0, } } diff --git a/voxygen/src/hud/chat.rs b/voxygen/src/hud/chat.rs index b41ea6c19d..20d29d5d62 100644 --- a/voxygen/src/hud/chat.rs +++ b/voxygen/src/hud/chat.rs @@ -318,7 +318,7 @@ impl<'a> Widget for Chat<'a> { } if let Some(comps) = &self.force_completions { - state.update(|s| s.completions = comps.clone()); + state.update(|s| s.completions.clone_from(comps)); } let mut force_cursor = self.force_cursor; @@ -394,8 +394,8 @@ impl<'a> Widget for Chat<'a> { } else if s.history_pos > 0 { s.history_pos -= 1; } - if s.history_pos > 0 { - s.input.message = s.history.get(s.history_pos - 1).unwrap().to_owned(); + if let Some(before) = s.history.iter().nth_back(s.history.len() - s.history_pos) { + s.input.message.clone_from(before); force_cursor = cursor_offset_to_index( s.input.message.len(), &s.input.message, diff --git a/voxygen/src/hud/trade.rs b/voxygen/src/hud/trade.rs index 3340d405a9..f9012ee0b3 100644 --- a/voxygen/src/hud/trade.rs +++ b/voxygen/src/hud/trade.rs @@ -746,7 +746,7 @@ impl<'a> Trade<'a> { .set(state.ids.amount_input, ui) { if new_input != key.input { - key.input = new_input.trim().to_owned(); + new_input.trim().clone_into(&mut key.input); if !key.input.is_empty() { // trade amount can change with (shift||ctrl)-click let amount = *trade.offers[key.who].get(&key.slot).unwrap_or(&0); diff --git a/voxygen/src/main.rs b/voxygen/src/main.rs index 242aee437d..bb89fd0e69 100644 --- a/voxygen/src/main.rs +++ b/voxygen/src/main.rs @@ -182,7 +182,7 @@ fn main() { ?selected_language, "Impossible to load language: change to the default language (English) instead.", ); - settings.language.selected_language = i18n::REFERENCE_LANG.to_owned(); + i18n::REFERENCE_LANG.clone_into(&mut settings.language.selected_language); LocalizationHandle::load_expect(&settings.language.selected_language) }); i18n.set_english_fallback(settings.language.use_english_fallback); diff --git a/voxygen/src/menu/main/mod.rs b/voxygen/src/menu/main/mod.rs index 42cb84f9d6..9da9311d49 100644 --- a/voxygen/src/menu/main/mod.rs +++ b/voxygen/src/menu/main/mod.rs @@ -376,8 +376,8 @@ impl PlayState for MainMenuState { let use_srv = net_settings.use_srv; let use_quic = net_settings.use_quic; let validate_tls = net_settings.validate_tls; - net_settings.username = username.clone(); - net_settings.default_server = server_address.clone(); + net_settings.username.clone_from(&username); + net_settings.default_server.clone_from(&server_address); if !net_settings.servers.contains(&server_address) { net_settings.servers.push(server_address.clone()); } diff --git a/voxygen/src/menu/main/ui/mod.rs b/voxygen/src/menu/main/ui/mod.rs index e7fa731073..1e3f7cd65f 100644 --- a/voxygen/src/menu/main/ui/mod.rs +++ b/voxygen/src/menu/main/ui/mod.rs @@ -549,7 +549,7 @@ impl Controls { }, Message::ServerChanged(new_value) => { self.selected_server_index = Some(new_value); - self.login_info.server = servers[new_value].clone(); + self.login_info.server.clone_from(&servers[new_value]); }, Message::FocusPassword => { if let Screen::Login { screen, .. } = &mut self.screen { diff --git a/voxygen/src/mesh/segment.rs b/voxygen/src/mesh/segment.rs index 52e6838b9e..e1087cab7c 100644 --- a/voxygen/src/mesh/segment.rs +++ b/voxygen/src/mesh/segment.rs @@ -18,7 +18,7 @@ use vek::*; // /// NOTE: bone_idx must be in [0, 15] (may be bumped to [0, 31] at some // /// point). // TODO: this function name... -pub fn generate_mesh_base_vol_figure<'a: 'b, 'b, V: 'a>( +pub fn generate_mesh_base_vol_figure<'a: 'b, 'b, V>( vol: V, (greedy, opaque_mesh, offs, scale, bone_idx): ( &'b mut GreedyMesh<'a, FigureSpriteAtlasData>, @@ -29,7 +29,7 @@ pub fn generate_mesh_base_vol_figure<'a: 'b, 'b, V: 'a>( ), ) -> MeshGen> where - V: BaseVol + ReadVol + SizedVol, + V: BaseVol + ReadVol + SizedVol + 'a, { assert!(bone_idx <= 15, "Bone index for figures must be in [0, 15]"); let max_size = greedy.max_size(); @@ -115,7 +115,7 @@ where // /// NOTE: bone_idx must be in [0, 15] (may be bumped to [0, 31] at some // /// point). // TODO: this function name... -pub fn generate_mesh_base_vol_terrain<'a: 'b, 'b, V: 'a>( +pub fn generate_mesh_base_vol_terrain<'a: 'b, 'b, V>( vol: V, (greedy, opaque_mesh, offs, scale, bone_idx): ( &'b mut GreedyMesh<'a, FigureSpriteAtlasData>, @@ -126,7 +126,7 @@ pub fn generate_mesh_base_vol_terrain<'a: 'b, 'b, V: 'a>( ), ) -> MeshGen> where - V: BaseVol + ReadVol + SizedVol, + V: BaseVol + ReadVol + SizedVol + 'a, { assert!(bone_idx <= 15, "Bone index for figures must be in [0, 15]"); let max_size = greedy.max_size(); @@ -218,7 +218,7 @@ where (Mesh::new(), Mesh::new(), Mesh::new(), bounds) } -pub fn generate_mesh_base_vol_sprite<'a: 'b, 'b, V: 'a>( +pub fn generate_mesh_base_vol_sprite<'a: 'b, 'b, V>( vol: V, (greedy, opaque_mesh, vertical_stripes): ( &'b mut GreedyMesh<'a, FigureSpriteAtlasData, greedy::SpriteAtlasAllocator>, @@ -228,7 +228,7 @@ pub fn generate_mesh_base_vol_sprite<'a: 'b, 'b, V: 'a>( offset: Vec3, ) -> MeshGen where - V: BaseVol + ReadVol + SizedVol, + V: BaseVol + ReadVol + SizedVol + 'a, { let max_size = greedy.max_size(); // NOTE: Required because we steal two bits from the normal in the shadow uint @@ -345,12 +345,12 @@ where (Mesh::new(), Mesh::new(), Mesh::new(), ()) } -pub fn generate_mesh_base_vol_particle<'a: 'b, 'b, V: 'a>( +pub fn generate_mesh_base_vol_particle<'a: 'b, 'b, V>( vol: V, greedy: &'b mut GreedyMesh<'a, FigureSpriteAtlasData>, ) -> MeshGen where - V: BaseVol + ReadVol + SizedVol, + V: BaseVol + ReadVol + SizedVol + 'a, { let max_size = greedy.max_size(); // NOTE: Required because we steal two bits from the normal in the shadow uint @@ -437,7 +437,7 @@ fn should_draw_greedy( let from = flat_get(pos - delta); let to = flat_get(pos); let from_opaque = from.is_filled(); - if from_opaque != !to.is_filled() { + if from_opaque == to.is_filled() { None } else { // If going from transparent to opaque, backward facing; otherwise, forward @@ -456,7 +456,7 @@ fn should_draw_greedy_ao( let from = flat_get(pos - delta); let to = flat_get(pos); let from_opaque = from.is_filled(); - if from_opaque != !to.is_filled() { + if from_opaque == to.is_filled() { None } else { let faces_forward = from_opaque; diff --git a/voxygen/src/scene/figure/load.rs b/voxygen/src/scene/figure/load.rs index 72f7e5b436..a0e6fe70e7 100644 --- a/voxygen/src/scene/figure/load.rs +++ b/voxygen/src/scene/figure/load.rs @@ -5665,14 +5665,11 @@ impl ItemDropCentralSpec { (segment, match item_drop { // TODO: apply non-random rotations to items here item_drop::Body::Tool(_) => Vec3::new(offset.x - 2.0, offset.y, offset.z), - item_drop::Body::Armor(kind) => match kind { + item_drop::Body::Armor( item_drop::ItemDropArmorKind::Neck | item_drop::ItemDropArmorKind::Back - | item_drop::ItemDropArmorKind::Tabard => { - Vec3::new(offset.x, offset.y - 2.0, offset.z) - }, - _ => offset * Vec3::new(1.0, 1.0, 0.0), - }, + | item_drop::ItemDropArmorKind::Tabard, + ) => Vec3::new(offset.x, offset.y - 2.0, offset.z), _ => offset * Vec3::new(1.0, 1.0, 0.0), }) } else { diff --git a/voxygen/src/scene/figure/mod.rs b/voxygen/src/scene/figure/mod.rs index 87102a003c..d4261e6ffe 100644 --- a/voxygen/src/scene/figure/mod.rs +++ b/voxygen/src/scene/figure/mod.rs @@ -241,14 +241,10 @@ impl FigureMgrStates { } } - fn get_mut<'a, Q: ?Sized>( - &'a mut self, - body: &Body, - entity: &Q, - ) -> Option<&'a mut FigureStateMeta> + fn get_mut<'a, Q>(&'a mut self, body: &Body, entity: &Q) -> Option<&'a mut FigureStateMeta> where EcsEntity: Borrow, - Q: Hash + Eq, + Q: Hash + Eq + ?Sized, { match body { Body::Humanoid(_) => self @@ -320,10 +316,10 @@ impl FigureMgrStates { } } - fn remove(&mut self, body: &Body, entity: &Q) -> Option + fn remove(&mut self, body: &Body, entity: &Q) -> Option where EcsEntity: Borrow, - Q: Hash + Eq, + Q: Hash + Eq + ?Sized, { match body { Body::Humanoid(_) => self.character_states.remove(entity).map(|e| e.meta), @@ -494,14 +490,14 @@ impl FigureMgrStates { .count() } - fn get_terrain_locals<'a, Q: ?Sized>( + fn get_terrain_locals<'a, Q>( &'a self, body: &Body, entity: &Q, ) -> Option<&'a BoundTerrainLocals> where EcsEntity: Borrow, - Q: Hash + Eq, + Q: Hash + Eq + ?Sized, { match body { Body::Ship(body) => { diff --git a/voxygen/src/singleplayer/singleplayer_world.rs b/voxygen/src/singleplayer/singleplayer_world.rs index cddfe15a93..de37ae3dd3 100644 --- a/voxygen/src/singleplayer/singleplayer_world.rs +++ b/voxygen/src/singleplayer/singleplayer_world.rs @@ -214,7 +214,7 @@ impl SingleplayerWorlds { 'fail: loop { for world in self.worlds.iter() { if world.path.ends_with(&test_name) { - test_name = name.clone(); + test_name.clone_from(&name); test_name.push('_'); test_name.push_str(&i.to_string()); i += 1;