From 98224cf91337aa312b72de87ea4c1b22794619b2 Mon Sep 17 00:00:00 2001 From: mat Date: Sat, 15 Oct 2022 16:53:34 -0500 Subject: [PATCH] fix clippy warnings --- azalea-buf/src/read.rs | 2 +- azalea-chat/src/style.rs | 16 ++-------------- azalea-nbt/src/decode.rs | 4 ++-- .../src/collision/discrete_voxel_shape.rs | 3 +-- azalea-protocol/src/read.rs | 2 +- azalea-protocol/src/write.rs | 2 +- azalea-world/src/bit_storage.rs | 14 +++++++------- azalea-world/src/entity/data.rs | 2 +- azalea-world/src/palette.rs | 4 ++-- 9 files changed, 18 insertions(+), 31 deletions(-) diff --git a/azalea-buf/src/read.rs b/azalea-buf/src/read.rs index 575066c4..b387dcfb 100644 --- a/azalea-buf/src/read.rs +++ b/azalea-buf/src/read.rs @@ -57,7 +57,7 @@ fn read_bytes<'a>(buf: &'a mut Cursor<&[u8]>, length: usize) -> Result<&'a [u8], fn read_utf_with_len(buf: &mut Cursor<&[u8]>, max_length: u32) -> Result { let length = u32::var_read_from(buf)?; // i don't know why it's multiplied by 4 but it's like that in mojang's code so - if length as u32 > max_length * 4 { + if length > max_length * 4 { return Err(BufReadError::StringLengthTooLong { length, max_length: max_length * 4, diff --git a/azalea-chat/src/style.rs b/azalea-chat/src/style.rs index 6edcdc2d..6422d5e4 100755 --- a/azalea-chat/src/style.rs +++ b/azalea-chat/src/style.rs @@ -274,7 +274,7 @@ impl TryFrom for TextColor { } } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Default)] pub struct Style { // these are options instead of just bools because None is different than false in this case pub color: Option, @@ -288,20 +288,8 @@ pub struct Style { } impl Style { - pub fn default() -> Self { - Self::empty() - } - pub fn empty() -> Self { - Self { - color: None, - bold: None, - italic: None, - underlined: None, - strikethrough: None, - obfuscated: None, - reset: false, - } + Self::default() } pub fn deserialize(json: &Value) -> Style { diff --git a/azalea-nbt/src/decode.rs b/azalea-nbt/src/decode.rs index a811bb1f..6937dc05 100755 --- a/azalea-nbt/src/decode.rs +++ b/azalea-nbt/src/decode.rs @@ -98,7 +98,7 @@ impl Tag { if length * 4 > (stream.get_ref().len() - stream.position() as usize) { return Err(Error::UnexpectedEof); } - let mut ints = Vec::with_capacity(length as usize); + let mut ints = Vec::with_capacity(length); for _ in 0..length { ints.push(stream.read_i32::()?); } @@ -111,7 +111,7 @@ impl Tag { if length * 8 > (stream.get_ref().len() - stream.position() as usize) { return Err(Error::UnexpectedEof); } - let mut longs = Vec::with_capacity(length as usize); + let mut longs = Vec::with_capacity(length); for _ in 0..length { longs.push(stream.read_i64::()?); } diff --git a/azalea-physics/src/collision/discrete_voxel_shape.rs b/azalea-physics/src/collision/discrete_voxel_shape.rs index 2be1e9b7..51d45316 100644 --- a/azalea-physics/src/collision/discrete_voxel_shape.rs +++ b/azalea-physics/src/collision/discrete_voxel_shape.rs @@ -338,8 +338,7 @@ impl From<&DiscreteVoxelShape> for BitSetDiscreteVoxelShape { for y in 0..y_size { for z in 0..z_size { if shape.is_full(x, y, z) { - storage - .set(Self::get_index_from_size(x, y, z, y_size, z_size) as usize); + storage.set(Self::get_index_from_size(x, y, z, y_size, z_size)); } } } diff --git a/azalea-protocol/src/read.rs b/azalea-protocol/src/read.rs index 16820846..8d8bc731 100644 --- a/azalea-protocol/src/read.rs +++ b/azalea-protocol/src/read.rs @@ -106,7 +106,7 @@ fn parse_frame(buffer: &mut BytesMut) -> Result { Ok(data) } -fn frame_splitter<'a>(buffer: &'a mut BytesMut) -> Result>, FrameSplitterError> { +fn frame_splitter(buffer: &mut BytesMut) -> Result>, FrameSplitterError> { // https://tokio.rs/tokio/tutorial/framing let read_frame = parse_frame(buffer); match read_frame { diff --git a/azalea-protocol/src/write.rs b/azalea-protocol/src/write.rs index a04979a5..9df54f4d 100755 --- a/azalea-protocol/src/write.rs +++ b/azalea-protocol/src/write.rs @@ -29,7 +29,7 @@ fn packet_encoder( packet: &P, ) -> Result, PacketEncodeError> { let mut buf = Vec::new(); - (packet.id() as u32).var_write_into(&mut buf)?; + packet.id().var_write_into(&mut buf)?; packet.write(&mut buf)?; if buf.len() > MAXIMUM_UNCOMPRESSED_LENGTH as usize { return Err(PacketEncodeError::TooBig { diff --git a/azalea-world/src/bit_storage.rs b/azalea-world/src/bit_storage.rs index 2626c312..113f23bc 100644 --- a/azalea-world/src/bit_storage.rs +++ b/azalea-world/src/bit_storage.rs @@ -120,21 +120,21 @@ impl BitStorage { let values_per_long = 64 / bits; let magic_index = values_per_long - 1; - let (divide_mul, divide_add, divide_shift) = MAGIC[magic_index as usize]; + let (divide_mul, divide_add, divide_shift) = MAGIC[magic_index]; let calculated_length = (size + values_per_long - 1) / values_per_long; let mask = (1 << bits) - 1; let using_data = if let Some(data) = data { - if data.len() != calculated_length as usize { + if data.len() != calculated_length { return Err(BitStorageError::InvalidLength { got: data.len(), - expected: calculated_length as usize, + expected: calculated_length, }); } data } else { - vec![0; calculated_length as usize] + vec![0; calculated_length] }; Ok(BitStorage { @@ -179,7 +179,7 @@ impl BitStorage { } let cell_index = self.cell_index(index as u64); - let cell = &self.data[cell_index as usize]; + let cell = &self.data[cell_index]; let bit_index = (index - cell_index * self.values_per_long as usize) * self.bits; cell >> bit_index & self.mask } @@ -193,7 +193,7 @@ impl BitStorage { assert!(index < self.size); assert!(value <= self.mask); let cell_index = self.cell_index(index as u64); - let cell = &mut self.data[cell_index as usize]; + let cell = &mut self.data[cell_index]; let bit_index = (index - cell_index * self.values_per_long as usize) * self.bits; let old_value = *cell >> (bit_index as u64) & self.mask; *cell = *cell & !(self.mask << bit_index) | (value & self.mask) << bit_index; @@ -209,7 +209,7 @@ impl BitStorage { assert!(index < self.size); assert!(value <= self.mask); let cell_index = self.cell_index(index as u64); - let cell = &mut self.data[cell_index as usize]; + let cell = &mut self.data[cell_index]; let bit_index = (index - cell_index * self.values_per_long as usize) * self.bits; *cell = *cell & !(self.mask << bit_index) | (value & self.mask) << bit_index; } diff --git a/azalea-world/src/entity/data.rs b/azalea-world/src/entity/data.rs index 3fd07ecb..0f90c790 100644 --- a/azalea-world/src/entity/data.rs +++ b/azalea-world/src/entity/data.rs @@ -110,7 +110,7 @@ impl McBufReadable for EntityDataValue { if val == 0 { None } else { - Some((val - 1) as u32) + Some(val - 1) } }), 18 => EntityDataValue::Pose(Pose::read_from(buf)?), diff --git a/azalea-world/src/palette.rs b/azalea-world/src/palette.rs index a467ea93..ef445541 100644 --- a/azalea-world/src/palette.rs +++ b/azalea-world/src/palette.rs @@ -149,7 +149,7 @@ impl PalettedContainer { } Palette::Linear(palette) => { if let Some(index) = palette.iter().position(|v| *v == value) { - return index as usize; + return index; } let capacity = 2usize.pow(self.bits_per_entry.into()); if capacity > palette.len() { @@ -162,7 +162,7 @@ impl PalettedContainer { Palette::Hashmap(palette) => { // TODO? vanilla keeps this in memory as a hashmap, but also i don't care if let Some(index) = palette.iter().position(|v| *v == value) { - return index as usize; + return index; } let capacity = 2usize.pow(self.bits_per_entry.into()); if capacity > palette.len() {