From ac1dad12df93ad67e9e039c1ab904ff96d251f49 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 28 Jun 2020 17:45:15 -0700 Subject: [PATCH 01/49] blocks: fix redundant_field_names cat src/lib.rs|perl -pe's/\b(\w+): \1\b/$1/g'|sponge src/lib.rs --- blocks/src/lib.rs | 74 +++++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/blocks/src/lib.rs b/blocks/src/lib.rs index b5bcda8..3cdf30e 100644 --- a/blocks/src/lib.rs +++ b/blocks/src/lib.rs @@ -570,9 +570,9 @@ define_blocks! { } }, update_state (world, pos) => if variant == DirtVariant::Podzol { - Block::Dirt{snowy: is_snowy(world, pos), variant: variant} + Block::Dirt{snowy: is_snowy(world, pos), variant} } else { - Block::Dirt{snowy: snowy, variant: variant} + Block::Dirt{snowy, variant} }, } Cobblestone { @@ -1337,7 +1337,7 @@ define_blocks! { collision vec![], update_state (world, pos) => { Fire{ - age: age, + age, up: can_burn(world, pos.shift(Direction::Up)), north: can_burn(world, pos.shift(Direction::North)), south: can_burn(world, pos.shift(Direction::South)), @@ -1438,7 +1438,7 @@ define_blocks! { south: can_connect_redstone(world, pos, Direction::South), west: can_connect_redstone(world, pos, Direction::West), east: can_connect_redstone(world, pos, Direction::East), - power: power + power }, multipart (key, val) => match key { "north" => val.contains(north.as_string()), @@ -1565,7 +1565,7 @@ define_blocks! { collision door_collision(facing, hinge, open), update_state (world, pos) => { let (facing, hinge, open, powered) = update_door_state(world, pos, half, facing, hinge, open, powered); - Block::WoodenDoor{facing: facing, half: half, hinge: hinge, open: open, powered: powered} + Block::WoodenDoor{facing, half, hinge, open, powered} }, } Ladder { @@ -1702,7 +1702,7 @@ define_blocks! { collision door_collision(facing, hinge, open), update_state (world, pos) => { let (facing, hinge, open, powered) = update_door_state(world, pos, half, facing, hinge, open, powered); - Block::IronDoor{facing: facing, half: half, hinge: hinge, open: open, powered: powered} + Block::IronDoor{facing, half, hinge, open, powered} }, } WoodenPressurePlate { @@ -2088,7 +2088,7 @@ define_blocks! { Point3::new(0.0, 0.0, 0.0), Point3::new(1.0, 1.0/8.0, 1.0) )], - update_state (world, pos) => RepeaterPowered{delay: delay, facing: facing, locked: update_repeater_state(world, pos, facing)}, + update_state (world, pos) => RepeaterPowered{delay, facing, locked: update_repeater_state(world, pos, facing)}, } StainedGlass { props { @@ -2380,7 +2380,7 @@ define_blocks! { _ => Direction::Up, }; - Block::PumpkinStem{age: age, facing: facing} + Block::PumpkinStem{age, facing} }, } MelonStem { @@ -2416,7 +2416,7 @@ define_blocks! { _ => Direction::Up, }; - Block::MelonStem{age: age, facing: facing} + Block::MelonStem{age, facing} }, } Vine { @@ -2448,7 +2448,7 @@ define_blocks! { update_state (world, pos) => { let mat = world.get_block(pos.shift(Direction::Up)).get_material(); let up = mat.renderable && (mat.should_cull_against || mat.never_cull /* Because leaves */); - Vine{up: up, south: south, west: west, north: north, east: east} + Vine{up, south, west, north, east} }, } FenceGate { @@ -2470,10 +2470,10 @@ define_blocks! { variant format!("facing={},in_wall={},open={}", facing.as_string(), in_wall, open), collision fence_gate_collision(facing, in_wall, open), update_state (world, pos) => Block::FenceGate{ - facing: facing, + facing, in_wall: fence_gate_update_state(world, pos, facing), - open: open, - powered: powered + open, + powered }, } BrickStairs { @@ -2930,14 +2930,14 @@ define_blocks! { }; Tripwire{ - powered: powered, - attached: attached, - disarmed: disarmed, + powered, + attached, + disarmed, north: f(Direction::North), south: f(Direction::South), west: f(Direction::West), east: f(Direction::East), - mojang_cant_even: mojang_cant_even + mojang_cant_even } }, } @@ -4206,10 +4206,10 @@ define_blocks! { variant format!("facing={},in_wall={},open={}", facing.as_string(), in_wall, open), collision fence_gate_collision(facing, in_wall, open), update_state (world, pos) => Block::SpruceFenceGate{ - facing: facing, + facing, in_wall: fence_gate_update_state(world, pos, facing), - open: open, - powered: powered + open, + powered }, } BirchFenceGate { @@ -4231,10 +4231,10 @@ define_blocks! { variant format!("facing={},in_wall={},open={}", facing.as_string(), in_wall, open), collision fence_gate_collision(facing, in_wall, open), update_state (world, pos) => Block::BirchFenceGate{ - facing: facing, + facing, in_wall: fence_gate_update_state(world, pos, facing), - open: open, - powered: powered + open, + powered }, } JungleFenceGate { @@ -4256,10 +4256,10 @@ define_blocks! { variant format!("facing={},in_wall={},open={}", facing.as_string(), in_wall, open), collision fence_gate_collision(facing, in_wall, open), update_state (world, pos) => Block::JungleFenceGate{ - facing: facing, + facing, in_wall: fence_gate_update_state(world, pos, facing), - open: open, - powered: powered + open, + powered }, } DarkOakFenceGate { @@ -4281,10 +4281,10 @@ define_blocks! { variant format!("facing={},in_wall={},open={}", facing.as_string(), in_wall, open), collision fence_gate_collision(facing, in_wall, open), update_state (world, pos) => Block::DarkOakFenceGate{ - facing: facing, + facing, in_wall: fence_gate_update_state(world, pos, facing), - open: open, - powered: powered + open, + powered }, } AcaciaFenceGate { @@ -4306,10 +4306,10 @@ define_blocks! { variant format!("facing={},in_wall={},open={}", facing.as_string(), in_wall, open), collision fence_gate_collision(facing, in_wall, open), update_state (world, pos) => Block::AcaciaFenceGate{ - facing: facing, + facing, in_wall: fence_gate_update_state(world, pos, facing), - open: open, - powered: powered + open, + powered }, } SpruceFence { @@ -4478,7 +4478,7 @@ define_blocks! { collision door_collision(facing, hinge, open), update_state (world, pos) => { let (facing, hinge, open, powered) = update_door_state(world, pos, half, facing, hinge, open, powered); - Block::SpruceDoor{facing: facing, half: half, hinge: hinge, open: open, powered: powered} + Block::SpruceDoor{facing, half, hinge, open, powered} }, } BirchDoor { @@ -4502,7 +4502,7 @@ define_blocks! { collision door_collision(facing, hinge, open), update_state (world, pos) => { let (facing, hinge, open, powered) = update_door_state(world, pos, half, facing, hinge, open, powered); - Block::BirchDoor{facing: facing, half: half, hinge: hinge, open: open, powered: powered} + Block::BirchDoor{facing, half, hinge, open, powered} }, } JungleDoor { @@ -4526,7 +4526,7 @@ define_blocks! { collision door_collision(facing, hinge, open), update_state (world, pos) => { let (facing, hinge, open, powered) = update_door_state(world, pos, half, facing, hinge, open, powered); - Block::JungleDoor{facing: facing, half: half, hinge: hinge, open: open, powered: powered} + Block::JungleDoor{facing, half, hinge, open, powered} }, } AcaciaDoor { @@ -4550,7 +4550,7 @@ define_blocks! { collision door_collision(facing, hinge, open), update_state (world, pos) => { let (facing, hinge, open, powered) = update_door_state(world, pos, half, facing, hinge, open, powered); - Block::AcaciaDoor{facing: facing, half: half, hinge: hinge, open: open, powered: powered} + Block::AcaciaDoor{facing, half, hinge, open, powered} }, } DarkOakDoor { @@ -4574,7 +4574,7 @@ define_blocks! { collision door_collision(facing, hinge, open), update_state (world, pos) => { let (facing, hinge, open, powered) = update_door_state(world, pos, half, facing, hinge, open, powered); - Block::DarkOakDoor{facing: facing, half: half, hinge: hinge, open: open, powered: powered} + Block::DarkOakDoor{facing, half, hinge, open, powered} }, } EndRod { From 842b4d8a5412926083482afe5c37c208b3ba7f39 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 28 Jun 2020 17:46:49 -0700 Subject: [PATCH 02/49] blocks: fix missing panic_params in TreeVariant --- blocks/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/blocks/src/lib.rs b/blocks/src/lib.rs index 3cdf30e..becf3d8 100644 --- a/blocks/src/lib.rs +++ b/blocks/src/lib.rs @@ -7264,7 +7264,7 @@ impl TreeVariant { TreeVariant::Spruce | TreeVariant::DarkOak => 1, TreeVariant::Birch => 2, TreeVariant::Jungle => 3, - _ => panic!("TreeVariant {:?} has no data (1.13+ only)"), + _ => panic!("TreeVariant {:?} has no data (1.13+ only)", self), } } @@ -7293,7 +7293,7 @@ impl TreeVariant { TreeVariant::Jungle => 3, TreeVariant::Acacia => 4, TreeVariant::DarkOak => 5, - _ => panic!("TreeVariant {:?} has no plank data (1.13+ only)"), + _ => panic!("TreeVariant {:?} has no plank data (1.13+ only)", self), } } } From f69b27ce74b08b29fe49bbc0e8ba21b29a825e5d Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 28 Jun 2020 17:48:18 -0700 Subject: [PATCH 03/49] blocks: allow clippy::identity_op because 1 << 0 is self-documenting bitfield --- blocks/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/blocks/src/lib.rs b/blocks/src/lib.rs index becf3d8..4d73e96 100644 --- a/blocks/src/lib.rs +++ b/blocks/src/lib.rs @@ -1,4 +1,5 @@ #![recursion_limit = "600"] +#![allow(clippy::identity_op)] extern crate steven_shared as shared; From d9a7015dc8a9aa7266669ab2e591966dba34325f Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 28 Jun 2020 17:49:07 -0700 Subject: [PATCH 04/49] blocks: fix useless_format, use .as_string() --- blocks/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blocks/src/lib.rs b/blocks/src/lib.rs index 4d73e96..b97f1b8 100644 --- a/blocks/src/lib.rs +++ b/blocks/src/lib.rs @@ -2223,7 +2223,7 @@ define_blocks! { data None::, offset mushroom_block_offset(false, west, up, south, north, east, down), model { ("minecraft", "mushroom_stem") }, - variant format!("variant=all_stem"), + variant "variant=all_stem".to_string(), } IronBars { props { From c255edd94423f55bd33436b491361aaee6a03561 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 28 Jun 2020 17:50:55 -0700 Subject: [PATCH 05/49] blocks: allow clippy::collapsible_if, represents data flow --- blocks/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/blocks/src/lib.rs b/blocks/src/lib.rs index b97f1b8..e689ad6 100644 --- a/blocks/src/lib.rs +++ b/blocks/src/lib.rs @@ -1,5 +1,6 @@ #![recursion_limit = "600"] #![allow(clippy::identity_op)] +#![allow(clippy::collapsible_if)] extern crate steven_shared as shared; From d64316e8c8bbe7e3f799e478429cdf66a7e06c9e Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 28 Jun 2020 18:14:09 -0700 Subject: [PATCH 06/49] blocks: fix clippy::precedence use + not | --- blocks/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blocks/src/lib.rs b/blocks/src/lib.rs index e689ad6..850b122 100644 --- a/blocks/src/lib.rs +++ b/blocks/src/lib.rs @@ -776,7 +776,7 @@ define_blocks! { offset if check_decay { None } else { - Some(variant.offset() * (7 * 2) + ((distance as usize - 1) << 1) | (if decayable { 0 } else { 1 })) + Some(variant.offset() * (7 * 2) + ((distance as usize - 1) << 1) + (if decayable { 0 } else { 1 })) }, material material::LEAVES, model { ("minecraft", format!("{}_leaves", variant.as_string()) ) }, From 6747ae176e72bce12b8d5ca94b05c386ed3c2bd1 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 28 Jun 2020 18:24:28 -0700 Subject: [PATCH 07/49] blocks: fix redundant_field_names in macro --- blocks/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/blocks/src/lib.rs b/blocks/src/lib.rs index 850b122..64f0551 100644 --- a/blocks/src/lib.rs +++ b/blocks/src/lib.rs @@ -263,7 +263,7 @@ macro_rules! define_blocks { return $update_state; )? Block::$name { - $($fname: $fname,)? + $($fname,)? } } )+ @@ -378,7 +378,7 @@ macro_rules! define_blocks { $($fname: $fname.next().unwrap(),)? }, state: CombinationIterState { - $($fname: $fname,)? + $($fname,)? } } } From 9621b235c4bfdff705c74133e262e042e39794e1 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 28 Jun 2020 18:26:52 -0700 Subject: [PATCH 08/49] protocol: fix redundant imports, single_component_path_imports --- protocol/src/format.rs | 1 - protocol/src/protocol/mod.rs | 3 --- protocol/src/protocol/mojang.rs | 1 - 3 files changed, 5 deletions(-) diff --git a/protocol/src/format.rs b/protocol/src/format.rs index 55cd4e2..49dfb46 100644 --- a/protocol/src/format.rs +++ b/protocol/src/format.rs @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -use serde_json; use std::fmt; use std::mem; diff --git a/protocol/src/protocol/mod.rs b/protocol/src/protocol/mod.rs index 62d0acf..1d1cff6 100644 --- a/protocol/src/protocol/mod.rs +++ b/protocol/src/protocol/mod.rs @@ -18,10 +18,7 @@ use aes::Aes128; use cfb8::stream_cipher::{NewStreamCipher, StreamCipher}; use cfb8::Cfb8; -use hex; #[cfg(not(target_arch = "wasm32"))] -use reqwest; -use serde_json; use std_or_web::fs; pub mod forge; diff --git a/protocol/src/protocol/mojang.rs b/protocol/src/protocol/mojang.rs index ebfd55b..2e764f4 100644 --- a/protocol/src/protocol/mojang.rs +++ b/protocol/src/protocol/mojang.rs @@ -13,7 +13,6 @@ // limitations under the License. #[cfg(not(target_arch = "wasm32"))] -use reqwest; use serde_json::json; use sha1::{self, Digest}; From 853f76b24a64ee334d407bad079bec4a908ae799 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 28 Jun 2020 18:27:30 -0700 Subject: [PATCH 09/49] protocol: fix redundant_static_lifetimes --- protocol/src/protocol/forge.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/protocol/src/protocol/forge.rs b/protocol/src/protocol/forge.rs index f9526e4..4dd9253 100644 --- a/protocol/src/protocol/forge.rs +++ b/protocol/src/protocol/forge.rs @@ -84,8 +84,8 @@ impl Serializable for ModIdMapping { } } -pub static BLOCK_NAMESPACE: &'static str = "\u{1}"; -pub static ITEM_NAMESPACE: &'static str = "\u{2}"; +pub static BLOCK_NAMESPACE: &str = "\u{1}"; +pub static ITEM_NAMESPACE: &str = "\u{2}"; #[derive(Debug)] pub enum FmlHs { From 07fed441f31e80702626f9322953c125898a10cc Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 28 Jun 2020 18:28:09 -0700 Subject: [PATCH 10/49] protocol: fix redundant_field_names --- protocol/src/protocol/packet.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protocol/src/protocol/packet.rs b/protocol/src/protocol/packet.rs index 39cddc8..365e38f 100644 --- a/protocol/src/protocol/packet.rs +++ b/protocol/src/protocol/packet.rs @@ -2569,7 +2569,7 @@ impl Serializable for PlayerInfoData { } }, }), - 4 => m.players.push(PlayerDetail::Remove { uuid: uuid }), + 4 => m.players.push(PlayerDetail::Remove { uuid }), _ => panic!(), } } From 77394f0536ed8b29e930bb5109a082957a6cea4d Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 28 Jun 2020 18:33:32 -0700 Subject: [PATCH 11/49] protocol: use and_then, ok_or_else; option_map_or_none and or_fun_call --- protocol/src/format.rs | 12 ++++++------ protocol/src/protocol/mod.rs | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/protocol/src/format.rs b/protocol/src/format.rs index 49dfb46..534b2bf 100644 --- a/protocol/src/format.rs +++ b/protocol/src/format.rs @@ -95,14 +95,14 @@ pub struct Modifier { impl Modifier { pub fn from_value(v: &serde_json::Value) -> Self { let mut m = Modifier { - bold: v.get("bold").map_or(Option::None, |v| v.as_bool()), - italic: v.get("italic").map_or(Option::None, |v| v.as_bool()), - underlined: v.get("underlined").map_or(Option::None, |v| v.as_bool()), - strikethrough: v.get("strikethrough").map_or(Option::None, |v| v.as_bool()), - obfuscated: v.get("obfuscated").map_or(Option::None, |v| v.as_bool()), + bold: v.get("bold").and_then(|v| v.as_bool()), + italic: v.get("italic").and_then(|v| v.as_bool()), + underlined: v.get("underlined").and_then(|v| v.as_bool()), + strikethrough: v.get("strikethrough").and_then(|v| v.as_bool()), + obfuscated: v.get("obfuscated").and_then(|v| v.as_bool()), color: v .get("color") - .map_or(Option::None, |v| v.as_str()) + .and_then(|v| v.as_str()) .map(|v| Color::from_string(&v.to_owned())), extra: Option::None, }; diff --git a/protocol/src/protocol/mod.rs b/protocol/src/protocol/mod.rs index 1d1cff6..b6db693 100644 --- a/protocol/src/protocol/mod.rs +++ b/protocol/src/protocol/mod.rs @@ -1208,8 +1208,8 @@ impl Conn { let invalid_status = || Error::Err("Invalid status".to_owned()); - let version = val.get("version").ok_or(invalid_status())?; - let players = val.get("players").ok_or(invalid_status())?; + let version = val.get("version").ok_or_else(invalid_status)?; + let players = val.get("players").ok_or_else(invalid_status)?; // For modded servers, get the list of Forge mods installed let mut forge_mods: std::vec::Vec = vec![]; @@ -1264,26 +1264,26 @@ impl Conn { name: version .get("name") .and_then(Value::as_str) - .ok_or(invalid_status())? + .ok_or_else(invalid_status)? .to_owned(), protocol: version .get("protocol") .and_then(Value::as_i64) - .ok_or(invalid_status())? as i32, + .ok_or_else(invalid_status)? as i32, }, players: StatusPlayers { max: players .get("max") .and_then(Value::as_i64) - .ok_or(invalid_status())? as i32, + .ok_or_else(invalid_status)? as i32, online: players .get("online") .and_then(Value::as_i64) - .ok_or(invalid_status())? as i32, + .ok_or_else(invalid_status)? as i32, sample: Vec::new(), /* TODO */ }, description: format::Component::from_value( - val.get("description").ok_or(invalid_status())?, + val.get("description").ok_or_else(invalid_status)?, ), favicon: val .get("favicon") From 2f1c7b3c60e8babe8901a12dcf53ca0b1060c1bf Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 28 Jun 2020 18:34:42 -0700 Subject: [PATCH 12/49] protocol: fix redundant_clone in access token --- protocol/src/protocol/mojang.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protocol/src/protocol/mojang.rs b/protocol/src/protocol/mojang.rs index 2e764f4..8b7e50a 100644 --- a/protocol/src/protocol/mojang.rs +++ b/protocol/src/protocol/mojang.rs @@ -77,7 +77,7 @@ impl Profile { pub fn refresh(self, token: &str) -> Result { let req_msg = json!({ - "accessToken": self.access_token.clone(), + "accessToken": self.access_token, "clientToken": token }); let req = serde_json::to_string(&req_msg)?; From 72f0595111e980bf0fbcaf0225df45405eba729c Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 28 Jun 2020 18:36:16 -0700 Subject: [PATCH 13/49] protocol: fix wildcard_in_or_patterns --- protocol/src/format.rs | 3 ++- protocol/src/types/mod.rs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/protocol/src/format.rs b/protocol/src/format.rs index 534b2bf..281a407 100644 --- a/protocol/src/format.rs +++ b/protocol/src/format.rs @@ -245,7 +245,8 @@ impl Color { }; Color::RGB(r, g, b) } - "white" | _ => Color::White, + "white" => Color::White, + _ => Color::White, } } diff --git a/protocol/src/types/mod.rs b/protocol/src/types/mod.rs index dcde267..b2ceaac 100644 --- a/protocol/src/types/mod.rs +++ b/protocol/src/types/mod.rs @@ -33,7 +33,8 @@ impl Gamemode { 3 => Gamemode::Spectator, 2 => Gamemode::Adventure, 1 => Gamemode::Creative, - 0 | _ => Gamemode::Survival, + 0 => Gamemode::Survival, + _ => Gamemode::Survival, } } From 783e43739742cf3b3dc2f450ca887136bb29b706 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 28 Jun 2020 18:39:57 -0700 Subject: [PATCH 14/49] protocol: fix manually copying, use clone_from_slice, thanks clippy! (manual_memcpy) --- protocol/src/protocol/mod.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/protocol/src/protocol/mod.rs b/protocol/src/protocol/mod.rs index b6db693..241d9b5 100644 --- a/protocol/src/protocol/mod.rs +++ b/protocol/src/protocol/mod.rs @@ -1343,11 +1343,8 @@ impl Write for Conn { match self.cipher.as_mut() { Option::None => self.stream.write(buf), Option::Some(cipher) => { - // TODO: avoid copying, but trait requires non-mutable buf let mut data = vec![0; buf.len()]; - for i in 0..buf.len() { - data[i] = buf[i]; - } + data[..buf.len()].clone_from_slice(&buf[..]); cipher.encrypt(&mut data); From 66a787a5355544ceab314f1012c238e39e1d51a0 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Mon, 29 Jun 2020 17:33:50 -0700 Subject: [PATCH 15/49] protocol: change UUID from_str to implement FromStr trait (should_implement_trait) --- protocol/src/protocol/mod.rs | 20 +++++++++++++++----- src/server/mod.rs | 7 ++++--- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/protocol/src/protocol/mod.rs b/protocol/src/protocol/mod.rs index 241d9b5..a576a47 100644 --- a/protocol/src/protocol/mod.rs +++ b/protocol/src/protocol/mod.rs @@ -419,11 +419,21 @@ impl Serializable for f64 { #[derive(Debug, PartialEq, Eq, Hash, Clone)] pub struct UUID(u64, u64); -impl UUID { - pub fn from_str(s: &str) -> UUID { - // TODO: Panics aren't the best idea here +#[derive(Debug)] +pub struct UUIDParseError; +impl std::error::Error for UUIDParseError {} + +impl fmt::Display for UUIDParseError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "Invalid UUID format") + } +} + +impl std::str::FromStr for UUID { + type Err = UUIDParseError; + fn from_str(s: &str) -> Result { if s.len() != 36 { - panic!("Invalid UUID format"); + return Err(UUIDParseError {}); } let mut parts = hex::decode(&s[..8]).unwrap(); parts.extend_from_slice(&hex::decode(&s[9..13]).unwrap()); @@ -436,7 +446,7 @@ impl UUID { high |= (parts[i] as u64) << (56 - i * 8); low |= (parts[i + 8] as u64) << (56 - i * 8); } - UUID(high, low) + Ok(UUID(high, low)) } } diff --git a/src/server/mod.rs b/src/server/mod.rs index cb5064f..cbafead 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -32,6 +32,7 @@ use rsa_public_encrypt_pkcs1; use serde_json; use std::collections::HashMap; use std::hash::BuildHasherDefault; +use std::str::FromStr; use std::sync::mpsc; use std::sync::{Arc, RwLock}; use std::thread; @@ -158,7 +159,7 @@ impl Server { return Ok(Server::new( protocol_version, forge_mods, - protocol::UUID::from_str(&val.uuid), + protocol::UUID::from_str(&val.uuid).unwrap(), resources, Some(write), Some(rx), @@ -230,7 +231,7 @@ impl Server { } protocol::packet::Packet::LoginSuccess_String(val) => { debug!("Login: {} {}", val.username, val.uuid); - uuid = protocol::UUID::from_str(&val.uuid); + uuid = protocol::UUID::from_str(&val.uuid).unwrap(); read.state = protocol::State::Play; write.state = protocol::State::Play; break; @@ -1368,7 +1369,7 @@ impl Server { ) { self.on_player_spawn( spawn.entity_id.0, - protocol::UUID::from_str(&spawn.uuid), + protocol::UUID::from_str(&spawn.uuid).unwrap(), f64::from(spawn.x), f64::from(spawn.y), f64::from(spawn.z), From cb8681a615e199a2d36cbefe5471124d73578491 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Mon, 29 Jun 2020 17:40:08 -0700 Subject: [PATCH 16/49] protocol: use mutable iterator populating Biomes3D (needless_range_loop) --- protocol/src/protocol/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/protocol/src/protocol/mod.rs b/protocol/src/protocol/mod.rs index a576a47..cbe8070 100644 --- a/protocol/src/protocol/mod.rs +++ b/protocol/src/protocol/mod.rs @@ -492,12 +492,12 @@ impl Default for Biomes3D { impl Serializable for Biomes3D { fn read_from(buf: &mut R) -> Result { - let mut data: [i32; 1024] = [0; 1024]; + let data: [i32; 1024] = [0; 1024]; // Non-length-prefixed three-dimensional biome data - for i in 0..1024 { + for item in &mut data.to_vec() { let b: i32 = Serializable::read_from(buf)?; - data[i] = b; + *item = b; } Result::Ok(Biomes3D { data }) From 6267509cbe002ad4dc91b451e0f377d6f4bfd915 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Mon, 29 Jun 2020 17:50:08 -0700 Subject: [PATCH 17/49] resources: use writeln macro, fixing write_with_newline --- resources/build.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/resources/build.rs b/resources/build.rs index 12220ab..a53c40c 100644 --- a/resources/build.rs +++ b/resources/build.rs @@ -13,12 +13,12 @@ fn main() { build_map(&mut out, &base); let mut file = BufWriter::new(fs::File::create(&dest.join("resources.rs")).unwrap()); - write!( + writeln!( file, - "pub fn get_file(name: &str) -> Option<&'static [u8]> {{\n" + "pub fn get_file(name: &str) -> Option<&'static [u8]> {{" ) .unwrap(); - write!(file, " match name {{\n").unwrap(); + writeln!(file, " match name {{").unwrap(); for path in &out { let mut absolute_path = std::env::current_dir().unwrap(); absolute_path.push(path); @@ -26,9 +26,9 @@ fn main() { let absolute = absolute_path.to_str().unwrap().replace("\\", "/"); let relative = path.to_str().unwrap().replace("\\", "/"); - write!( + writeln!( file, - " {:?} => Some(include_bytes!(\"{}\")),\n", + " {:?} => Some(include_bytes!(\"{}\")),", relative, absolute ) .unwrap(); From c3038f82ce6310016a65a6c38c48c1e0c808cfc2 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Mon, 29 Jun 2020 18:01:02 -0700 Subject: [PATCH 18/49] Remove redundant imports (single_component_path_imports) --- src/chunk_builder.rs | 1 - src/console/mod.rs | 1 - src/main.rs | 1 - src/model/mod.rs | 1 - src/render/mod.rs | 4 ---- src/render/ui.rs | 1 - src/resources.rs | 5 ----- src/screen/server_list.rs | 4 ---- src/server/mod.rs | 3 --- src/server/target.rs | 1 - src/ui/logo.rs | 1 - src/world/mod.rs | 1 - 12 files changed, 24 deletions(-) diff --git a/src/chunk_builder.rs b/src/chunk_builder.rs index 20b5b55..b3ba7f6 100644 --- a/src/chunk_builder.rs +++ b/src/chunk_builder.rs @@ -6,7 +6,6 @@ use crate::types::bit::Set; use crate::world; use crate::world::block; use rand::{self, Rng, SeedableRng}; -use rand_pcg; use std::sync::mpsc; use std::sync::{Arc, RwLock}; use std::thread; diff --git a/src/console/mod.rs b/src/console/mod.rs index 0f21b6f..6504779 100644 --- a/src/console/mod.rs +++ b/src/console/mod.rs @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -use log; use std::any::Any; use std::cell::{Ref, RefCell}; use std::collections::HashMap; diff --git a/src/main.rs b/src/main.rs index 12d4781..208c75c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -43,7 +43,6 @@ pub mod world; use crate::protocol::mojang; use cfg_if::cfg_if; -use glutin; use std::marker::PhantomData; use std::rc::Rc; use std::sync::mpsc; diff --git a/src/model/mod.rs b/src/model/mod.rs index 00d7459..7956b7b 100644 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -6,7 +6,6 @@ use crate::shared::Direction; use crate::world; use crate::world::block::{Block, TintType}; use byteorder::{NativeEndian, WriteBytesExt}; -use serde_json; use std::cell::RefCell; use std::collections::HashMap; use std::io::Write; diff --git a/src/render/mod.rs b/src/render/mod.rs index d70f667..c418ad8 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -25,11 +25,8 @@ use crate::resources; use crate::world; use byteorder::{NativeEndian, WriteBytesExt}; use cgmath::prelude::*; -use collision; -use image; use image::{GenericImage, GenericImageView}; use log::{error, trace}; -use serde_json; use std::collections::HashMap; use std::io::Write; use std::sync::{Arc, RwLock}; @@ -41,7 +38,6 @@ use std::sync::mpsc; use std::thread; #[cfg(not(target_arch = "wasm32"))] -use reqwest; const ATLAS_SIZE: usize = 1024; diff --git a/src/render/ui.rs b/src/render/ui.rs index bea74d4..28178b8 100644 --- a/src/render/ui.rs +++ b/src/render/ui.rs @@ -18,7 +18,6 @@ use crate::render::glsl; use crate::render::shaders; use crate::resources; use byteorder::{NativeEndian, WriteBytesExt}; -use image; use image::GenericImageView; use std::collections::HashMap; use std::sync::{Arc, RwLock}; diff --git a/src/resources.rs b/src/resources.rs index 50589fa..0fedcf4 100644 --- a/src/resources.rs +++ b/src/resources.rs @@ -14,7 +14,6 @@ extern crate steven_resources as internal; -use serde_json; use std::collections::HashMap; use std::hash::BuildHasherDefault; use std::io; @@ -24,10 +23,6 @@ use std::sync::{Arc, Mutex}; use std::thread; use std_or_web::fs; -#[cfg(not(target_arch = "wasm32"))] -use reqwest; -use zip; - use crate::types::hash::FNVHash; use crate::ui; diff --git a/src/screen/server_list.rs b/src/screen/server_list.rs index dbbbc9a..6d7376f 100644 --- a/src/screen/server_list.rs +++ b/src/screen/server_list.rs @@ -24,11 +24,7 @@ use crate::protocol; use crate::render; use crate::ui; -use base64; -use image; -use rand; use rand::Rng; -use serde_json; use std::time::Duration; pub struct ServerList { diff --git a/src/server/mod.rs b/src/server/mod.rs index cbafead..f4c022d 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -24,12 +24,9 @@ use crate::types::hash::FNVHash; use crate::types::Gamemode; use crate::world; use crate::world::block; -use base64; use cgmath::prelude::*; use log::{debug, error, warn}; use rand::{self, Rng}; -use rsa_public_encrypt_pkcs1; -use serde_json; use std::collections::HashMap; use std::hash::BuildHasherDefault; use std::str::FromStr; diff --git a/src/server/target.rs b/src/server/target.rs index ebb103b..fbb1ed4 100644 --- a/src/server/target.rs +++ b/src/server/target.rs @@ -3,7 +3,6 @@ use crate::render::model; use crate::shared::{Direction, Position}; use crate::world; use crate::world::block; -use cgmath; use collision::{self, Aabb}; pub struct Info { diff --git a/src/ui/logo.rs b/src/ui/logo.rs index 20f9c84..697b23e 100644 --- a/src/ui/logo.rs +++ b/src/ui/logo.rs @@ -2,7 +2,6 @@ use crate::render; use crate::resources; use crate::ui; use rand::{self, seq::SliceRandom}; -use rand_pcg; use std::f64::consts; use std::sync::{Arc, RwLock}; use std::time::{SystemTime, UNIX_EPOCH}; diff --git a/src/world/mod.rs b/src/world/mod.rs index cdb4d23..0b9ad53 100644 --- a/src/world/mod.rs +++ b/src/world/mod.rs @@ -24,7 +24,6 @@ use crate::shared::{Direction, Position}; use crate::types::hash::FNVHash; use crate::types::{bit, nibble}; use cgmath::prelude::*; -use collision; use flate2::read::ZlibDecoder; use std::collections::HashMap; use std::collections::VecDeque; From c2e3ddb80539e2652f81085281c952a52175eb28 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Mon, 29 Jun 2020 18:06:35 -0700 Subject: [PATCH 19/49] Fix write_with_newline, use writeln --- src/console/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/console/mod.rs b/src/console/mod.rs index 6504779..4c684b6 100644 --- a/src/console/mod.rs +++ b/src/console/mod.rs @@ -190,7 +190,7 @@ impl Vars { continue; } for line in var.description().lines() { - write!(file, "# {}\n", line).unwrap(); + writeln!(file, "# {}", line).unwrap(); } write!( file, From 132b40c19e3ce8c35def79f77b9c29688d5699da Mon Sep 17 00:00:00 2001 From: ice_iix Date: Mon, 29 Jun 2020 18:06:51 -0700 Subject: [PATCH 20/49] Fix collapsible_if in main game loop --- src/main.rs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/main.rs b/src/main.rs index 208c75c..c999dd2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -507,18 +507,16 @@ fn handle_window_event( game.focused = true; window.window().set_cursor_grab(true).unwrap(); window.window().set_cursor_visible(false); - } else { - if !game.focused { - window.window().set_cursor_grab(false).unwrap(); - window.window().set_cursor_visible(true); - ui_container.click_at( - game, - game.last_mouse_x, - game.last_mouse_y, - width, - height, - ); - } + } else if !game.focused { + window.window().set_cursor_grab(false).unwrap(); + window.window().set_cursor_visible(true); + ui_container.click_at( + game, + game.last_mouse_x, + game.last_mouse_y, + width, + height, + ); } } (ElementState::Pressed, MouseButton::Right) => { From fe5cb47d40436b22e3b951cfadea1726d578431e Mon Sep 17 00:00:00 2001 From: ice_iix Date: Mon, 29 Jun 2020 18:07:12 -0700 Subject: [PATCH 21/49] Fix redundant field names in struct initialization (redundant_field_names) --- src/screen/login.rs | 2 +- src/screen/settings_menu.rs | 2 +- src/ui/mod.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/screen/login.rs b/src/screen/login.rs index 784554b..8fd9b56 100644 --- a/src/screen/login.rs +++ b/src/screen/login.rs @@ -51,7 +51,7 @@ impl Login { pub fn new(vars: Rc) -> Login { Login { elements: None, - vars: vars, + vars, } } } diff --git a/src/screen/settings_menu.rs b/src/screen/settings_menu.rs index f44cc40..5928886 100644 --- a/src/screen/settings_menu.rs +++ b/src/screen/settings_menu.rs @@ -21,7 +21,7 @@ impl SettingsMenu { SettingsMenu { _vars: vars, elements: None, - show_disconnect_button: show_disconnect_button, + show_disconnect_button, } } } diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 86dedb3..fa63aaf 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -769,7 +769,7 @@ macro_rules! element { $oname: self.$oname.unwrap_or($oval), )* $( - $nname: $nname, + $nname, )* // Base fields draw_index: self.draw_index, From e8c066cd266ce3262c7bb03183f1ecf1d030a421 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Mon, 29 Jun 2020 18:17:16 -0700 Subject: [PATCH 22/49] Clippy: allow too_many_arguments, many_single_char_names --- src/main.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main.rs b/src/main.rs index c999dd2..9f9d696 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,6 +13,8 @@ // limitations under the License. #![recursion_limit = "300"] +#![allow(clippy::too_many_arguments)] +#![allow(clippy::many_single_char_names)] use log::{error, info, warn}; use std::time::{Duration, Instant}; From 55856ccf1b1c42c18b3fc2f375c519a43e89cb6f Mon Sep 17 00:00:00 2001 From: ice_iix Date: Mon, 29 Jun 2020 18:26:29 -0700 Subject: [PATCH 23/49] Allow TeleportFlag enum variant names Rel..., Rel..., as they are all relative --- src/server/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/server/mod.rs b/src/server/mod.rs index f4c022d..c705d7b 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -1970,6 +1970,7 @@ impl Server { } } +#[allow(clippy::enum_variant_names)] #[derive(Debug, Clone, Copy)] enum TeleportFlag { RelX = 0b00001, From 9d88168d0e43405b86f0481a3ba32e7f0e13b09e Mon Sep 17 00:00:00 2001 From: ice_iix Date: Mon, 29 Jun 2020 18:26:53 -0700 Subject: [PATCH 24/49] Fix collapsible_if in lighting update --- src/world/mod.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/world/mod.rs b/src/world/mod.rs index 0b9ad53..711689a 100644 --- a/src/world/mod.rs +++ b/src/world/mod.rs @@ -208,11 +208,9 @@ impl World { while !self.light_updates.is_empty() { updates_performed += 1; self.do_light_update(); - if updates_performed & 0xFFF == 0 { - if start.elapsed().subsec_nanos() >= 5000000 { - // 5 ms for light updates - break; - } + if (updates_performed & 0xFFF == 0) && start.elapsed().subsec_nanos() >= 5000000 { + // 5 ms for light updates + break; } } From 8fb5491e15390c7f486987b713063fc1b17a4d04 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Mon, 29 Jun 2020 18:37:08 -0700 Subject: [PATCH 25/49] Add missing default implementations (new_without_default) --- src/console/mod.rs | 1 + src/ecs/mod.rs | 7 +++++++ src/gl/mod.rs | 5 +++++ src/server/target.rs | 6 ++++++ src/ui/mod.rs | 7 +++++++ 5 files changed, 26 insertions(+) diff --git a/src/console/mod.rs b/src/console/mod.rs index 4c684b6..4a054e1 100644 --- a/src/console/mod.rs +++ b/src/console/mod.rs @@ -203,6 +203,7 @@ impl Vars { } } +#[derive(Default)] pub struct Console { history: Vec, dirty: bool, diff --git a/src/ecs/mod.rs b/src/ecs/mod.rs index 719bf8d..c2ab443 100644 --- a/src/ecs/mod.rs +++ b/src/ecs/mod.rs @@ -53,6 +53,12 @@ pub struct Filter { bits: BSet, } +impl Default for Filter { + fn default() -> Self { + Self::new() + } +} + impl Filter { /// Creates an empty filter which matches everything pub fn new() -> Filter { @@ -106,6 +112,7 @@ struct EntityState { } /// Stores and manages a collection of entities. +#[derive(Default)] pub struct Manager { num_components: usize, entities: Vec<(Option, u32)>, diff --git a/src/gl/mod.rs b/src/gl/mod.rs index 9a100fb..a782d78 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -264,6 +264,7 @@ pub const NEAREST_MIPMAP_LINEAR: TextureValue = gl::NEAREST_MIPMAP_LINEAR as Tex pub const CLAMP_TO_EDGE: TextureValue = gl::CLAMP_TO_EDGE as TextureValue; /// `Texture` is a buffer of data used by fragment shaders. +#[derive(Default)] pub struct Texture(u32); impl Texture { @@ -510,6 +511,7 @@ pub type ShaderParameter = u32; pub const COMPILE_STATUS: ShaderParameter = gl::COMPILE_STATUS; pub const INFO_LOG_LENGTH: ShaderParameter = gl::INFO_LOG_LENGTH; +#[derive(Default)] pub struct Program(u32); impl Program { @@ -712,6 +714,7 @@ impl Attribute { // VertexArray is used to store state needed to render vertices. // This includes buffers, the format of the buffers and enabled // attributes. +#[derive(Default)] pub struct VertexArray(u32); impl VertexArray { @@ -772,6 +775,7 @@ pub const READ_ONLY: Access = gl::READ_ONLY; pub const WRITE_ONLY: Access = gl::WRITE_ONLY; /// `Buffer` is a storage for vertex data. +#[derive(Default)] pub struct Buffer(u32); impl Buffer { @@ -871,6 +875,7 @@ pub const COLOR_ATTACHMENT_1: Attachment = gl::COLOR_ATTACHMENT1; pub const COLOR_ATTACHMENT_2: Attachment = gl::COLOR_ATTACHMENT2; pub const DEPTH_ATTACHMENT: Attachment = gl::DEPTH_ATTACHMENT; +#[derive(Default)] pub struct Framebuffer(u32); pub fn check_framebuffer_status() { diff --git a/src/server/target.rs b/src/server/target.rs index fbb1ed4..c8c1ba4 100644 --- a/src/server/target.rs +++ b/src/server/target.rs @@ -11,6 +11,12 @@ pub struct Info { last_pos: Position, } +impl Default for Info { + fn default() -> Self { + Self::new() + } +} + impl Info { pub fn new() -> Info { Info { diff --git a/src/ui/mod.rs b/src/ui/mod.rs index fa63aaf..0091a62 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -282,6 +282,12 @@ pub struct Container { last_height: f64, } +impl Default for Container { + fn default() -> Self { + Self::new() + } +} + impl Container { pub fn new() -> Container { Container { @@ -677,6 +683,7 @@ macro_rules! element { } } + #[derive(Default)] pub struct $builder { $( $sname: Option<$sty>, From 98dff0b390b40402386e4db63a22034e3cf39b0f Mon Sep 17 00:00:00 2001 From: ice_iix Date: Mon, 29 Jun 2020 18:48:07 -0700 Subject: [PATCH 26/49] Fix redundant clones --- src/chunk_builder.rs | 5 +---- src/render/mod.rs | 5 ++--- src/server/mod.rs | 6 +++--- src/server/sun.rs | 4 ++-- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/chunk_builder.rs b/src/chunk_builder.rs index b3ba7f6..5bdd915 100644 --- a/src/chunk_builder.rs +++ b/src/chunk_builder.rs @@ -26,10 +26,7 @@ impl ChunkBuilder { resources: Arc>, textures: Arc>, ) -> ChunkBuilder { - let models = Arc::new(RwLock::new(model::Factory::new( - resources.clone(), - textures, - ))); + let models = Arc::new(RwLock::new(model::Factory::new(resources, textures))); let mut threads = vec![]; let mut free = vec![]; diff --git a/src/render/mod.rs b/src/render/mod.rs index c418ad8..325bb73 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -1386,7 +1386,7 @@ impl TextureManager { rel_height: 1.0, is_rel: false, }; - self.textures.insert(full_name.to_owned(), t.clone()); + self.textures.insert(full_name, t.clone()); t } @@ -1421,8 +1421,7 @@ impl TextureManager { (height as f32) / (tex.height as f32), ); let old_name = mem::replace(&mut tex.name, format!("steven-dynamic:{}", name)); - self.dynamic_textures - .insert(name.to_owned(), (tex.clone(), img)); + self.dynamic_textures.insert(name.to_owned(), (tex, img)); // We need to rename the texture itself so that get_texture calls // work with the new name let mut old = self.textures.remove(&old_name).unwrap(); diff --git a/src/server/mod.rs b/src/server/mod.rs index c705d7b..1ec9e87 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -149,7 +149,7 @@ impl Server { warn!("Server is running in offline mode"); debug!("Login: {} {}", val.username, val.uuid); let mut read = conn.clone(); - let mut write = conn.clone(); + let mut write = conn; read.state = protocol::State::Play; write.state = protocol::State::Play; let rx = Self::spawn_reader(read); @@ -167,7 +167,7 @@ impl Server { warn!("Server is running in offline mode"); debug!("Login: {} {:?}", val.username, val.uuid); let mut read = conn.clone(); - let mut write = conn.clone(); + let mut write = conn; read.state = protocol::State::Play; write.state = protocol::State::Play; let rx = Self::spawn_reader(read); @@ -214,7 +214,7 @@ impl Server { } let mut read = conn.clone(); - let mut write = conn.clone(); + let mut write = conn; read.enable_encyption(&shared, true); write.enable_encyption(&shared, false); diff --git a/src/server/sun.rs b/src/server/sun.rs index 9855c88..114113c 100644 --- a/src/server/sun.rs +++ b/src/server/sun.rs @@ -114,7 +114,7 @@ impl SunModel { z: SIZE, texture_x: 1.0, texture_y: 0.0, - texture: tex.clone(), + texture: tex, r: 255, g: 255, b: 255, @@ -178,7 +178,7 @@ impl SunModel { z: SIZE, texture_x: mpx + (1.0 / 4.0), texture_y: mpy, - texture: tex.clone(), + texture: tex, r: 255, g: 255, b: 255, From 3aaa14eb8052586852c5e4e8a79315c86d1d8047 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Tue, 30 Jun 2020 18:36:20 -0700 Subject: [PATCH 27/49] steven_gl: suppress clippy warnings in gl-generated code --- gl/src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gl/src/lib.rs b/gl/src/lib.rs index 44ae78f..0d44ad1 100644 --- a/gl/src/lib.rs +++ b/gl/src/lib.rs @@ -1 +1,4 @@ +#![allow(clippy::unused_unit)] +#![allow(clippy::missing_safety_doc)] +#![allow(clippy::too_many_arguments)] include!(concat!(env!("OUT_DIR"), "/bindings.rs")); From b4aa23ecf5a2feb83fea1be3b24722d019ffa4ff Mon Sep 17 00:00:00 2001 From: ice_iix Date: Tue, 30 Jun 2020 18:48:25 -0700 Subject: [PATCH 28/49] Use if let instead of map, fixes option_map_unit_fn --- src/render/model.rs | 105 ++++++++++++++++++++++---------------------- 1 file changed, 53 insertions(+), 52 deletions(-) diff --git a/src/render/model.rs b/src/render/model.rs index c4d2a30..339af43 100644 --- a/src/render/model.rs +++ b/src/render/model.rs @@ -86,31 +86,36 @@ impl Manager { let mut model = { let collection = &mut self.collections[ckey.0]; collection.shader.program.use_program(); - collection.shader.position.map(|v| v.enable()); - collection.shader.texture_info.map(|v| v.enable()); - collection.shader.texture_offset.map(|v| v.enable()); - collection.shader.color.map(|v| v.enable()); - collection.shader.id.map(|v| v.enable()); - collection - .shader - .position - .map(|v| v.vertex_pointer(3, gl::FLOAT, false, 36, 0)); - collection - .shader - .texture_info - .map(|v| v.vertex_pointer(4, gl::UNSIGNED_SHORT, false, 36, 12)); - collection - .shader - .texture_offset - .map(|v| v.vertex_pointer_int(3, gl::SHORT, 36, 20)); - collection - .shader - .color - .map(|v| v.vertex_pointer(4, gl::UNSIGNED_BYTE, true, 36, 28)); - collection - .shader - .id - .map(|v| v.vertex_pointer_int(1, gl::UNSIGNED_BYTE, 36, 32)); + if let Some(v) = collection.shader.position { + v.enable() + } + if let Some(v) = collection.shader.texture_info { + v.enable() + } + if let Some(v) = collection.shader.texture_offset { + v.enable() + } + if let Some(v) = collection.shader.color { + v.enable() + } + if let Some(v) = collection.shader.id { + v.enable() + } + if let Some(v) = collection.shader.position { + v.vertex_pointer(3, gl::FLOAT, false, 36, 0) + } + if let Some(v) = collection.shader.texture_info { + v.vertex_pointer(4, gl::UNSIGNED_SHORT, false, 36, 12) + } + if let Some(v) = collection.shader.texture_offset { + v.vertex_pointer_int(3, gl::SHORT, 36, 20) + } + if let Some(v) = collection.shader.color { + v.vertex_pointer(4, gl::UNSIGNED_BYTE, true, 36, 28) + } + if let Some(v) = collection.shader.id { + v.vertex_pointer_int(1, gl::UNSIGNED_BYTE, 36, 32) + } let mut model = Model { // For culling only @@ -244,23 +249,21 @@ impl Manager { gl::enable(gl::BLEND); for collection in &self.collections { collection.shader.program.use_program(); - collection - .shader - .perspective_matrix - .map(|v| v.set_matrix4(perspective_matrix)); - collection - .shader - .camera_matrix - .map(|v| v.set_matrix4(camera_matrix)); - collection.shader.texture.map(|v| v.set_int(0)); - collection - .shader - .sky_offset - .map(|v| v.set_float(sky_offset)); - collection - .shader - .light_level - .map(|v| v.set_float(light_level)); + if let Some(v) = collection.shader.perspective_matrix { + v.set_matrix4(perspective_matrix) + } + if let Some(v) = collection.shader.camera_matrix { + v.set_matrix4(camera_matrix) + } + if let Some(v) = collection.shader.texture { + v.set_int(0) + } + if let Some(v) = collection.shader.sky_offset { + v.set_float(sky_offset) + } + if let Some(v) = collection.shader.light_level { + v.set_float(light_level) + } gl::blend_func(collection.blend_s, collection.blend_d); for model in collection.models.values() { @@ -273,17 +276,15 @@ impl Manager { continue; } model.array.bind(); - collection - .shader - .lighting - .map(|v| v.set_float2(model.block_light, model.sky_light)); - collection - .shader - .model_matrix - .map(|v| v.set_matrix4_multi(&model.matrix)); - collection.shader.color_mul.map(|v| { + if let Some(v) = collection.shader.lighting { + v.set_float2(model.block_light, model.sky_light) + } + if let Some(v) = collection.shader.model_matrix { + v.set_matrix4_multi(&model.matrix) + } + if let Some(v) = collection.shader.color_mul { v.set_float_mutli_raw(model.colors.as_ptr() as *const _, model.colors.len()) - }); + } gl::draw_elements(gl::TRIANGLES, model.count, self.index_type, 0); } } From d496eaf3bbc719c4a17ef8ccb3d43a2d198ef13f Mon Sep 17 00:00:00 2001 From: ice_iix Date: Tue, 30 Jun 2020 18:50:46 -0700 Subject: [PATCH 29/49] Use is_*() instead of if let x(_), fixes redundant_pattern_matching --- src/render/mod.rs | 2 +- src/resources.rs | 4 ++-- src/server/mod.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/render/mod.rs b/src/render/mod.rs index 325bb73..85d95e8 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -1218,7 +1218,7 @@ impl TextureManager { } fn get_texture(&self, name: &str) -> Option { - if let Some(_) = name.find(':') { + if name.find(':').is_some() { self.textures.get(name).cloned() } else { self.textures.get(&format!("minecraft:{}", name)).cloned() diff --git a/src/resources.rs b/src/resources.rs index 0fedcf4..b8d3fa8 100644 --- a/src/resources.rs +++ b/src/resources.rs @@ -131,7 +131,7 @@ impl Manager { // (if it was started) let mut done = false; if let Some(ref recv) = self.vanilla_chan { - if let Ok(_) = recv.try_recv() { + if recv.try_recv().is_ok() { done = true; } } @@ -141,7 +141,7 @@ impl Manager { } let mut done = false; if let Some(ref recv) = self.vanilla_assets_chan { - if let Ok(_) = recv.try_recv() { + if recv.try_recv().is_ok() { done = true; } } diff --git a/src/server/mod.rs b/src/server/mod.rs index 1ec9e87..814de7a 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -266,7 +266,7 @@ impl Server { thread::spawn(move || loop { let pck = read.read_packet(); let was_error = pck.is_err(); - if let Err(_) = tx.send(pck) { + if tx.send(pck).is_err() { return; } if was_error { From 8a0936faac3537b53b40d99502795ea4d2802eff Mon Sep 17 00:00:00 2001 From: ice_iix Date: Tue, 30 Jun 2020 18:53:33 -0700 Subject: [PATCH 30/49] Disable clippy::let_and_return for now in src/render/mod.rs --- src/render/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/render/mod.rs b/src/render/mod.rs index 85d95e8..5c52e23 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -955,6 +955,7 @@ pub struct TextureManager { } impl TextureManager { + #[allow(clippy::let_and_return)] fn new( res: Arc>, ) -> ( @@ -968,6 +969,7 @@ impl TextureManager { let mut tm = TextureManager { textures: HashMap::with_hasher(BuildHasherDefault::default()), version: { + // TODO: fix borrow and remove clippy::let_and_return above let ver = res.read().unwrap().version(); ver }, From c4690bba32e467a4b62f3a348378fd1ba1b26ffe Mon Sep 17 00:00:00 2001 From: ice_iix Date: Tue, 30 Jun 2020 18:56:08 -0700 Subject: [PATCH 31/49] Use add(x) instead of offset(x as isize), fixes ptr_offset_with_cast --- src/ecs/mod.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ecs/mod.rs b/src/ecs/mod.rs index c2ab443..36da092 100644 --- a/src/ecs/mod.rs +++ b/src/ecs/mod.rs @@ -626,7 +626,7 @@ impl ComponentMem { data.2 += 1; data.1.set(rem, true); unsafe { - ptr::write(data.0.as_mut_ptr().offset(start as isize) as *mut T, val); + ptr::write(data.0.as_mut_ptr().add(start) as *mut T, val); } } @@ -642,7 +642,7 @@ impl ComponentMem { // we use the drop_func which stores the type in its closure // to handle the dropping for us. unsafe { - (self.drop_func)(data.0.as_mut_ptr().offset(start as isize)); + (self.drop_func)(data.0.as_mut_ptr().add(start)); } data.2 -= 1; data.2 @@ -657,7 +657,7 @@ impl ComponentMem { let rem = index % COMPONENTS_PER_BLOCK; let data = self.data[idx].as_ref().unwrap(); let start = rem * self.component_size; - unsafe { &*(data.0.as_ptr().offset(start as isize) as *const T) } + unsafe { &*(data.0.as_ptr().add(start) as *const T) } } fn get_mut(&mut self, index: usize) -> &mut T { @@ -665,7 +665,7 @@ impl ComponentMem { let rem = index % COMPONENTS_PER_BLOCK; let data = self.data[idx].as_mut().unwrap(); let start = rem * self.component_size; - unsafe { &mut *(data.0.as_mut_ptr().offset(start as isize) as *mut T) } + unsafe { &mut *(data.0.as_mut_ptr().add(start) as *mut T) } } } @@ -677,7 +677,7 @@ impl Drop for ComponentMem { if data.1.get(i) { let start = i * self.component_size; unsafe { - (self.drop_func)(data.0.as_mut_ptr().offset(start as isize)); + (self.drop_func)(data.0.as_mut_ptr().add(start)); } } } From bffb33297feddc1f24d2f40f7a3a0b6528de9cd3 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Tue, 30 Jun 2020 19:01:17 -0700 Subject: [PATCH 32/49] Allow float_cmp since we use it to check if floating point values changed from the last value assigned, not compare two different floating point values; downgrade not_unsafe_ptr_arg_deref to warning --- azure-pipelines.yml | 2 +- src/main.rs | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 1889625..0445577 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -6,7 +6,7 @@ jobs: displayName: "Install build dependencies" condition: eq(variables['Agent.OS'], 'Linux') minrust: 1.44.1 - clippy: -A clippy::not_unsafe_ptr_arg_deref -A clippy::float_cmp + clippy: resources: repositories: diff --git a/src/main.rs b/src/main.rs index 9f9d696..971f3d0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,8 +13,10 @@ // limitations under the License. #![recursion_limit = "300"] -#![allow(clippy::too_many_arguments)] -#![allow(clippy::many_single_char_names)] +#![allow(clippy::too_many_arguments)] // match standard gl functions with many arguments +#![allow(clippy::many_single_char_names)] // short variable names provide concise clarity +#![warn(clippy::not_unsafe_ptr_arg_deref)] // TODO: fix unsafe warnings +#![allow(clippy::float_cmp)] // float comparison used to check if changed use log::{error, info, warn}; use std::time::{Duration, Instant}; From 07fd4788e1d702e0150a77b5dfeb48e89abfb3db Mon Sep 17 00:00:00 2001 From: ice_iix Date: Tue, 30 Jun 2020 19:03:59 -0700 Subject: [PATCH 33/49] Use += to fix assign_op_pattern --- src/entity/player.rs | 4 ++-- src/entity/systems.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/entity/player.rs b/src/entity/player.rs index 997115f..0a2fa40 100644 --- a/src/entity/player.rs +++ b/src/entity/player.rs @@ -640,7 +640,7 @@ impl ecs::System for MovementHandler { if movement.is_key_pressed(Stevenkey::Jump) { if movement.when_last_jump_pressed.is_none() { movement.when_last_jump_pressed = Some(Instant::now()); - if !movement.when_last_jump_released.is_none() { + if movement.when_last_jump_released.is_some() { let dt = movement.when_last_jump_pressed.unwrap() - movement.when_last_jump_released.unwrap(); if dt.as_secs() == 0 @@ -655,7 +655,7 @@ impl ecs::System for MovementHandler { } } } - } else if !movement.when_last_jump_pressed.is_none() { + } else if movement.when_last_jump_pressed.is_some() { movement.when_last_jump_released = Some(Instant::now()); movement.when_last_jump_pressed = None; } diff --git a/src/entity/systems.rs b/src/entity/systems.rs index dbb56ec..73c75c9 100644 --- a/src/entity/systems.rs +++ b/src/entity/systems.rs @@ -38,7 +38,7 @@ impl ecs::System for ApplyVelocity { } let pos = m.get_component_mut(e, self.position).unwrap(); let vel = m.get_component(e, self.velocity).unwrap(); - pos.position = pos.position + vel.velocity; + pos.position += vel.velocity; } } } From 0f9dcd2515a723001de69c4be271812d2dbd58ab Mon Sep 17 00:00:00 2001 From: ice_iix Date: Tue, 30 Jun 2020 19:09:15 -0700 Subject: [PATCH 34/49] Use unwrap_or_else to fix two or_fun_call and suppress one --- src/main.rs | 3 ++- src/model/mod.rs | 2 +- src/world/mod.rs | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 971f3d0..1833dfa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -299,7 +299,8 @@ fn main2() { let textures = renderer.get_textures(); let dpi_factor = window.window().scale_factor(); let default_protocol_version = protocol::versions::protocol_name_to_protocol_version( - opt.default_protocol_version.unwrap_or("".to_string()), + opt.default_protocol_version + .unwrap_or_else(|| "".to_string()), ); let mut game = Game { server: server::Server::dummy_server(resource_manager.clone()), diff --git a/src/model/mod.rs b/src/model/mod.rs index 7956b7b..7a6c365 100644 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -891,7 +891,7 @@ impl RawModel { .texture_vars .get(&name[1..]) .cloned() - .unwrap_or("".to_owned()); + .unwrap_or_else(|| "".to_owned()); return self.lookup_texture(&tex); } name.to_owned() diff --git a/src/world/mod.rs b/src/world/mod.rs index 711689a..c56f091 100644 --- a/src/world/mod.rs +++ b/src/world/mod.rs @@ -994,6 +994,7 @@ impl World { self.load_chunk19_or_115(false, x, z, new, mask, data) } + #[allow(clippy::or_fun_call)] fn load_chunk19_or_115( &mut self, read_biomes: bool, @@ -1068,6 +1069,7 @@ impl World { mappings .get(&id) .cloned() + // TODO: fix or_fun_call, but do not re-borrow self .unwrap_or(block::Block::by_vanilla_id( id, self.protocol_version, From c27425750d53597c7f81891dd9f432132490ad84 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Thu, 2 Jul 2020 16:49:38 -0700 Subject: [PATCH 35/49] Change set_float_multi_raw to unsafe because it dereferences a raw pointer argument (not_unsafe_ptr_arg_deref); fix typo --- src/gl/mod.rs | 7 +++---- src/main.rs | 1 - src/render/model.rs | 4 +++- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/gl/mod.rs b/src/gl/mod.rs index a782d78..646a322 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -648,10 +648,9 @@ impl Uniform { } } - pub fn set_float_mutli_raw(&self, data: *const f32, len: usize) { - unsafe { - gl::Uniform4fv(self.0, len as i32, data); - } + #[allow(clippy::missing_safety_doc)] + pub unsafe fn set_float_multi_raw(&self, data: *const f32, len: usize) { + gl::Uniform4fv(self.0, len as i32, data); } pub fn set_matrix4(&self, m: &::cgmath::Matrix4) { diff --git a/src/main.rs b/src/main.rs index 1833dfa..3f4009b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,7 +15,6 @@ #![recursion_limit = "300"] #![allow(clippy::too_many_arguments)] // match standard gl functions with many arguments #![allow(clippy::many_single_char_names)] // short variable names provide concise clarity -#![warn(clippy::not_unsafe_ptr_arg_deref)] // TODO: fix unsafe warnings #![allow(clippy::float_cmp)] // float comparison used to check if changed use log::{error, info, warn}; diff --git a/src/render/model.rs b/src/render/model.rs index 339af43..70a1bea 100644 --- a/src/render/model.rs +++ b/src/render/model.rs @@ -283,7 +283,9 @@ impl Manager { v.set_matrix4_multi(&model.matrix) } if let Some(v) = collection.shader.color_mul { - v.set_float_mutli_raw(model.colors.as_ptr() as *const _, model.colors.len()) + unsafe { + v.set_float_multi_raw(model.colors.as_ptr() as *const _, model.colors.len()) + } } gl::draw_elements(gl::TRIANGLES, model.count, self.index_type, 0); } From 35f29705b3b54562257075ee9b2f9a08bce02f23 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Thu, 2 Jul 2020 16:53:27 -0700 Subject: [PATCH 36/49] Use question mark operator idiom (question_mark) --- src/render/atlas.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/render/atlas.rs b/src/render/atlas.rs index 8ad527e..11a469a 100644 --- a/src/render/atlas.rs +++ b/src/render/atlas.rs @@ -57,9 +57,7 @@ impl Atlas { } } } - if target.is_none() { - return None; - } + target?; let mut t = target.unwrap(); let ret = Rect { x: t.x, From 9939eae361d5fe7597f856c2b762f85e40e0a37c Mon Sep 17 00:00:00 2001 From: ice_iix Date: Thu, 2 Jul 2020 17:07:48 -0700 Subject: [PATCH 37/49] Use values_mut() to iterate map values (for_kv_map) --- src/render/model.rs | 2 +- src/world/mod.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/render/model.rs b/src/render/model.rs index 70a1bea..20a1879 100644 --- a/src/render/model.rs +++ b/src/render/model.rs @@ -219,7 +219,7 @@ impl Manager { textures: &Arc>, ) { for collection in &mut self.collections { - for (_, model) in &mut collection.models { + for model in collection.models.values_mut() { for vert in &mut model.verts { vert.texture = if vert.texture.version == version { vert.texture.clone() diff --git a/src/world/mod.rs b/src/world/mod.rs index c56f091..92336e3 100644 --- a/src/world/mod.rs +++ b/src/world/mod.rs @@ -313,7 +313,7 @@ impl World { pub fn copy_cloud_heightmap(&mut self, data: &mut [u8]) -> bool { let mut dirty = false; - for (_, c) in &mut self.chunks { + for c in self.chunks.values_mut() { if c.heightmap_dirty { dirty = true; c.heightmap_dirty = false; @@ -440,7 +440,7 @@ impl World { pub fn get_dirty_chunk_sections(&mut self) -> Vec<(i32, i32, i32)> { let mut out = vec![]; - for (_, chunk) in &mut self.chunks { + for chunk in self.chunks.values_mut() { for sec in &mut chunk.sections { if let Some(sec) = sec.as_mut() { if !sec.building && sec.dirty { @@ -487,7 +487,7 @@ impl World { } pub fn flag_dirty_all(&mut self) { - for (_, chunk) in &mut self.chunks { + for chunk in self.chunks.values_mut() { for sec in &mut chunk.sections { if let Some(sec) = sec.as_mut() { sec.dirty = true; From 2e2c82eae4a860f0958c85d0e8a0ea35382011e9 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Thu, 2 Jul 2020 17:14:49 -0700 Subject: [PATCH 38/49] Use if let pattern match to fix unnecessary_wrap --- src/main.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3f4009b..c95b46e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -350,8 +350,7 @@ fn main2() { let version = { let try_res = game.resource_manager.try_write(); - if try_res.is_ok() { - let mut res = try_res.unwrap(); + if let Ok(mut res) = try_res { res.tick(&mut resui, &mut ui_container, delta); res.version() } else { From deb35db895c45b1f6db373a7a4e9635c8a9225f0 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Thu, 2 Jul 2020 17:17:51 -0700 Subject: [PATCH 39/49] Use more descriptive name to fix blacklisted_name 'bar' (as in foobar) --- src/resources.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/resources.rs b/src/resources.rs index b8d3fa8..2163e9a 100644 --- a/src/resources.rs +++ b/src/resources.rs @@ -230,11 +230,11 @@ impl Manager { prog = task.progress as f64 / task.total as f64; } let background = ui.background.borrow(); - let bar = ui.progress_bar.borrow(); + let progress_bar = ui.progress_bar.borrow(); // Let the progress bar finish if !found && (background.y - ui.position).abs() < 0.7 * delta - && (bar.width - 350.0).abs() < 1.0 * delta + && (progress_bar.width - 350.0).abs() < 1.0 * delta { ui.closing = true; ui.position = -UI_HEIGHT; @@ -257,12 +257,13 @@ impl Manager { } else { background.y += (ui.position - background.y).signum() * 0.7 * delta; } - let mut bar = ui.progress_bar.borrow_mut(); + let mut progress_bar = ui.progress_bar.borrow_mut(); let target_size = (350.0 * ui.progress).min(350.0); - if (bar.width - target_size).abs() < 1.0 * delta { - bar.width = target_size; + if (progress_bar.width - target_size).abs() < 1.0 * delta { + progress_bar.width = target_size; } else { - bar.width += ((target_size - bar.width).signum() * delta).max(0.0); + progress_bar.width += + ((target_size - progress_bar.width).signum() * delta).max(0.0); } } From 113abefd80511360498fb04678638998fe7e2ace Mon Sep 17 00:00:00 2001 From: ice_iix Date: Thu, 2 Jul 2020 17:22:24 -0700 Subject: [PATCH 40/49] Fix unnecessary use of match with if let (single_match) --- src/server/mod.rs | 4 ++-- src/ui/mod.rs | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/server/mod.rs b/src/server/mod.rs index 814de7a..c95307d 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -844,8 +844,8 @@ impl Server { } match channel { - // TODO: "REGISTER" => - // TODO: "UNREGISTER" => + "REGISTER" => {} // TODO + "UNREGISTER" => {} // TODO "FML|HS" => { let msg = crate::protocol::Serializable::read_from(&mut std::io::Cursor::new(data)) .unwrap(); diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 0091a62..4b43a35 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -1539,9 +1539,8 @@ impl UIElement for TextBox { (VirtualKeyCode::V, true) => { if ctrl_pressed { let mut clipboard: ClipboardContext = ClipboardProvider::new().unwrap(); - match clipboard.get_contents() { - Ok(text) => self.input.push_str(&text), - Err(_) => (), + if let Ok(text) = clipboard.get_contents() { + self.input.push_str(&text) } } } From 7f5ab06c340f2756d44018a78a5440d596c55938 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Thu, 2 Jul 2020 17:25:55 -0700 Subject: [PATCH 41/49] Use !is_empty instead of length check (len_zero) --- src/screen/server_list.rs | 2 +- src/server/mod.rs | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/screen/server_list.rs b/src/screen/server_list.rs index 6d7376f..bdec200 100644 --- a/src/screen/server_list.rs +++ b/src/screen/server_list.rs @@ -502,7 +502,7 @@ impl super::Screen for ServerList { } let sm = format!("{} mods + {}", res.forge_mods.len(), res.protocol_name); - let st = if res.forge_mods.len() > 0 { + let st = if !res.forge_mods.is_empty() { &sm } else { &res.protocol_name diff --git a/src/server/mod.rs b/src/server/mod.rs index c95307d..8af1474 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -112,7 +112,11 @@ impl Server { ) -> Result { let mut conn = protocol::Conn::new(address, protocol_version)?; - let tag = if forge_mods.len() != 0 { "\0FML\0" } else { "" }; + let tag = if !forge_mods.is_empty() { + "\0FML\0" + } else { + "" + }; let host = conn.host.clone() + tag; let port = conn.port; conn.write_packet(protocol::packet::handshake::serverbound::Handshake { From f88036ea4e21cbce614793c28532f408c2acf606 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Thu, 2 Jul 2020 17:29:16 -0700 Subject: [PATCH 42/49] Use byte literal b"" instead of as_bytes (string_lit_as_bytes) --- src/server/mod.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/server/mod.rs b/src/server/mod.rs index 8af1474..f8ed6b4 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -867,10 +867,7 @@ impl Server { fml_protocol_version, override_dimension ); - self.write_plugin_message( - "REGISTER", - "FML|HS\0FML\0FML|MP\0FML\0FORGE".as_bytes(), - ); + self.write_plugin_message("REGISTER", b"FML|HS\0FML\0FML|MP\0FML\0FORGE"); self.write_fmlhs_plugin_message(&ClientHello { fml_protocol_version, }); From 0d1e86a233214c1d6552c5b73b41a63e764eb38f Mon Sep 17 00:00:00 2001 From: ice_iix Date: Thu, 2 Jul 2020 17:39:40 -0700 Subject: [PATCH 43/49] Box block update sign text to reduce enum size from 268 bytes (large_enum_variant) warning: large size difference between variants --> src/world/mod.rs:54:5 | 54 | / UpdateSignText( 55 | | Position, 56 | | format::Component, 57 | | format::Component, 58 | | format::Component, 59 | | format::Component, 60 | | ), | |_____^ this variant is 268 bytes | = note: `#[warn(clippy::large_enum_variant)]` on by default note: and the second-largest variant is 12 bytes: --> src/world/mod.rs:53:5 | 53 | Remove(Position), | ^^^^^^^^^^^^^^^^ help: consider boxing the large fields to reduce the total size of the enum --> src/world/mod.rs:54:5 | 54 | / UpdateSignText( 55 | | Position, 56 | | format::Component, 57 | | format::Component, 58 | | format::Component, 59 | | format::Component, 60 | | ), | |_____^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#large_enum_variant --- src/server/mod.rs | 12 ++++++------ src/world/mod.rs | 15 +++++++++------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/server/mod.rs b/src/server/mod.rs index f8ed6b4..24edd36 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -1576,13 +1576,13 @@ impl Server { nbt.1.get("Text4").unwrap().as_str().unwrap(), ); self.world.add_block_entity_action( - world::BlockEntityAction::UpdateSignText( + world::BlockEntityAction::UpdateSignText(Box::new(( block_update.location, line1, line2, line3, line4, - ), + ))), ); } //10 => // Unused @@ -1610,13 +1610,13 @@ impl Server { format::convert_legacy(&mut update_sign.line3); format::convert_legacy(&mut update_sign.line4); self.world - .add_block_entity_action(world::BlockEntityAction::UpdateSignText( + .add_block_entity_action(world::BlockEntityAction::UpdateSignText(Box::new(( update_sign.location, update_sign.line1, update_sign.line2, update_sign.line3, update_sign.line4, - )); + )))); } fn on_sign_update_u16(&mut self, mut update_sign: packet::play::clientbound::UpdateSign_u16) { @@ -1625,13 +1625,13 @@ impl Server { format::convert_legacy(&mut update_sign.line3); format::convert_legacy(&mut update_sign.line4); self.world - .add_block_entity_action(world::BlockEntityAction::UpdateSignText( + .add_block_entity_action(world::BlockEntityAction::UpdateSignText(Box::new(( Position::new(update_sign.x, update_sign.y as i32, update_sign.z), update_sign.line1, update_sign.line2, update_sign.line3, update_sign.line4, - )); + )))); } fn on_player_info_string( diff --git a/src/world/mod.rs b/src/world/mod.rs index 92336e3..7cdb72b 100644 --- a/src/world/mod.rs +++ b/src/world/mod.rs @@ -52,11 +52,13 @@ pub enum BlockEntityAction { Create(Position), Remove(Position), UpdateSignText( - Position, - format::Component, - format::Component, - format::Component, - format::Component, + Box<( + Position, + format::Component, + format::Component, + format::Component, + format::Component, + )>, ), } @@ -240,7 +242,8 @@ impl World { } } } - BlockEntityAction::UpdateSignText(pos, line1, line2, line3, line4) => { + BlockEntityAction::UpdateSignText(bx) => { + let (pos, line1, line2, line3, line4) = *bx; if let Some(chunk) = self.chunks.get(&CPos(pos.x >> 4, pos.z >> 4)) { if let Some(entity) = chunk.block_entities.get(&pos) { if let Some(sign) = m.get_component_mut(*entity, sign_info) { From 7ef173416abd65a849985a79ea19e168fe7d87d1 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Thu, 2 Jul 2020 17:47:12 -0700 Subject: [PATCH 44/49] Suppress needless_range_loop in chunk loading for clarity -- it will always be 16, and this value is not from block_types, blocks_meta, blocks_add, but must be consistent with all variables and is part of the wire protocol --- src/world/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/world/mod.rs b/src/world/mod.rs index 7cdb72b..8abd699 100644 --- a/src/world/mod.rs +++ b/src/world/mod.rs @@ -801,6 +801,7 @@ impl World { ) } + #[allow(clippy::needless_range_loop)] fn load_uncompressed_chunk17( &mut self, x: i32, From 5ce06c3067654509768453ea846a33648fc3d325 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Thu, 2 Jul 2020 17:49:04 -0700 Subject: [PATCH 45/49] Suppress type_complexity, would not be clarified by using a type definition --- src/render/mod.rs | 1 + src/server/target.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/render/mod.rs b/src/render/mod.rs index 5c52e23..49a04a3 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -956,6 +956,7 @@ pub struct TextureManager { impl TextureManager { #[allow(clippy::let_and_return)] + #[allow(clippy::type_complexity)] fn new( res: Arc>, ) -> ( diff --git a/src/server/target.rs b/src/server/target.rs index c8c1ba4..8348e98 100644 --- a/src/server/target.rs +++ b/src/server/target.rs @@ -135,6 +135,7 @@ impl Info { } } +#[allow(clippy::type_complexity)] pub fn test_block( world: &world::World, pos: Position, From 476d46cac6bb8b5d03854c07ed104ea50e6dd5d2 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Thu, 2 Jul 2020 17:51:48 -0700 Subject: [PATCH 46/49] Use into_*(self) convention, fixes wrong_self_convention --- src/server/mod.rs | 4 ++-- src/server/plugin_messages.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/server/mod.rs b/src/server/mod.rs index 24edd36..cb9e682 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -1028,9 +1028,9 @@ impl Server { }; // TODO: refactor with write_plugin_message if self.protocol_version >= 47 { - self.write_packet(brand.as_message()); + self.write_packet(brand.into_message()); } else { - self.write_packet(brand.as_message17()); + self.write_packet(brand.into_message17()); } } diff --git a/src/server/plugin_messages.rs b/src/server/plugin_messages.rs index 0ba269e..e607cbb 100644 --- a/src/server/plugin_messages.rs +++ b/src/server/plugin_messages.rs @@ -7,7 +7,7 @@ pub struct Brand { } impl Brand { - pub fn as_message(self) -> PluginMessageServerbound { + pub fn into_message(self) -> PluginMessageServerbound { let protocol_version = crate::protocol::current_protocol_version(); let channel_name = if protocol_version >= 404 { @@ -25,7 +25,7 @@ impl Brand { } // TODO: cleanup this duplication for 1.7, return either message dynamically - pub fn as_message17(self) -> PluginMessageServerbound_i16 { + pub fn into_message17(self) -> PluginMessageServerbound_i16 { let mut data = vec![]; Serializable::write_to(&self.brand, &mut data).unwrap(); PluginMessageServerbound_i16 { From 9cfb686528326f3ff225eb99ae461a9ff936c1f5 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Thu, 2 Jul 2020 17:58:12 -0700 Subject: [PATCH 47/49] Use cmp match to replace if chain (comparison_chain) --- src/world/mod.rs | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/world/mod.rs b/src/world/mod.rs index 8abd699..ac79281 100644 --- a/src/world/mod.rs +++ b/src/world/mod.rs @@ -25,6 +25,7 @@ use crate::types::hash::FNVHash; use crate::types::{bit, nibble}; use cgmath::prelude::*; use flate2::read::ZlibDecoder; +use std::cmp::Ordering; use std::collections::HashMap; use std::collections::VecDeque; use std::hash::BuildHasherDefault; @@ -1270,20 +1271,24 @@ impl Chunk { } } let idx = ((z << 4) | x) as usize; - if self.heightmap[idx] < y as u8 { - self.heightmap[idx] = y as u8; - self.heightmap_dirty = true; - } else if self.heightmap[idx] == y as u8 { - // Find a new lowest - for yy in 0..y { - let sy = y - yy - 1; - if let block::Air { .. } = self.get_block(x, sy, z) { - continue; - } - self.heightmap[idx] = sy as u8; - break; + match self.heightmap[idx].cmp(&(y as u8)) { + Ordering::Less => { + self.heightmap[idx] = y as u8; + self.heightmap_dirty = true; } - self.heightmap_dirty = true; + Ordering::Equal => { + // Find a new lowest + for yy in 0..y { + let sy = y - yy - 1; + if let block::Air { .. } = self.get_block(x, sy, z) { + continue; + } + self.heightmap[idx] = sy as u8; + break; + } + self.heightmap_dirty = true; + } + Ordering::Greater => (), } true } From 337ee74b22c2bc12ddef27e6432ebdbfcae4ddee Mon Sep 17 00:00:00 2001 From: ice_iix Date: Thu, 2 Jul 2020 18:11:52 -0700 Subject: [PATCH 48/49] Allow verbose bit mask because this is in a performance-critical path, tick(), and it is faster on Intel according to https://rust-lang.github.io/rust-clippy/master/index.html#verbose_bit_mask --- src/world/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/world/mod.rs b/src/world/mod.rs index ac79281..47bd499 100644 --- a/src/world/mod.rs +++ b/src/world/mod.rs @@ -204,6 +204,7 @@ impl World { self.block_entity_actions.push_back(action); } + #[allow(clippy::verbose_bit_mask)] // "llvm generates better code" for updates_performed & 0xFFF "on x86" pub fn tick(&mut self, m: &mut ecs::Manager) { use std::time::Instant; let start = Instant::now(); From bb6d8568792face3a2367d47b9c051681e4809ec Mon Sep 17 00:00:00 2001 From: ice_iix Date: Thu, 2 Jul 2020 18:22:41 -0700 Subject: [PATCH 49/49] Azure: fail on clippy all (deny) --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 0445577..ead5cb8 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -6,7 +6,7 @@ jobs: displayName: "Install build dependencies" condition: eq(variables['Agent.OS'], 'Linux') minrust: 1.44.1 - clippy: + clippy: -D clippy::all resources: repositories: