Skip to content

Commit

Permalink
A bunch of clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ReCore-sys committed Oct 22, 2024
1 parent 470f87d commit 89cca38
Show file tree
Hide file tree
Showing 16 changed files with 63 additions and 56 deletions.
20 changes: 10 additions & 10 deletions src/lib/adapters/nbt/benches/ferrumc-nbt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ mod structs {
pub(crate) z_pos: i32,
#[nbt(rename = "Heightmaps")]
pub(crate) heightmaps: Heightmaps<'a>,
sections: Vec<Section<'a>>,
_sections: Vec<Section<'a>>,
}

#[derive(NBTDeserialize)]
Expand All @@ -29,20 +29,20 @@ mod structs {
#[derive(NBTDeserialize)]
pub(super) struct Section<'a> {
#[nbt(rename = "Y")]
y: i8,
block_states: Option<BlockState<'a>>,
_y: i8,
_block_states: Option<BlockState<'a>>,
}

#[derive(NBTDeserialize)]
pub(super) struct BlockState<'a> {
pub(crate) data: Option<&'a [i64]>,
pub(crate) palette: Vec<Palette<'a>>,
pub(crate) _data: Option<&'a [i64]>,
pub(crate) _palette: Vec<Palette<'a>>,
}

#[derive(NBTDeserialize)]
pub(super) struct Palette<'a> {
#[nbt(rename = "Name")]
pub(crate) name: &'a str,
pub(crate) _name: &'a str,
}
}
fn bench_ferrumc_nbt(data: &[u8]) {
Expand Down Expand Up @@ -76,7 +76,7 @@ fn bench_simdnbt(data: &[u8]) {
.unwrap()
.into_iter()
.filter_map(|section| {
let y = section.get("Y").unwrap().byte().unwrap();
let _ = section.get("Y").unwrap().byte().unwrap();
let block_states = section.get("block_states")?;
let block_states = block_states.compound().unwrap();
let data = block_states.get("data")?;
Expand All @@ -92,12 +92,12 @@ fn bench_simdnbt(data: &[u8]) {
let str = name.to_str();
let name = str.as_ref();
let name = Box::leak(name.to_string().into_boxed_str());
Palette { name }
Palette { _name: name }
})
.collect();
Some(BlockState {
data: Some(data),
palette,
_data: Some(data),
_palette: palette,
})
})
.collect::<Vec<_>>();
Expand Down
26 changes: 13 additions & 13 deletions src/lib/adapters/nbt/src/de/borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ impl<'a> NbtTape<'a> {
}
}
}
impl<'a> NbtTape<'a> {
impl NbtTape<'_> {
/// Skips over a single tag based on its type.
fn skip_tag(&mut self, tag: u8) -> usize {
let start_pos = self.pos;
Expand Down Expand Up @@ -391,71 +391,71 @@ pub trait NbtDeserializable<'a>: Sized {

mod primitives {
use super::NbtDeserializable;
impl<'a> NbtDeserializable<'a> for i8 {
impl NbtDeserializable<'_> for i8 {
fn parse_from_bytes(data: &[u8]) -> Self {
data[0] as i8
}
}
impl<'a> NbtDeserializable<'a> for u8 {
impl NbtDeserializable<'_> for u8 {
fn parse_from_bytes(data: &[u8]) -> Self {
u8::from_be_bytes([data[0]])
}
}
impl<'a> NbtDeserializable<'a> for i16 {
impl NbtDeserializable<'_> for i16 {
fn parse_from_bytes(data: &[u8]) -> Self {
i16::from_be_bytes([data[0], data[1]])
}
}

impl<'a> NbtDeserializable<'a> for u16 {
impl NbtDeserializable<'_> for u16 {
fn parse_from_bytes(data: &[u8]) -> Self {
u16::from_be_bytes([data[0], data[1]])
}
}

impl<'a> NbtDeserializable<'a> for i32 {
impl NbtDeserializable<'_> for i32 {
fn parse_from_bytes(data: &[u8]) -> Self {
i32::from_be_bytes([data[0], data[1], data[2], data[3]])
}
}

impl<'a> NbtDeserializable<'a> for u32 {
impl NbtDeserializable<'_> for u32 {
fn parse_from_bytes(data: &[u8]) -> Self {
u32::from_be_bytes([data[0], data[1], data[2], data[3]])
}
}

impl<'a> NbtDeserializable<'a> for i64 {
impl NbtDeserializable<'_> for i64 {
fn parse_from_bytes(data: &[u8]) -> Self {
i64::from_be_bytes([
data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7],
])
}
}

impl<'a> NbtDeserializable<'a> for u64 {
impl NbtDeserializable<'_> for u64 {
fn parse_from_bytes(data: &[u8]) -> Self {
u64::from_be_bytes([
data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7],
])
}
}

impl<'a> NbtDeserializable<'a> for f32 {
impl NbtDeserializable<'_> for f32 {
fn parse_from_bytes(data: &[u8]) -> Self {
f32::from_be_bytes([data[0], data[1], data[2], data[3]])
}
}

impl<'a> NbtDeserializable<'a> for f64 {
impl NbtDeserializable<'_> for f64 {
fn parse_from_bytes(data: &[u8]) -> Self {
f64::from_be_bytes([
data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7],
])
}
}

