diff --git a/client/src/lib.rs b/client/src/lib.rs index 3a28b6d35d..e2bffe4579 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -1338,6 +1338,7 @@ impl Client { Ok(()) } + #[allow(clippy::unnecessary_wraps)] fn handle_server_in_game_msg( &mut self, frontend_events: &mut Vec, @@ -1492,6 +1493,7 @@ impl Client { Ok(()) } + #[allow(clippy::unnecessary_wraps)] fn handle_server_character_screen_msg( &mut self, events: &mut Vec, @@ -1765,7 +1767,7 @@ impl Client { comp::ChatType::Online(uid) => { // Default message formats if no localized message string is set by hud // Needed for cli clients that don't set localization info - if message == "" { + if message.is_empty() { format!("[{}] came online", alias_of_uid(uid)) } else { message.replace("{name}", &alias_of_uid(uid)) @@ -1774,7 +1776,7 @@ impl Client { comp::ChatType::Offline(uid) => { // Default message formats if no localized message string is set by hud // Needed for cli clients that don't set localization info - if message == "" { + if message.is_empty() { format!("[{}] went offline", alias_of_uid(uid)) } else { message.replace("{name}", &alias_of_uid(uid)) @@ -1788,7 +1790,7 @@ impl Client { comp::ChatType::Kill(kill_source, victim) => { // Default message formats if no localized message string is set by hud // Needed for cli clients that don't set localization info - if message == "" { + if message.is_empty() { match kill_source { KillSource::Player(attacker_uid, KillType::Melee) => format!( "[{}] killed [{}]", diff --git a/common/src/comp/character_state.rs b/common/src/comp/character_state.rs index fc58d86f90..ff5ebb55a8 100644 --- a/common/src/comp/character_state.rs +++ b/common/src/comp/character_state.rs @@ -82,20 +82,21 @@ pub enum CharacterState { impl CharacterState { pub fn is_wield(&self) -> bool { - matches!(self, + matches!( + self, CharacterState::Wielding - | CharacterState::BasicMelee(_) - | CharacterState::BasicRanged(_) - | CharacterState::DashMelee(_) - | CharacterState::ComboMelee(_) - | CharacterState::BasicBlock - | CharacterState::LeapMelee(_) - | CharacterState::SpinMelee(_) - | CharacterState::ChargedMelee(_) - | CharacterState::ChargedRanged(_) - | CharacterState::RepeaterRanged(_) - | CharacterState::Shockwave(_) - | CharacterState::BasicBeam(_) + | CharacterState::BasicMelee(_) + | CharacterState::BasicRanged(_) + | CharacterState::DashMelee(_) + | CharacterState::ComboMelee(_) + | CharacterState::BasicBlock + | CharacterState::LeapMelee(_) + | CharacterState::SpinMelee(_) + | CharacterState::ChargedMelee(_) + | CharacterState::ChargedRanged(_) + | CharacterState::RepeaterRanged(_) + | CharacterState::Shockwave(_) + | CharacterState::BasicBeam(_) ) } @@ -104,35 +105,37 @@ impl CharacterState { } pub fn is_attack(&self) -> bool { - matches!(self, + matches!( + self, CharacterState::BasicMelee(_) - | CharacterState::BasicRanged(_) - | CharacterState::DashMelee(_) - | CharacterState::ComboMelee(_) - | CharacterState::LeapMelee(_) - | CharacterState::SpinMelee(_) - | CharacterState::ChargedMelee(_) - | CharacterState::ChargedRanged(_) - | CharacterState::RepeaterRanged(_) - | CharacterState::Shockwave(_) - | CharacterState::BasicBeam(_) + | CharacterState::BasicRanged(_) + | CharacterState::DashMelee(_) + | CharacterState::ComboMelee(_) + | CharacterState::LeapMelee(_) + | CharacterState::SpinMelee(_) + | CharacterState::ChargedMelee(_) + | CharacterState::ChargedRanged(_) + | CharacterState::RepeaterRanged(_) + | CharacterState::Shockwave(_) + | CharacterState::BasicBeam(_) ) } pub fn is_aimed(&self) -> bool { - matches!(self, + matches!( + self, CharacterState::BasicMelee(_) - | CharacterState::BasicRanged(_) - | CharacterState::DashMelee(_) - | CharacterState::ComboMelee(_) - | CharacterState::BasicBlock - | CharacterState::LeapMelee(_) - | CharacterState::ChargedMelee(_) - | CharacterState::ChargedRanged(_) - | CharacterState::RepeaterRanged(_) - | CharacterState::Shockwave(_) - | CharacterState::BasicBeam(_) - | CharacterState::Wielding + | CharacterState::BasicRanged(_) + | CharacterState::DashMelee(_) + | CharacterState::ComboMelee(_) + | CharacterState::BasicBlock + | CharacterState::LeapMelee(_) + | CharacterState::ChargedMelee(_) + | CharacterState::ChargedRanged(_) + | CharacterState::RepeaterRanged(_) + | CharacterState::Shockwave(_) + | CharacterState::BasicBeam(_) + | CharacterState::Wielding ) } diff --git a/common/src/comp/inventory/item/mod.rs b/common/src/comp/inventory/item/mod.rs index 7933596660..8f4e1ad290 100644 --- a/common/src/comp/inventory/item/mod.rs +++ b/common/src/comp/inventory/item/mod.rs @@ -144,10 +144,13 @@ impl PartialEq for ItemDef { impl ItemDef { pub fn is_stackable(&self) -> bool { - matches!(self.kind, ItemKind::Consumable { .. } - | ItemKind::Ingredient { .. } - | ItemKind::Throwable { .. } - | ItemKind::Utility { .. }) + matches!( + self.kind, + ItemKind::Consumable { .. } + | ItemKind::Ingredient { .. } + | ItemKind::Throwable { .. } + | ItemKind::Utility { .. } + ) } } diff --git a/common/src/comp/inventory/slot.rs b/common/src/comp/inventory/slot.rs index 02f641b41c..817aa930f1 100644 --- a/common/src/comp/inventory/slot.rs +++ b/common/src/comp/inventory/slot.rs @@ -70,20 +70,20 @@ impl EquipSlot { impl ArmorSlot { fn can_hold(self, armor: &item::armor::ArmorKind) -> bool { use item::armor::ArmorKind; - match (self, armor) { - (Self::Head, ArmorKind::Head(_)) => true, - (Self::Neck, ArmorKind::Neck(_)) => true, - (Self::Shoulders, ArmorKind::Shoulder(_)) => true, - (Self::Chest, ArmorKind::Chest(_)) => true, - (Self::Hands, ArmorKind::Hand(_)) => true, - (Self::Ring, ArmorKind::Ring(_)) => true, - (Self::Back, ArmorKind::Back(_)) => true, - (Self::Belt, ArmorKind::Belt(_)) => true, - (Self::Legs, ArmorKind::Pants(_)) => true, - (Self::Feet, ArmorKind::Foot(_)) => true, - (Self::Tabard, ArmorKind::Tabard(_)) => true, - _ => false, - } + matches!( + (self, armor), + (Self::Head, ArmorKind::Head(_)) + | (Self::Neck, ArmorKind::Neck(_)) + | (Self::Shoulders, ArmorKind::Shoulder(_)) + | (Self::Chest, ArmorKind::Chest(_)) + | (Self::Hands, ArmorKind::Hand(_)) + | (Self::Ring, ArmorKind::Ring(_)) + | (Self::Back, ArmorKind::Back(_)) + | (Self::Belt, ArmorKind::Belt(_)) + | (Self::Legs, ArmorKind::Pants(_)) + | (Self::Feet, ArmorKind::Foot(_)) + | (Self::Tabard, ArmorKind::Tabard(_)) + ) } } diff --git a/common/src/npc.rs b/common/src/npc.rs index 806a34d24f..ca8d58f2f6 100644 --- a/common/src/npc.rs +++ b/common/src/npc.rs @@ -73,7 +73,7 @@ lazy_static! { impl FromStr for NpcKind { type Err = (); - fn from_str(s: &str) -> Result { + fn from_str(s: &str) -> Result { let npc_names = &*NPC_NAMES; ALL_NPCS .iter() @@ -126,13 +126,14 @@ impl FromStr for NpcBody { /// associated species, generate the species randomly within it; if an /// explicit species is found, generate a random member of the species; /// otherwise, return Err(()). - fn from_str(s: &str) -> Result { Self::from_str_with(s, kind_to_body) } + fn from_str(s: &str) -> Result { Self::from_str_with(s, kind_to_body) } } impl NpcBody { /// If there is an exact name match for a body kind, call kind_to_body on /// it. Otherwise, if an explicit species is found, generate a random /// member of the species; otherwise, return Err(()). + #[allow(clippy::result_unit_err)] pub fn from_str_with(s: &str, kind_to_body: fn(NpcKind) -> Body) -> Result { fn parse< 'a, diff --git a/common/src/states/utils.rs b/common/src/states/utils.rs index 09abdbfe44..d1a7991061 100644 --- a/common/src/states/utils.rs +++ b/common/src/states/utils.rs @@ -133,21 +133,13 @@ impl Body { } pub fn can_fly(&self) -> bool { - match self { - Body::BirdMedium(_) => true, - Body::Dragon(_) => true, - Body::BirdSmall(_) => true, - _ => false, - } + matches!( + self, + Body::BirdMedium(_) | Body::Dragon(_) | Body::BirdSmall(_) + ) } - #[allow(clippy::match_like_matches_macro)] - pub fn can_climb(&self) -> bool { - match self { - Body::Humanoid(_) => true, - _ => false, - } - } + pub fn can_climb(&self) -> bool { matches!(self, Body::Humanoid(_)) } } /// Handles updating `Components` to move player based on state of `JoinData` diff --git a/common/src/terrain/map.rs b/common/src/terrain/map.rs index 2a50b9a982..8ff78641cc 100644 --- a/common/src/terrain/map.rs +++ b/common/src/terrain/map.rs @@ -155,6 +155,7 @@ impl MapSizeLg { /// that these invariants indeed hold, safely opening up optimizations /// that might not otherwise be available at runtime. #[inline(always)] + #[allow(clippy::result_unit_err)] pub const fn new(map_size_lg: Vec2) -> Result { // Assertion on dimensions: must be between // 0 and ([MAX_WORLD_BLOCKS_LG] - [TERRAIN_CHUNK_BLOCKS_LG]) diff --git a/common/src/terrain/mod.rs b/common/src/terrain/mod.rs index 74591cd049..d1c478381c 100644 --- a/common/src/terrain/mod.rs +++ b/common/src/terrain/mod.rs @@ -259,8 +259,8 @@ pub fn quadratic_nearest_point( // In the (unlikely?) case that distances are equal, prefer the earliest point along the // river. .min_by(|&(ap, _, a), &(bp, _, b)| { - (a, ap < 0.0 || ap > 1.0, ap) - .partial_cmp(&(b, bp < 0.0 || bp > 1.0, bp)) + (a, !(0.0..=1.0).contains(&ap), ap) + .partial_cmp(&(b, !(0.0..=1.0).contains(&bp), bp)) .unwrap() }); min_root diff --git a/common/src/util/color.rs b/common/src/util/color.rs index e20b526bb8..c1e4c273d2 100644 --- a/common/src/util/color.rs +++ b/common/src/util/color.rs @@ -81,7 +81,7 @@ pub fn hsv_to_rgb(hsv: Vec3) -> Rgb { let x = c * (1.0 - (h % 2.0 - 1.0).abs()); let m = v - c; - let (r, g, b) = if h >= 0.0 && h <= 1.0 { + let (r, g, b) = if (0.0..=1.0).contains(&h) { (c, x, 0.0) } else if h <= 2.0 { (x, c, 0.0) diff --git a/common/src/util/dir.rs b/common/src/util/dir.rs index 30cb4cfe07..1ba5055f4d 100644 --- a/common/src/util/dir.rs +++ b/common/src/util/dir.rs @@ -119,7 +119,7 @@ fn slerp_normalized(from: vek::Vec3, to: vek::Vec3, factor: f32) -> ve { let unnormalized = { let len_sq = from.magnitude_squared(); - len_sq < 0.999 || len_sq > 1.001 + !(0.999..=1.001).contains(&len_sq) }; if unnormalized { @@ -132,7 +132,7 @@ fn slerp_normalized(from: vek::Vec3, to: vek::Vec3, factor: f32) -> ve { let unnormalized = { let len_sq = from.magnitude_squared(); - len_sq < 0.999 || len_sq > 1.001 + !(0.999..=1.001).contains(&len_sq) }; if unnormalized { diff --git a/common/src/util/mod.rs b/common/src/util/mod.rs index 1656467664..3da0f632a9 100644 --- a/common/src/util/mod.rs +++ b/common/src/util/mod.rs @@ -13,12 +13,12 @@ lazy_static::lazy_static! { static ref GIT_DATETIME: &'static str = GIT_VERSION.split('/').nth(1).expect("failed to retrieve git_datetime!"); pub static ref GIT_DATE: String = GIT_DATETIME.split('-').take(3).collect::>().join("-"); pub static ref GIT_TIME: &'static str = GIT_DATETIME.split('-').nth(3).expect("failed to retrieve git_time!"); - pub static ref DISPLAY_VERSION: String = if GIT_TAG == "" { + pub static ref DISPLAY_VERSION: String = if GIT_TAG.is_empty() { format!("{}-{}", VELOREN_VERSION_STAGE, GIT_DATE.to_string()) } else { format!("{}-{}", VELOREN_VERSION_STAGE, GIT_TAG.to_string()) }; - pub static ref DISPLAY_VERSION_LONG: String = if GIT_TAG == "" { + pub static ref DISPLAY_VERSION_LONG: String = if GIT_TAG.is_empty() { format!("{} ({})", DISPLAY_VERSION.as_str(), GIT_HASH.to_string()) } else { format!("{} ({})", DISPLAY_VERSION.as_str(), GIT_VERSION.to_string()) diff --git a/rust-toolchain b/rust-toolchain index 148ed93dbc..ea448088e5 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2020-10-25 +nightly-2020-12-09 diff --git a/server-cli/src/logging.rs b/server-cli/src/logging.rs index 394400296f..6a738ed2c5 100644 --- a/server-cli/src/logging.rs +++ b/server-cli/src/logging.rs @@ -56,7 +56,9 @@ pub fn init(basic: bool) { .with_env_filter(filter); if basic { - subscriber.with_writer(|| StandardStream::stdout(ColorChoice::Auto)).init(); + subscriber + .with_writer(|| StandardStream::stdout(ColorChoice::Auto)) + .init(); } else { subscriber.with_writer(|| LOG.clone()).init(); } diff --git a/server-cli/src/main.rs b/server-cli/src/main.rs index eabbcf96fd..ba83e1d67f 100644 --- a/server-cli/src/main.rs +++ b/server-cli/src/main.rs @@ -25,6 +25,7 @@ use tracing::info; const TPS: u64 = 30; +#[allow(clippy::unnecessary_wraps)] fn main() -> io::Result<()> { let matches = App::new("Veloren server cli") .version(common::util::DISPLAY_VERSION_LONG.as_str()) diff --git a/server-cli/src/tui_runner.rs b/server-cli/src/tui_runner.rs index 834fd7fd62..5b7cde1013 100644 --- a/server-cli/src/tui_runner.rs +++ b/server-cli/src/tui_runner.rs @@ -204,12 +204,14 @@ impl Tui { let block = Block::default().borders(Borders::ALL); - let mut wrap = Wrap::default(); - wrap.scroll_callback = Some(Box::new(|text_area, lines| { - LOG.resize(text_area.height as usize); - let len = lines.len() as u16; - (len.saturating_sub(text_area.height), 0) - })); + let wrap = Wrap { + scroll_callback: Some(Box::new(|text_area, lines| { + LOG.resize(text_area.height as usize); + let len = lines.len() as u16; + (len.saturating_sub(text_area.height), 0) + })), + ..Default::default() + }; let logger = Paragraph::new(LOG.inner.lock().unwrap().clone()) .block(block) diff --git a/server/src/events/entity_manipulation.rs b/server/src/events/entity_manipulation.rs index 6914dc30d9..73a85b45f7 100644 --- a/server/src/events/entity_manipulation.rs +++ b/server/src/events/entity_manipulation.rs @@ -552,6 +552,7 @@ pub fn handle_respawn(server: &Server, entity: EcsEntity) { } } +#[allow(clippy::blocks_in_if_conditions)] pub fn handle_explosion( server: &Server, pos: Vec3, @@ -565,9 +566,18 @@ pub fn handle_explosion( // Add an outcome // Uses radius as outcome power, makes negative if explosion has healing effect let outcome_power = explosion.radius - * if explosion.effects.iter().any( - |e| matches!(e, RadiusEffect::Entity(_, Effect::Damage(Damage { source: DamageSource::Healing, .. }))) - ) { + * if explosion.effects.iter().any(|e| { + matches!( + e, + RadiusEffect::Entity( + _, + Effect::Damage(Damage { + source: DamageSource::Healing, + .. + }) + ) + ) + }) { -1.0 } else { 1.0 diff --git a/server/src/events/inventory_manip.rs b/server/src/events/inventory_manip.rs index b141e7544d..013c07ae44 100644 --- a/server/src/events/inventory_manip.rs +++ b/server/src/events/inventory_manip.rs @@ -572,6 +572,7 @@ mod tests { use vek::Vec3; // Helper function + #[allow(clippy::unnecessary_wraps)] fn test_cylinder(pos: comp::Pos) -> Option { Some(Cylinder::from_components(pos.0, None, None, None)) } diff --git a/server/src/sys/msg/general.rs b/server/src/sys/msg/general.rs index a5277a85e5..a41734dde7 100644 --- a/server/src/sys/msg/general.rs +++ b/server/src/sys/msg/general.rs @@ -14,6 +14,7 @@ use tracing::{debug, error, warn}; impl Sys { #[allow(clippy::too_many_arguments)] + #[allow(clippy::unnecessary_wraps)] fn handle_general_msg( server_emitter: &mut common::event::Emitter<'_, ServerEvent>, new_chat_msgs: &mut Vec<(Option, UnresolvedChatMsg)>, diff --git a/server/src/sys/msg/in_game.rs b/server/src/sys/msg/in_game.rs index a575b10fd9..78aaf09e9b 100644 --- a/server/src/sys/msg/in_game.rs +++ b/server/src/sys/msg/in_game.rs @@ -38,7 +38,7 @@ impl Sys { None => { debug!(?entity, "client is not in_game, ignoring msg"); trace!(?msg, "ignored msg content"); - if matches!(msg, ClientGeneral::TerrainChunkRequest{ .. }) { + if matches!(msg, ClientGeneral::TerrainChunkRequest { .. }) { network_metrics.chunks_request_dropped.inc(); } return Ok(()); diff --git a/voxygen/anim/src/quadruped_low/dash.rs b/voxygen/anim/src/quadruped_low/dash.rs index e64669ab23..836de317ac 100644 --- a/voxygen/anim/src/quadruped_low/dash.rs +++ b/voxygen/anim/src/quadruped_low/dash.rs @@ -44,13 +44,13 @@ impl Animation for DashAnimation { let movement1abs = movement1base * pullback; let movement2abs = movement2base * pullback; let short = (((1.0) - / (0.72 + 0.28 * ((anim_time as f32 * 16.0 as f32 + PI * 0.25).sin()).powi(2))) + / (0.72 + 0.28 * ((anim_time as f32 * 16.0_f32 + PI * 0.25).sin()).powi(2))) .sqrt()) - * ((anim_time as f32 * 16.0 as f32 + PI * 0.25).sin()) + * ((anim_time as f32 * 16.0_f32 + PI * 0.25).sin()) * chargemovementbase * pullback; let shortalt = - (anim_time as f32 * 16.0 as f32 + PI * 0.25).sin() * chargemovementbase * pullback; + (anim_time as f32 * 16.0_f32 + PI * 0.25).sin() * chargemovementbase * pullback; next.head_upper.orientation = Quaternion::rotation_x(movement1abs * 0.4 + movement2abs * 0.3) diff --git a/voxygen/anim/src/quadruped_medium/dash.rs b/voxygen/anim/src/quadruped_medium/dash.rs index 08d3aba41d..b467e5a766 100644 --- a/voxygen/anim/src/quadruped_medium/dash.rs +++ b/voxygen/anim/src/quadruped_medium/dash.rs @@ -49,13 +49,13 @@ impl Animation for DashAnimation { let legtwitch = (legtell * 6.0).sin() * pullback; let legswing = legtell * pullback; let short = (((1.0) - / (0.72 + 0.28 * ((anim_time as f32 * 16.0 as f32 + PI * 0.25).sin()).powi(2))) + / (0.72 + 0.28 * ((anim_time as f32 * 16.0_f32 + PI * 0.25).sin()).powi(2))) .sqrt()) - * ((anim_time as f32 * 16.0 as f32 + PI * 0.25).sin()) + * ((anim_time as f32 * 16.0_f32 + PI * 0.25).sin()) * chargemovementbase * pullback; let shortalt = - (anim_time as f32 * 16.0 as f32 + PI * 0.25).sin() * chargemovementbase * pullback; + (anim_time as f32 * 16.0_f32 + PI * 0.25).sin() * chargemovementbase * pullback; next.head.orientation = Quaternion::rotation_x(movement1abs * -0.2 + movement2abs * 0.8) * Quaternion::rotation_z(short * -0.06 + twitch1 * 0.2); diff --git a/voxygen/src/audio/sfx/event_mapper/combat/tests.rs b/voxygen/src/audio/sfx/event_mapper/combat/tests.rs index 8793381422..677d942164 100644 --- a/voxygen/src/audio/sfx/event_mapper/combat/tests.rs +++ b/voxygen/src/audio/sfx/event_mapper/combat/tests.rs @@ -8,16 +8,17 @@ use std::time::{Duration, Instant}; #[test] fn maps_wield_while_equipping() { - let mut loadout = Loadout::default(); - - loadout.active_item = Some(ItemConfig { - item: Item::new_from_asset_expect("common.items.weapons.axe.starter_axe"), - ability1: None, - ability2: None, - ability3: None, - block_ability: None, - dodge_ability: None, - }); + let loadout = Loadout { + active_item: Some(ItemConfig { + item: Item::new_from_asset_expect("common.items.weapons.axe.starter_axe"), + ability1: None, + ability2: None, + ability3: None, + block_ability: None, + dodge_ability: None, + }), + ..Default::default() + }; let result = CombatEventMapper::map_event( &CharacterState::Equipping(states::equipping::Data { @@ -39,16 +40,17 @@ fn maps_wield_while_equipping() { #[test] fn maps_unwield() { - let mut loadout = Loadout::default(); - - loadout.active_item = Some(ItemConfig { - item: Item::new_from_asset_expect("common.items.weapons.bow.starter_bow"), - ability1: None, - ability2: None, - ability3: None, - block_ability: None, - dodge_ability: None, - }); + let loadout = Loadout { + active_item: Some(ItemConfig { + item: Item::new_from_asset_expect("common.items.weapons.bow.starter_bow"), + ability1: None, + ability2: None, + ability3: None, + block_ability: None, + dodge_ability: None, + }), + ..Default::default() + }; let result = CombatEventMapper::map_event( &CharacterState::default(), @@ -65,16 +67,17 @@ fn maps_unwield() { #[test] fn maps_basic_melee() { - let mut loadout = Loadout::default(); - - loadout.active_item = Some(ItemConfig { - item: Item::new_from_asset_expect("common.items.weapons.axe.starter_axe"), - ability1: None, - ability2: None, - ability3: None, - block_ability: None, - dodge_ability: None, - }); + let loadout = Loadout { + active_item: Some(ItemConfig { + item: Item::new_from_asset_expect("common.items.weapons.axe.starter_axe"), + ability1: None, + ability2: None, + ability3: None, + block_ability: None, + dodge_ability: None, + }), + ..Default::default() + }; let result = CombatEventMapper::map_event( &CharacterState::BasicMelee(states::basic_melee::Data { @@ -108,16 +111,17 @@ fn maps_basic_melee() { #[test] fn matches_ability_stage() { - let mut loadout = Loadout::default(); - - loadout.active_item = Some(ItemConfig { - item: Item::new_from_asset_expect("common.items.weapons.sword.starter_sword"), - ability1: None, - ability2: None, - ability3: None, - block_ability: None, - dodge_ability: None, - }); + let loadout = Loadout { + active_item: Some(ItemConfig { + item: Item::new_from_asset_expect("common.items.weapons.sword.starter_sword"), + ability1: None, + ability2: None, + ability3: None, + block_ability: None, + dodge_ability: None, + }), + ..Default::default() + }; let result = CombatEventMapper::map_event( &CharacterState::ComboMelee(states::combo_melee::Data { @@ -169,16 +173,17 @@ fn matches_ability_stage() { #[test] fn ignores_different_ability_stage() { - let mut loadout = Loadout::default(); - - loadout.active_item = Some(ItemConfig { - item: Item::new_from_asset_expect("common.items.weapons.sword.starter_sword"), - ability1: None, - ability2: None, - ability3: None, - block_ability: None, - dodge_ability: None, - }); + let loadout = Loadout { + active_item: Some(ItemConfig { + item: Item::new_from_asset_expect("common.items.weapons.sword.starter_sword"), + ability1: None, + ability2: None, + ability3: None, + block_ability: None, + dodge_ability: None, + }), + ..Default::default() + }; let result = CombatEventMapper::map_event( &CharacterState::ComboMelee(states::combo_melee::Data { diff --git a/voxygen/src/hud/group.rs b/voxygen/src/hud/group.rs index 57ee603e79..d1df7e783d 100644 --- a/voxygen/src/hud/group.rs +++ b/voxygen/src/hud/group.rs @@ -391,8 +391,8 @@ impl<'a> Widget for Group<'a> { // Health Text let txt = format!( "{}/{}", - health.current() / 10 as u32, - health.maximum() / 10 as u32, + health.current() / 10_u32, + health.maximum() / 10_u32, ); // Change font size depending on health amount let font_size = match health.maximum() { diff --git a/voxygen/src/hud/hotbar.rs b/voxygen/src/hud/hotbar.rs index d055b0c284..1fbe84b101 100644 --- a/voxygen/src/hud/hotbar.rs +++ b/voxygen/src/hud/hotbar.rs @@ -80,17 +80,17 @@ impl State { ItemKind, }; if let ItemKind::Tool(kind) = kind { - match &kind.kind { - ToolKind::Staff => true, - ToolKind::Debug => true, - ToolKind::Sword => true, - ToolKind::Hammer => true, - ToolKind::Axe => true, - ToolKind::Bow => true, - ToolKind::Unique(UniqueKind::QuadMedQuick) => true, - ToolKind::Unique(UniqueKind::QuadLowBreathe) => true, - _ => false, - } + matches!( + &kind.kind, + ToolKind::Staff + | ToolKind::Debug + | ToolKind::Sword + | ToolKind::Hammer + | ToolKind::Axe + | ToolKind::Bow + | ToolKind::Unique(UniqueKind::QuadMedQuick) + | ToolKind::Unique(UniqueKind::QuadLowBreathe) + ) } else { false } diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index 1da67e06f1..3f97949fdb 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -2519,20 +2519,16 @@ impl Hud { // If not showing the ui don't allow keys that change the ui state but do listen for // hotbar keys - event if !self.show.ui => { - if let WinEvent::InputUpdate(key, state) = event { - if let Some(slot) = try_hotbar_slot_from_input(key) { - handle_slot( - slot, - state, - &mut self.events, - &mut self.slot_manager, - &mut self.hotbar, - ); - true - } else { - false - } + WinEvent::InputUpdate(key, state) if !self.show.ui => { + if let Some(slot) = try_hotbar_slot_from_input(key) { + handle_slot( + slot, + state, + &mut self.events, + &mut self.slot_manager, + &mut self.hotbar, + ); + true } else { false } @@ -2660,15 +2656,15 @@ 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}; - matches!(event, - /* event::Event::Raw(event::Input::Press(input::Button::Keyboard(input::Key::Tab))) | */ - event::Event::Ui(event::Ui::Press( - _, - event::Press { - button: event::Button::Keyboard(input::Key::Tab), - .. - }, - ))) + matches!( + event, + /* event::Event::Raw(event::Input::Press(input::Button::Keyboard(input::Key:: + * Tab))) | */ + event::Event::Ui(event::Ui::Press(_, event::Press { + button: event::Button::Keyboard(input::Key::Tab), + .. + },)) + ) }) { self.ui .ui diff --git a/voxygen/src/main.rs b/voxygen/src/main.rs index 1181d4ed87..8c564768fb 100644 --- a/voxygen/src/main.rs +++ b/voxygen/src/main.rs @@ -21,6 +21,7 @@ use common::{ use std::panic; use tracing::{error, info, warn}; +#[allow(clippy::manual_unwrap_or)] fn main() { // Load the settings // Note: This won't log anything due to it being called before diff --git a/voxygen/src/menu/main/ui/mod.rs b/voxygen/src/menu/main/ui/mod.rs index 6852b1f210..18c5d42505 100644 --- a/voxygen/src/menu/main/ui/mod.rs +++ b/voxygen/src/menu/main/ui/mod.rs @@ -263,7 +263,7 @@ impl Controls { .padding(3) .width(Length::Fill); - let bg_img = if matches!(&self.screen, Screen::Connecting {..}) { + let bg_img = if matches!(&self.screen, Screen::Connecting { .. }) { self.bg_img } else { self.imgs.bg @@ -333,7 +333,7 @@ impl Controls { }; }, Message::ShowServers => { - if matches!(&self.screen, Screen::Login {..}) { + if matches!(&self.screen, Screen::Login { .. }) { self.selected_server_index = servers.iter().position(|f| f == &self.login_info.server); self.screen = Screen::Servers { @@ -418,7 +418,7 @@ impl Controls { // Connection successful of failed fn exit_connect_screen(&mut self) { - if matches!(&self.screen, Screen::Connecting {..}) { + if matches!(&self.screen, Screen::Connecting { .. }) { self.screen = Screen::Login { screen: login::Screen::new(), error: None, @@ -444,7 +444,7 @@ impl Controls { } fn connection_error(&mut self, error: String) { - if matches!(&self.screen, Screen::Connecting {..}) { + if matches!(&self.screen, Screen::Connecting { .. }) { self.screen = Screen::Login { screen: login::Screen::new(), error: Some(error), diff --git a/voxygen/src/mesh/greedy.rs b/voxygen/src/mesh/greedy.rs index ebbaed7c93..46d13141fa 100644 --- a/voxygen/src/mesh/greedy.rs +++ b/voxygen/src/mesh/greedy.rs @@ -234,7 +234,7 @@ where let pos = Vec3::new(pos.z, pos.x, pos.y); let uv = Vec2::new(Vec3::unit_y(), Vec3::unit_z()); let norm = Vec3::unit_x(); - let atlas_pos = if let Some(atlas_pos) = add_to_atlas( + let atlas_pos = add_to_atlas( atlas, &mut todo_rects, pos, @@ -244,11 +244,7 @@ where faces_forward, max_size, col_lights_size, - ) { - atlas_pos - } else { - return; - }; + ); create_quad_greedy( pos, dim, @@ -279,7 +275,7 @@ where let pos = Vec3::new(pos.y, pos.z, pos.x); let uv = Vec2::new(Vec3::unit_z(), Vec3::unit_x()); let norm = Vec3::unit_y(); - let atlas_pos = if let Some(atlas_pos) = add_to_atlas( + let atlas_pos = add_to_atlas( atlas, &mut todo_rects, pos, @@ -289,11 +285,7 @@ where faces_forward, max_size, col_lights_size, - ) { - atlas_pos - } else { - return; - }; + ); create_quad_greedy( pos, dim, @@ -324,7 +316,7 @@ where let pos = Vec3::new(pos.x, pos.y, pos.z); let uv = Vec2::new(Vec3::unit_x(), Vec3::unit_y()); let norm = Vec3::unit_z(); - let atlas_pos = if let Some(atlas_pos) = add_to_atlas( + let atlas_pos = add_to_atlas( atlas, &mut todo_rects, pos, @@ -334,11 +326,7 @@ where faces_forward, max_size, col_lights_size, - ) { - atlas_pos - } else { - return; - }; + ); create_quad_greedy( pos, dim, @@ -444,7 +432,7 @@ fn add_to_atlas( faces_forward: bool, max_size: guillotiere::Size, cur_size: &mut Vec2, -) -> Option { +) -> guillotiere::Rectangle { // TODO: Check this conversion. let atlas_rect; loop { @@ -502,7 +490,7 @@ fn add_to_atlas( atlas_rect, if faces_forward { norm } else { -norm }, )); - Some(atlas_rect) + atlas_rect } /// We deferred actually recording the colors within the rectangles in order to diff --git a/voxygen/src/mesh/terrain.rs b/voxygen/src/mesh/terrain.rs index 664094e5af..242ee59fed 100644 --- a/voxygen/src/mesh/terrain.rs +++ b/voxygen/src/mesh/terrain.rs @@ -265,8 +265,6 @@ impl<'a, V: RectRasterableVol + ReadVol + Debug + 'static> #[allow(clippy::many_single_char_names)] #[allow(clippy::needless_range_loop)] // TODO: Pending review in #587 #[allow(clippy::or_fun_call)] // TODO: Pending review in #587 - #[allow(clippy::panic_params)] // TODO: Pending review in #587 - fn generate_mesh( self, (range, max_texture_size, _boi): Self::Supplement, diff --git a/voxygen/src/render/texture.rs b/voxygen/src/render/texture.rs index 1c4cb1fa50..cbf5468251 100644 --- a/voxygen/src/render/texture.rs +++ b/voxygen/src/render/texture.rs @@ -79,7 +79,7 @@ where height, gfx::texture::AaMode::Single, ), - 1 as gfx::texture::Level, + 1_u8, gfx::memory::Bind::SHADER_RESOURCE, gfx::memory::Usage::Dynamic, Some(<::Channel as gfx::format::ChannelTyped>::get_channel_type()), diff --git a/voxygen/src/scene/figure/mod.rs b/voxygen/src/scene/figure/mod.rs index f8083bd871..ec5ed16189 100644 --- a/voxygen/src/scene/figure/mod.rs +++ b/voxygen/src/scene/figure/mod.rs @@ -3693,6 +3693,7 @@ impl FigureColLights { }) } + #[allow(clippy::unnecessary_wraps)] fn make_atlas(renderer: &mut Renderer) -> Result { let max_texture_size = renderer.max_texture_size(); let atlas_size = diff --git a/voxygen/src/scene/terrain.rs b/voxygen/src/scene/terrain.rs index 9f6ca7c6b5..bb4e1bc8e9 100644 --- a/voxygen/src/scene/terrain.rs +++ b/voxygen/src/scene/terrain.rs @@ -433,7 +433,7 @@ impl Terrain { max_texture_size, gfx::texture::AaMode::Single, ), - 1 as gfx::texture::Level, + 1_u8, gfx::memory::Bind::SHADER_RESOURCE, gfx::memory::Usage::Dynamic, (0, 0), diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index d19dc53712..8b98dbf25d 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -927,10 +927,8 @@ impl PlayState for SessionState { HudEvent::DropSlot(x) => { let mut client = self.client.borrow_mut(); client.drop_slot(x); - if let comp::slot::Slot::Equip(equip_slot) = x { - if let comp::slot::EquipSlot::Lantern = equip_slot { - client.disable_lantern(); - } + if let comp::slot::Slot::Equip(comp::slot::EquipSlot::Lantern) = x { + client.disable_lantern(); } }, HudEvent::ChangeHotbarState(state) => { diff --git a/voxygen/src/ui/event.rs b/voxygen/src/ui/event.rs index 56bc07e2a8..fa26c03eb4 100644 --- a/voxygen/src/ui/event.rs +++ b/voxygen/src/ui/event.rs @@ -30,19 +30,23 @@ impl Event { } pub fn is_keyboard_or_mouse(&self) -> bool { - matches!(self.0, + matches!( + self.0, Input::Press(_) - | Input::Release(_) - | Input::Motion(_) - | Input::Touch(_) - | Input::Text(_)) + | Input::Release(_) + | Input::Motion(_) + | Input::Touch(_) + | Input::Text(_) + ) } pub fn is_keyboard(&self) -> bool { - matches!(self.0, + matches!( + self.0, Input::Press(Button::Keyboard(_)) - | Input::Release(Button::Keyboard(_)) - | Input::Text(_)) + | Input::Release(Button::Keyboard(_)) + | Input::Text(_) + ) } pub fn new_resize(dims: Vec2) -> Self { Self(Input::Resize(dims.x, dims.y)) } diff --git a/world/src/lib.rs b/world/src/lib.rs index c36ebed098..6529a27443 100644 --- a/world/src/lib.rs +++ b/world/src/lib.rs @@ -145,6 +145,7 @@ impl World { #[allow(clippy::or_fun_call)] // TODO: Pending review in #587 #[allow(clippy::eval_order_dependence)] + #[allow(clippy::result_unit_err)] pub fn generate_chunk( &self, index: IndexRef, diff --git a/world/src/sim/erosion.rs b/world/src/sim/erosion.rs index aed89171d0..37f376078c 100644 --- a/world/src/sim/erosion.rs +++ b/world/src/sim/erosion.rs @@ -995,14 +995,15 @@ fn erode( debug!("Computed stream power factors..."); - let mut lake_water_volume = vec![0.0 as Compute; map_size_lg.chunks_len()].into_boxed_slice(); - let mut elev = vec![0.0 as Compute; map_size_lg.chunks_len()].into_boxed_slice(); - let mut h_p = vec![0.0 as Compute; map_size_lg.chunks_len()].into_boxed_slice(); - let mut deltah = vec![0.0 as Compute; map_size_lg.chunks_len()].into_boxed_slice(); + let mut lake_water_volume: Box<[Compute]> = + vec![0.0_f64; map_size_lg.chunks_len()].into_boxed_slice(); + let mut elev: Box<[Compute]> = vec![0_f64; map_size_lg.chunks_len()].into_boxed_slice(); + let mut h_p: Box<[Compute]> = vec![0_f64; map_size_lg.chunks_len()].into_boxed_slice(); + let mut deltah: Box<[Compute]> = vec![0_f64; map_size_lg.chunks_len()].into_boxed_slice(); // calculate the elevation / SPL, including sediment flux - let tol1 = 1.0e-4 as Compute * (maxh as Compute + 1.0); - let tol2 = 1.0e-3 as Compute * (max_uplift as Compute + 1.0); + let tol1: Compute = 1.0e-4_f64 * (maxh as Compute + 1.0); + let tol2: Compute = 1.0e-3_f64 * (max_uplift as Compute + 1.0); let tol = tol1.max(tol2); let mut err = 2.0 * tol; @@ -1032,7 +1033,7 @@ fn erode( // Gauss-Seidel iteration - let mut lake_silt = vec![0.0 as Compute; map_size_lg.chunks_len()].into_boxed_slice(); + let mut lake_silt: Box<[Compute]> = vec![0.0_f64; map_size_lg.chunks_len()].into_boxed_slice(); let mut lake_sill = vec![-1isize; map_size_lg.chunks_len()].into_boxed_slice(); let mut n_gs_stream_power_law = 0; @@ -1219,7 +1220,7 @@ fn erode( let start_time = Instant::now(); // TODO: Consider taking advantage of multi-receiver flow here. // Iterate in ascending height order. - let mut sum_err = 0.0 as Compute; + let mut sum_err: Compute = 0.0_f64; itertools::izip!(&*mstack, &*elev, &*b_stack, &*h_t_stack, &*dh_stack, &*h_p) .enumerate() .rev() diff --git a/world/src/sim/util.rs b/world/src/sim/util.rs index 763a63e09c..f4ed9ef16c 100644 --- a/world/src/sim/util.rs +++ b/world/src/sim/util.rs @@ -366,6 +366,7 @@ pub fn get_oceans(map_size_lg: MapSizeLg, oldh: impl Fn(usize) -> F + } /// Finds the horizon map for sunlight for the given chunks. +#[allow(clippy::result_unit_err)] pub fn get_horizon_map( map_size_lg: MapSizeLg, bounds: Aabr, diff --git a/world/src/site/dungeon/mod.rs b/world/src/site/dungeon/mod.rs index 87b5098cd5..47aa2ac104 100644 --- a/world/src/site/dungeon/mod.rs +++ b/world/src/site/dungeon/mod.rs @@ -224,13 +224,10 @@ pub enum Tile { impl Tile { fn is_passable(&self) -> bool { - match self { - Tile::UpStair(_) => true, - Tile::DownStair(_) => true, - Tile::Room(_) => true, - Tile::Tunnel => true, - _ => false, - } + matches!( + self, + Tile::UpStair(_) | Tile::DownStair(_) | Tile::Room(_) | Tile::Tunnel + ) } } diff --git a/world/src/site/settlement/mod.rs b/world/src/site/settlement/mod.rs index 8add7e55fb..c5bfbf9bd3 100644 --- a/world/src/site/settlement/mod.rs +++ b/world/src/site/settlement/mod.rs @@ -294,10 +294,8 @@ impl Settlement { let mut origin = Vec2::new(ctx.rng.gen_range(-2, 3), ctx.rng.gen_range(-2, 3)); for i in 0..PLOT_COUNT { - if let Some(base_tile) = self.land.find_tile_near(origin, |plot| match plot { - Some(Plot::Field { .. }) => true, - Some(Plot::Dirt) => true, - _ => false, + if let Some(base_tile) = self.land.find_tile_near(origin, |plot| { + matches!(plot, Some(Plot::Field { .. }) | Some(Plot::Dirt)) }) { // self.land // .plot_at_mut(base_tile)