From 10970841cc31ed29ea716f9de4c48ee4960cacc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=A4rtens?= Date: Mon, 17 Aug 2020 10:28:02 +0200 Subject: [PATCH 1/2] fix master / update toolchain to `2020-08-15` --- network/src/lib.rs | 2 +- network/src/message.rs | 20 ++++---------------- rust-toolchain | 2 +- 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/network/src/lib.rs b/network/src/lib.rs index 51d4e7a1e1..264527c5d3 100644 --- a/network/src/lib.rs +++ b/network/src/lib.rs @@ -1,7 +1,7 @@ #![deny(unsafe_code)] #![cfg_attr(test, deny(rust_2018_idioms))] #![cfg_attr(test, deny(warnings))] -#![feature(try_trait, const_if_match)] +#![feature(try_trait)] //! Crate to handle high level networking of messages with different //! requirements and priorities over a number of protocols diff --git a/network/src/message.rs b/network/src/message.rs index 03626f22d3..a8c9eb1612 100644 --- a/network/src/message.rs +++ b/network/src/message.rs @@ -112,26 +112,14 @@ pub(crate) fn partial_eq_bincode(first: &bincode::ErrorKind, second: &bincode::E bincode::ErrorKind::InvalidBoolEncoding(s) => f == s, _ => false, }, - bincode::ErrorKind::InvalidCharEncoding => match *second { - bincode::ErrorKind::InvalidCharEncoding => true, - _ => false, - }, + bincode::ErrorKind::InvalidCharEncoding => matches!(*second, bincode::ErrorKind::InvalidCharEncoding), bincode::ErrorKind::InvalidTagEncoding(f) => match *second { bincode::ErrorKind::InvalidTagEncoding(s) => f == s, _ => false, }, - bincode::ErrorKind::DeserializeAnyNotSupported => match *second { - bincode::ErrorKind::DeserializeAnyNotSupported => true, - _ => false, - }, - bincode::ErrorKind::SizeLimit => match *second { - bincode::ErrorKind::SizeLimit => true, - _ => false, - }, - bincode::ErrorKind::SequenceMustHaveLength => match *second { - bincode::ErrorKind::SequenceMustHaveLength => true, - _ => false, - }, + bincode::ErrorKind::DeserializeAnyNotSupported => matches!(*second, bincode::ErrorKind::DeserializeAnyNotSupported), + bincode::ErrorKind::SizeLimit => matches!(*second, bincode::ErrorKind::SizeLimit), + bincode::ErrorKind::SequenceMustHaveLength => matches!(*second, bincode::ErrorKind::SequenceMustHaveLength), bincode::ErrorKind::Custom(ref f) => match *second { bincode::ErrorKind::Custom(ref s) => f == s, _ => false, diff --git a/rust-toolchain b/rust-toolchain index 38819f8f09..83d79d2890 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2020-06-22 +nightly-2020-08-15 From 8687740265861791af74e234e61620d8b047e5d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=A4rtens?= Date: Mon, 17 Aug 2020 11:08:11 +0200 Subject: [PATCH 2/2] fix clippy warnings in new version --- common/src/comp/agent.rs | 19 ++--------- common/src/comp/body.rs | 7 +--- common/src/comp/character_state.rs | 32 +++++-------------- common/src/figure/mat_cell.rs | 7 +--- common/src/terrain/block.rs | 7 +--- common/src/terrain/structure.rs | 7 +--- network/src/message.rs | 12 +++++-- server/src/client.rs | 16 +++++----- server/src/events/entity_manipulation.rs | 1 + server/src/events/inventory_manip.rs | 1 + server/src/state_ext.rs | 1 + server/src/sys/entity_sync.rs | 2 +- server/src/sys/message.rs | 2 +- voxygen/src/audio/mod.rs | 1 + .../src/audio/sfx/event_mapper/combat/mod.rs | 6 +--- voxygen/src/hud/chat.rs | 5 +-- voxygen/src/hud/mod.rs | 11 ++----- voxygen/src/scene/particle.rs | 3 ++ voxygen/src/settings.rs | 7 +--- voxygen/src/ui/event.rs | 12 +++---- world/src/sim/erosion.rs | 24 ++------------ world/src/sim/map.rs | 1 + .../settlement/building/archetype/house.rs | 16 ++-------- world/src/site/settlement/mod.rs | 7 ++-- 24 files changed, 59 insertions(+), 148 deletions(-) diff --git a/common/src/comp/agent.rs b/common/src/comp/agent.rs index 93642ab75e..22322b6df0 100644 --- a/common/src/comp/agent.rs +++ b/common/src/comp/agent.rs @@ -43,10 +43,7 @@ impl Alignment { // TODO: Remove this hack pub fn is_friendly_to_players(&self) -> bool { - match self { - Alignment::Npc | Alignment::Tame | Alignment::Owned(_) => true, - _ => false, - } + matches!(self, Alignment::Npc | Alignment::Tame | Alignment::Owned(_)) } } @@ -129,19 +126,9 @@ pub enum Activity { } impl Activity { - pub fn is_follow(&self) -> bool { - match self { - Activity::Follow { .. } => true, - _ => false, - } - } + pub fn is_follow(&self) -> bool { matches!(self, Activity::Follow { .. }) } - pub fn is_attack(&self) -> bool { - match self { - Activity::Attack { .. } => true, - _ => false, - } - } + pub fn is_attack(&self) -> bool { matches!(self, Activity::Attack { .. }) } } impl Default for Activity { diff --git a/common/src/comp/body.rs b/common/src/comp/body.rs index b685d0bb99..f0458c4b17 100644 --- a/common/src/comp/body.rs +++ b/common/src/comp/body.rs @@ -100,12 +100,7 @@ impl< } impl Body { - pub fn is_humanoid(&self) -> bool { - match self { - Body::Humanoid(_) => true, - _ => false, - } - } + pub fn is_humanoid(&self) -> bool { matches!(self, Body::Humanoid(_)) } // Note: this might need to be refined to something more complex for realistic // behavior with less cylindrical bodies (e.g. wolfs) diff --git a/common/src/comp/character_state.rs b/common/src/comp/character_state.rs index af1d1fac4c..7f7eef651d 100644 --- a/common/src/comp/character_state.rs +++ b/common/src/comp/character_state.rs @@ -73,7 +73,7 @@ pub enum CharacterState { impl CharacterState { pub fn is_wield(&self) -> bool { - match self { + matches!(self, CharacterState::Wielding | CharacterState::BasicMelee(_) | CharacterState::BasicRanged(_) @@ -82,50 +82,34 @@ impl CharacterState { | CharacterState::BasicBlock | CharacterState::LeapMelee(_) | CharacterState::SpinMelee(_) - | CharacterState::ChargedRanged(_) => true, - _ => false, - } + | CharacterState::ChargedRanged(_)) } pub fn is_attack(&self) -> bool { - match self { + matches!(self, CharacterState::BasicMelee(_) | CharacterState::BasicRanged(_) | CharacterState::DashMelee(_) | CharacterState::TripleStrike(_) | CharacterState::LeapMelee(_) | CharacterState::SpinMelee(_) - | CharacterState::ChargedRanged(_) => true, - _ => false, - } + | CharacterState::ChargedRanged(_)) } pub fn is_aimed(&self) -> bool { - match self { + matches!(self, CharacterState::BasicMelee(_) | CharacterState::BasicRanged(_) | CharacterState::DashMelee(_) | CharacterState::TripleStrike(_) | CharacterState::BasicBlock | CharacterState::LeapMelee(_) - | CharacterState::ChargedRanged(_) => true, - _ => false, - } + | CharacterState::ChargedRanged(_)) } - pub fn is_block(&self) -> bool { - match self { - CharacterState::BasicBlock => true, - _ => false, - } - } + pub fn is_block(&self) -> bool { matches!(self, CharacterState::BasicBlock) } - pub fn is_dodge(&self) -> bool { - match self { - CharacterState::Roll(_) => true, - _ => false, - } - } + pub fn is_dodge(&self) -> bool { matches!(self, CharacterState::Roll(_)) } /// Compares for shallow equality (does not check internal struct equality) pub fn same_variant(&self, other: &Self) -> bool { diff --git a/common/src/figure/mat_cell.rs b/common/src/figure/mat_cell.rs index 1a51b1da74..0c066d3681 100644 --- a/common/src/figure/mat_cell.rs +++ b/common/src/figure/mat_cell.rs @@ -25,10 +25,5 @@ pub enum MatCell { impl Vox for MatCell { fn empty() -> Self { MatCell::None } - fn is_empty(&self) -> bool { - match self { - MatCell::None => true, - _ => false, - } - } + fn is_empty(&self) -> bool { matches!(self, MatCell::None) } } diff --git a/common/src/terrain/block.rs b/common/src/terrain/block.rs index e228381c36..72717bd0fb 100644 --- a/common/src/terrain/block.rs +++ b/common/src/terrain/block.rs @@ -201,12 +201,7 @@ impl BlockKind { } } - pub fn is_fluid(&self) -> bool { - match self { - BlockKind::Water => true, - _ => false, - } - } + pub fn is_fluid(&self) -> bool { matches!(self, BlockKind::Water) } pub fn get_glow(&self) -> Option { // TODO: When we have proper volumetric lighting diff --git a/common/src/terrain/structure.rs b/common/src/terrain/structure.rs index 315e70065e..25501a4ac2 100644 --- a/common/src/terrain/structure.rs +++ b/common/src/terrain/structure.rs @@ -32,12 +32,7 @@ pub enum StructureBlock { impl Vox for StructureBlock { fn empty() -> Self { StructureBlock::None } - fn is_empty(&self) -> bool { - match self { - StructureBlock::None => true, - _ => false, - } - } + fn is_empty(&self) -> bool { matches!(self, StructureBlock::None) } } #[derive(Debug)] diff --git a/network/src/message.rs b/network/src/message.rs index a8c9eb1612..5238f6791a 100644 --- a/network/src/message.rs +++ b/network/src/message.rs @@ -112,14 +112,20 @@ pub(crate) fn partial_eq_bincode(first: &bincode::ErrorKind, second: &bincode::E bincode::ErrorKind::InvalidBoolEncoding(s) => f == s, _ => false, }, - bincode::ErrorKind::InvalidCharEncoding => matches!(*second, bincode::ErrorKind::InvalidCharEncoding), + bincode::ErrorKind::InvalidCharEncoding => { + matches!(*second, bincode::ErrorKind::InvalidCharEncoding) + }, bincode::ErrorKind::InvalidTagEncoding(f) => match *second { bincode::ErrorKind::InvalidTagEncoding(s) => f == s, _ => false, }, - bincode::ErrorKind::DeserializeAnyNotSupported => matches!(*second, bincode::ErrorKind::DeserializeAnyNotSupported), + bincode::ErrorKind::DeserializeAnyNotSupported => { + matches!(*second, bincode::ErrorKind::DeserializeAnyNotSupported) + }, bincode::ErrorKind::SizeLimit => matches!(*second, bincode::ErrorKind::SizeLimit), - bincode::ErrorKind::SequenceMustHaveLength => matches!(*second, bincode::ErrorKind::SequenceMustHaveLength), + bincode::ErrorKind::SequenceMustHaveLength => { + matches!(*second, bincode::ErrorKind::SequenceMustHaveLength) + }, bincode::ErrorKind::Custom(ref f) => match *second { bincode::ErrorKind::Custom(ref s) => f == s, _ => false, diff --git a/server/src/client.rs b/server/src/client.rs index 95e6d96b91..3cb76f659b 100644 --- a/server/src/client.rs +++ b/server/src/client.rs @@ -50,17 +50,17 @@ impl Client { } pub fn is_registered(&self) -> bool { - match self.client_state { - ClientState::Registered | ClientState::Spectator | ClientState::Character => true, - _ => false, - } + matches!( + self.client_state, + ClientState::Registered | ClientState::Spectator | ClientState::Character + ) } pub fn is_ingame(&self) -> bool { - match self.client_state { - ClientState::Spectator | ClientState::Character => true, - _ => false, - } + matches!( + self.client_state, + ClientState::Spectator | ClientState::Character + ) } pub fn allow_state(&mut self, new_state: ClientState) { diff --git a/server/src/events/entity_manipulation.rs b/server/src/events/entity_manipulation.rs index b74ab69cdb..b09f4c9f0d 100644 --- a/server/src/events/entity_manipulation.rs +++ b/server/src/events/entity_manipulation.rs @@ -33,6 +33,7 @@ pub fn handle_damage(server: &Server, uid: Uid, change: HealthChange) { /// other players. If the entity that killed it had stats, then give it exp for /// the kill. Experience given is equal to the level of the entity that was /// killed times 10. +#[allow(clippy::needless_collect)] pub fn handle_destroy(server: &mut Server, entity: EcsEntity, cause: HealthSource) { let state = server.state_mut(); diff --git a/server/src/events/inventory_manip.rs b/server/src/events/inventory_manip.rs index ca219723f6..de201fd6fa 100644 --- a/server/src/events/inventory_manip.rs +++ b/server/src/events/inventory_manip.rs @@ -33,6 +33,7 @@ pub fn snuff_lantern(storage: &mut WriteStorage, entity: Ecs } #[allow(clippy::blocks_in_if_conditions)] +#[allow(clippy::same_item_push)] // TODO: Pending review in #587 pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::InventoryManip) { let state = server.state_mut(); let mut dropped_items = Vec::new(); diff --git a/server/src/state_ext.rs b/server/src/state_ext.rs index 816b41401c..e2d8a8c15f 100644 --- a/server/src/state_ext.rs +++ b/server/src/state_ext.rs @@ -206,6 +206,7 @@ impl StateExt for State { } } + #[allow(clippy::map_identity)] // TODO: Pending review in #587 fn update_character_data(&mut self, entity: EcsEntity, components: PersistedComponents) { let (body, stats, inventory, loadout) = components; // Make sure physics are accepted. diff --git a/server/src/sys/entity_sync.rs b/server/src/sys/entity_sync.rs index 2dc20648b4..202592b44b 100644 --- a/server/src/sys/entity_sync.rs +++ b/server/src/sys/entity_sync.rs @@ -338,7 +338,7 @@ impl<'a> System<'a> for Sys { .filter(|o| o.get_pos().and_then(&is_near).unwrap_or(true)) .cloned() .collect::>(); - if outcomes.len() > 0 { + if !outcomes.is_empty() { client.notify(ServerMsg::Outcomes(outcomes)); } } diff --git a/server/src/sys/message.rs b/server/src/sys/message.rs index 0528e8cfba..234f6c0a86 100644 --- a/server/src/sys/message.rs +++ b/server/src/sys/message.rs @@ -192,7 +192,7 @@ impl Sys { }); // Give the player a welcome message - if settings.server_description.len() > 0 { + if !settings.server_description.is_empty() { client.notify( ChatType::CommandInfo .server_msg(settings.server_description.clone()), diff --git a/voxygen/src/audio/mod.rs b/voxygen/src/audio/mod.rs index 5af08f8dc6..a8796fe8e8 100644 --- a/voxygen/src/audio/mod.rs +++ b/voxygen/src/audio/mod.rs @@ -44,6 +44,7 @@ pub struct AudioFrontend { listener: Listener, } +#[allow(clippy::same_item_push)] // TODO: Pending review in #587 impl AudioFrontend { /// Construct with given device #[allow(clippy::redundant_clone)] // TODO: Pending review in #587 diff --git a/voxygen/src/audio/sfx/event_mapper/combat/mod.rs b/voxygen/src/audio/sfx/event_mapper/combat/mod.rs index 56aca955b0..3caeb17fc4 100644 --- a/voxygen/src/audio/sfx/event_mapper/combat/mod.rs +++ b/voxygen/src/audio/sfx/event_mapper/combat/mod.rs @@ -171,11 +171,7 @@ impl CombatEventMapper { /// ::Equipping to mean the weapon is drawn. This will need updating if the /// animations change to match the wield_duration associated with the weapon fn weapon_drawn(character: &CharacterState) -> bool { - character.is_wield() - || match character { - CharacterState::Equipping { .. } => true, - _ => false, - } + character.is_wield() || matches!(character, CharacterState::Equipping { .. }) } } diff --git a/voxygen/src/hud/chat.rs b/voxygen/src/hud/chat.rs index 2e35de6493..a89a29d62f 100644 --- a/voxygen/src/hud/chat.rs +++ b/voxygen/src/hud/chat.rs @@ -395,10 +395,7 @@ impl<'a> Widget for Chat<'a> { .widget_input(state.ids.chat_input) .presses() .key() - .any(|key_press| match key_press.key { - Key::Return if !state.input.is_empty() => true, - _ => false, - }) + .any(|key_press| matches!(key_press.key, Key::Return if !state.input.is_empty())) { let msg = state.input.clone(); state.update(|s| { diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index c2510cbea0..8bfc23d35c 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -477,10 +477,7 @@ impl Show { || self.spell || self.help || self.intro - || match self.open_windows { - Windows::None => false, - _ => true, - } + || !matches!(self.open_windows, Windows::None) { self.bag = false; self.esc_menu = false; @@ -2453,7 +2450,7 @@ impl Hud { // conrod eats tabs. Un-eat a tabstop so tab completion can work if self.ui.ui.global_input().events().any(|event| { use conrod_core::{event, input}; - match event { + matches!(event, //event::Event::Raw(event::Input::Press(input::Button::Keyboard(input::Key::Tab))) // => true, event::Event::Ui(event::Ui::Press( @@ -2462,9 +2459,7 @@ impl Hud { button: event::Button::Keyboard(input::Key::Tab), .. }, - )) => true, - _ => false, - } + ))) }) { self.ui .ui diff --git a/voxygen/src/scene/particle.rs b/voxygen/src/scene/particle.rs index aff6107727..7bc5fb6ff3 100644 --- a/voxygen/src/scene/particle.rs +++ b/voxygen/src/scene/particle.rs @@ -43,6 +43,7 @@ impl ParticleMgr { } } + #[allow(clippy::same_item_push)] // TODO: Pending review in #587 pub fn handle_outcome(&mut self, outcome: &Outcome, scene_data: &SceneData) { let time = scene_data.state.get_time(); let mut rng = rand::thread_rng(); @@ -177,6 +178,7 @@ impl ParticleMgr { } } + #[allow(clippy::same_item_push)] // TODO: Pending review in #587 fn maintain_boltfirebig_particles(&mut self, scene_data: &SceneData, pos: &Pos) { let time = scene_data.state.get_time(); @@ -223,6 +225,7 @@ impl ParticleMgr { } } + #[allow(clippy::same_item_push)] // TODO: Pending review in #587 fn maintain_boost_particles(&mut self, scene_data: &SceneData) { let state = scene_data.state; let ecs = state.ecs(); diff --git a/voxygen/src/settings.rs b/voxygen/src/settings.rs index 5e1e86f4b4..b953960231 100644 --- a/voxygen/src/settings.rs +++ b/voxygen/src/settings.rs @@ -660,12 +660,7 @@ pub enum AudioOutput { } impl AudioOutput { - pub fn is_enabled(&self) -> bool { - match self { - Self::Off => false, - _ => true, - } - } + pub fn is_enabled(&self) -> bool { !matches!(self, Self::Off) } } /// `AudioSettings` controls the volume of different audio subsystems and which /// device is used. diff --git a/voxygen/src/ui/event.rs b/voxygen/src/ui/event.rs index e5a30b62cf..e84deca87f 100644 --- a/voxygen/src/ui/event.rs +++ b/voxygen/src/ui/event.rs @@ -30,23 +30,19 @@ impl Event { } pub fn is_keyboard_or_mouse(&self) -> bool { - match self.0 { + matches!(self.0, Input::Press(_) | Input::Release(_) | Input::Motion(_) | Input::Touch(_) - | Input::Text(_) => true, - _ => false, - } + | Input::Text(_)) } pub fn is_keyboard(&self) -> bool { - match self.0 { + matches!(self.0, Input::Press(Button::Keyboard(_)) | Input::Release(Button::Keyboard(_)) - | Input::Text(_) => true, - _ => false, - } + | Input::Text(_)) } pub fn new_resize(dims: Vec2) -> Self { Self(Input::Resize(dims.x, dims.y)) } diff --git a/world/src/sim/erosion.rs b/world/src/sim/erosion.rs index 046207c8c3..19b946982b 100644 --- a/world/src/sim/erosion.rs +++ b/world/src/sim/erosion.rs @@ -111,29 +111,11 @@ pub enum RiverKind { } impl RiverKind { - pub fn is_ocean(&self) -> bool { - if let RiverKind::Ocean = *self { - true - } else { - false - } - } + pub fn is_ocean(&self) -> bool { matches!(self, RiverKind::Ocean) } - pub fn is_river(&self) -> bool { - if let RiverKind::River { .. } = *self { - true - } else { - false - } - } + pub fn is_river(&self) -> bool { matches!(self, RiverKind::River { .. }) } - pub fn is_lake(&self) -> bool { - if let RiverKind::Lake { .. } = *self { - true - } else { - false - } - } + pub fn is_lake(&self) -> bool { matches!(self, RiverKind::Lake { .. }) } } impl PartialOrd for RiverKind { diff --git a/world/src/sim/map.rs b/world/src/sim/map.rs index 6655b84e35..2dee374295 100644 --- a/world/src/sim/map.rs +++ b/world/src/sim/map.rs @@ -110,6 +110,7 @@ impl MapConfig { /// into the correct format for a buffer and writes to it. #[allow(clippy::if_same_then_else)] // TODO: Pending review in #587 #[allow(clippy::unnested_or_patterns)] // TODO: Pending review in #587 + #[allow(clippy::map_identity)] // TODO: Pending review in #587 #[allow(clippy::many_single_char_names)] pub fn generate( &self, diff --git a/world/src/site/settlement/building/archetype/house.rs b/world/src/site/settlement/building/archetype/house.rs index fc0f3365be..970e3a4698 100644 --- a/world/src/site/settlement/building/archetype/house.rs +++ b/world/src/site/settlement/building/archetype/house.rs @@ -93,21 +93,9 @@ pub enum StoreyFill { } impl StoreyFill { - fn has_lower(&self) -> bool { - if let StoreyFill::All = self { - true - } else { - false - } - } + fn has_lower(&self) -> bool { matches!(self, StoreyFill::All) } - fn has_upper(&self) -> bool { - if let StoreyFill::None = self { - false - } else { - true - } - } + fn has_upper(&self) -> bool { !matches!(self, StoreyFill::None) } } #[derive(Copy, Clone)] diff --git a/world/src/site/settlement/mod.rs b/world/src/site/settlement/mod.rs index 7b9f418965..4ead8da0bc 100644 --- a/world/src/site/settlement/mod.rs +++ b/world/src/site/settlement/mod.rs @@ -236,10 +236,7 @@ impl Settlement { let origin = dir.map(|e| (e * 100.0) as i32); let origin = self .land - .find_tile_near(origin, |plot| match plot { - Some(&Plot::Field { .. }) => true, - _ => false, - }) + .find_tile_near(origin, |plot| matches!(plot, Some(&Plot::Field { .. }))) .unwrap(); if let Some(path) = self.town.as_ref().and_then(|town| { @@ -520,7 +517,7 @@ impl Settlement { .land .get_at_block(wpos - self.origin) .plot - .map(|p| if let Plot::Hazard = p { true } else { false }) + .map(|p| matches!(p, Plot::Hazard)) .unwrap_or(true), ..SpawnRules::default() }