impl<'a> NbtDeserializable<'a> for bool {
impl NbtDeserializable<'_> for bool {
fn parse_from_bytes(data: &[u8]) -> Self {
data[0] != 0
}
Expand Down Expand Up @@ -621,7 +621,7 @@ impl<'a> NetEncode for NbtTape<'a> {
}


impl<'a> NbtTapeElement<'a> {
impl NbtTapeElement<'_> {
pub fn serialize_as_network(&self, tape: &mut NbtTape, writer: &mut Vec<u8>, opts: &NBTSerializeOptions) -> NetEncodeResult<()> {
/*if let NBTSerializeOptions::WithHeader(name) = opts {
writer.write_all(&[self.nbt_id()])?;
Expand Down
9 changes: 3 additions & 6 deletions src/lib/adapters/nbt/src/ser/impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl<T: NBTSerializable + std::fmt::Debug> NBTSerializable for Vec<T> {
}
}

impl<'a, T: NBTSerializable> NBTSerializable for &'a [T] {
impl<T: NBTSerializable> NBTSerializable for &'_ [T] {
fn serialize(&self, buf: &mut Vec<u8>, options: &NBTSerializeOptions<'_>) {
write_header::<Self>(buf, options);

Expand Down Expand Up @@ -149,11 +149,8 @@ impl<'a, T: NBTSerializable> NBTSerializable for &'a [T] {

impl<T: NBTSerializable> NBTSerializable for Option<T> {
fn serialize(&self, buf: &mut Vec<u8>, options: &NBTSerializeOptions<'_>) {
match self {
Some(value) => {
value.serialize(buf, options);
}
None => {}
if let Some(value) = self {
value.serialize(buf, options);
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/lib/ecs/src/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl ComponentStorage {
let mut components = self
.components
.entry(type_id)
.or_insert_with(SparseSet::new);
.or_default();
components.insert(entity, RwLock::new(Box::new(component)));
}

Expand Down Expand Up @@ -127,36 +127,36 @@ mod debug {
use std::fmt::Debug;
use crate::components::{Component, ComponentRef, ComponentRefMut};

impl<'a, T: Component + Debug> Debug for ComponentRef<'a, T> {
impl<T: Component + Debug> Debug for ComponentRef<'_, T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Debug::fmt(&**self, f)
}
}

impl<'a, T: Component + Debug> Debug for ComponentRefMut<'a, T> {
impl<T: Component + Debug> Debug for ComponentRefMut<'_, T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Debug::fmt(&**self, f)
}
}
}

impl<'a, T: Component> Deref for ComponentRef<'a, T> {
impl<T: Component> Deref for ComponentRef<'_, T> {
type Target = T;

fn deref(&self) -> &Self::Target {
unsafe { &*(&**self.read_guard as *const dyn Component as *const T) }
}
}

impl<'a, T: Component> Deref for ComponentRefMut<'a, T> {
impl<T: Component> Deref for ComponentRefMut<'_, T> {
type Target = T;

fn deref(&self) -> &Self::Target {
unsafe { &*(&**self.write_guard as *const dyn Component as *const T) }
}
}

impl<'a, T: Component> DerefMut for ComponentRefMut<'a, T> {
impl<T: Component> DerefMut for ComponentRefMut<'_, T> {
fn deref_mut(&mut self) -> &mut Self::Target {
unsafe { &mut *(&mut **self.write_guard as *mut dyn Component as *mut T) }
}
Expand Down
6 changes: 6 additions & 0 deletions src/lib/ecs/src/components/sparse_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ pub struct SparseSet<T> {
indices: HashMap<Entity, usize>,
}

impl<T> Default for SparseSet<T> {
fn default() -> Self {
Self::new()
}
}

impl<T> SparseSet<T> {
pub fn new() -> Self {
SparseSet {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/ecs/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub struct Query<'a, Q: QueryItem> {
_marker: std::marker::PhantomData<Q>,
}

impl<'a, Q: QueryItem> Clone for Query<'a, Q> {
impl<Q: QueryItem> Clone for Query<'_, Q> {
fn clone(&self) -> Self {
//! Clones the query, and re-calculates the entities
Self {
Expand Down
4 changes: 3 additions & 1 deletion src/lib/ecs/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use rayon::prelude::*;


#[derive(Debug)]
#[expect(dead_code)]
struct Position {
x: u32,
y: u32,
Expand All @@ -15,6 +16,7 @@ struct Position {
unsafe impl Send for Position {}

#[derive(Debug)]
#[expect(dead_code)]
struct Player {
username: String,
}
Expand All @@ -36,7 +38,7 @@ fn test_basic() {
let query = Query::<(&Player, &mut Position)>::new(&component_storage);

let start = Instant::now();
ParallelIterator::for_each(query.into_par_iter(), |(player, position)| {
ParallelIterator::for_each(query.into_par_iter(), |(_player, position)| {
let sleep_duration = Duration::from_millis(100 * (position.x as u64));
thread::sleep(sleep_duration);
});
Expand Down
2 changes: 1 addition & 1 deletion src/lib/events/src/infrastructure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ pub trait Event: Sized + Send + Sync + 'static {
Ok(())
}
*/
/// Register a a new event listener for this event
/// Register a new event listener for this event
fn register(listener: AsyncEventListener<Self>, priority: u8) {
// Create the event listener structure
let listener = EventListener::<Self> { listener, priority };
Expand Down
7 changes: 4 additions & 3 deletions src/lib/events/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub enum SomeEventError {}

impl Event for SomeEvent {
type Data = Self;
type State = ();

type Error = SomeEventError;

Expand All @@ -29,7 +30,7 @@ impl Event for SomeEvent {
async fn test_something() {
let event_data = SomeEvent { data: 0 };

SomeEvent::trigger(event_data).await.unwrap();
SomeEvent::trigger(event_data, ()).await.unwrap();
}

// #[ctor::ctor]
Expand All @@ -56,7 +57,7 @@ async fn test_something() {

#[ctor::ctor]
fn __register_some_event_listener() {
SomeEvent::register(|ev: SomeEvent| Box::pin(some_event_listener(ev)), 0);
SomeEvent::register(|ev: SomeEvent, _: ()| Box::pin(some_event_listener(ev)), 0);
}

async fn some_event_listener(mut event: SomeEvent) -> Result<SomeEvent, SomeEventError> {
Expand All @@ -67,7 +68,7 @@ async fn some_event_listener(mut event: SomeEvent) -> Result<SomeEvent, SomeEven

#[ctor::ctor]
fn __register_some_event_listener2() {
SomeEvent::register(|ev: SomeEvent| Box::pin(some_event_listener2(ev)), 255);
SomeEvent::register(|ev: SomeEvent, _: ()| Box::pin(some_event_listener2(ev)), 255);
}

async fn some_event_listener2(event: SomeEvent) -> Result<SomeEvent, SomeEventError> {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/net/src/packets/outgoing/client_bound_known_packs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ pub struct Pack<'a> {
pub version: &'a str,
}

impl<'a> Default for ClientBoundKnownPacksPacket<'a> {
impl Default for ClientBoundKnownPacksPacket<'_> {
fn default() -> Self {
Self::new()
}
}

impl<'a> ClientBoundKnownPacksPacket<'a> {
impl ClientBoundKnownPacksPacket<'_> {
pub fn new() -> Self {
Self {
packs: LengthPrefixedVec::new(vec![Pack::new("minecraft", "core", "1.21")]),
Expand Down
2 changes: 1 addition & 1 deletion src/lib/net/src/packets/outgoing/login_play.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub struct LoginPlayPacket<'a> {
pub enforces_secure_chat: bool,
}

impl<'a> LoginPlayPacket<'a> {
impl LoginPlayPacket<'_> {
pub fn new(conn_id: usize) -> Self {
Self {
entity_id: conn_id as i32,
Expand Down
6 changes: 3 additions & 3 deletions src/lib/net/src/packets/outgoing/registry_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub struct RegistryEntry<'a> {
pub data: Vec<u8>,
}

impl<'a> RegistryDataPacket<'a> {
impl RegistryDataPacket<'_> {
// TODO: bake this. and make it return just the bytes instead.
pub fn get_registry_packets() -> Vec<Self> {
let registry_nbt_buf = include_bytes!("../../../../../../.etc/registry.nbt");
Expand Down Expand Up @@ -80,7 +80,7 @@ pub const fn get_registry_packets() -> &'static [u8] {
mod tests {
use std::io::Write;

use ferrumc_nbt::NbtTape;
use ferrumc_nbt::{NBTSerializeOptions, NbtTape};
use ferrumc_net_codec::encode::{NetEncode, NetEncodeOpts};
use tracing::debug;

Expand Down Expand Up @@ -1235,7 +1235,7 @@ mod tests {
let has_data = true;
let mut data = vec![];
element
.serialize_as_network(&mut rewind_machine, &mut data)
.serialize_as_network(&mut rewind_machine, &mut data, &NBTSerializeOptions::Network)
.unwrap_or_else(|_| {
panic!("Failed to serialize entry for {}", registry_id)
});
Expand Down
2 changes: 1 addition & 1 deletion src/lib/storage/src/backends/surrealkv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ impl DatabaseBackend for SurrealKVBackend {
async fn create_table(&mut self, _: String) -> Result<(), StorageError> {
Ok(())
}
#[expect(clippy::await_holding_lock)]
async fn close(&mut self) -> Result<(), StorageError> {
#[allow(clippy::await_holding_lock)]
let write_guard = self.db.write();
let res = write_guard.close().await;
drop(write_guard);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/utils/config/src/server_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl ServerConfig {
std::io::stdin().read_line(&mut input)?;

// If the user enters "y", create a new configuration file.
if input.trim().to_ascii_lowercase() == "y" {
if input.trim().eq_ignore_ascii_case("y") {
// Backup the old configuration file.
std::fs::rename(&path, "config.toml.bak")?;

Expand Down
Loading

0 comments on commit 89cca38

Please sign in to comment.