Skip to content

Commit 89cca38

Browse files
committed
A bunch of clippy fixes
1 parent 470f87d commit 89cca38

File tree

16 files changed

+63
-56
lines changed

16 files changed

+63
-56
lines changed

src/lib/adapters/nbt/benches/ferrumc-nbt.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ mod structs {
1717
pub(crate) z_pos: i32,
1818
#[nbt(rename = "Heightmaps")]
1919
pub(crate) heightmaps: Heightmaps<'a>,
20-
sections: Vec<Section<'a>>,
20+
_sections: Vec<Section<'a>>,
2121
}
2222

2323
#[derive(NBTDeserialize)]
@@ -29,20 +29,20 @@ mod structs {
2929
#[derive(NBTDeserialize)]
3030
pub(super) struct Section<'a> {
3131
#[nbt(rename = "Y")]
32-
y: i8,
33-
block_states: Option<BlockState<'a>>,
32+
_y: i8,
33+
_block_states: Option<BlockState<'a>>,
3434
}
3535

3636
#[derive(NBTDeserialize)]
3737
pub(super) struct BlockState<'a> {
38-
pub(crate) data: Option<&'a [i64]>,
39-
pub(crate) palette: Vec<Palette<'a>>,
38+
pub(crate) _data: Option<&'a [i64]>,
39+
pub(crate) _palette: Vec<Palette<'a>>,
4040
}
4141

4242
#[derive(NBTDeserialize)]
4343
pub(super) struct Palette<'a> {
4444
#[nbt(rename = "Name")]
45-
pub(crate) name: &'a str,
45+
pub(crate) _name: &'a str,
4646
}
4747
}
4848
fn bench_ferrumc_nbt(data: &[u8]) {
@@ -76,7 +76,7 @@ fn bench_simdnbt(data: &[u8]) {
7676
.unwrap()
7777
.into_iter()
7878
.filter_map(|section| {
79-
let y = section.get("Y").unwrap().byte().unwrap();
79+
let _ = section.get("Y").unwrap().byte().unwrap();
8080
let block_states = section.get("block_states")?;
8181
let block_states = block_states.compound().unwrap();
8282
let data = block_states.get("data")?;
@@ -92,12 +92,12 @@ fn bench_simdnbt(data: &[u8]) {
9292
let str = name.to_str();
9393
let name = str.as_ref();
9494
let name = Box::leak(name.to_string().into_boxed_str());
95-
Palette { name }
95+
Palette { _name: name }
9696
})
9797
.collect();
9898
Some(BlockState {
99-
data: Some(data),
100-
palette,
99+
_data: Some(data),
100+
_palette: palette,
101101
})
102102
})
103103
.collect::<Vec<_>>();

src/lib/adapters/nbt/src/de/borrow.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ impl<'a> NbtTape<'a> {
292292
}
293293
}
294294
}
295-
impl<'a> NbtTape<'a> {
295+
impl NbtTape<'_> {
296296
/// Skips over a single tag based on its type.
297297
fn skip_tag(&mut self, tag: u8) -> usize {
298298
let start_pos = self.pos;
@@ -391,71 +391,71 @@ pub trait NbtDeserializable<'a>: Sized {
391391

392392
mod primitives {
393393
use super::NbtDeserializable;
394-
impl<'a> NbtDeserializable<'a> for i8 {
394+
impl NbtDeserializable<'_> for i8 {
395395
fn parse_from_bytes(data: &[u8]) -> Self {
396396
data[0] as i8
397397
}
398398
}
399-
impl<'a> NbtDeserializable<'a> for u8 {
399+
impl NbtDeserializable<'_> for u8 {
400400
fn parse_from_bytes(data: &[u8]) -> Self {
401401
u8::from_be_bytes([data[0]])
402402
}
403403
}
404-
impl<'a> NbtDeserializable<'a> for i16 {
404+
impl NbtDeserializable<'_> for i16 {
405405
fn parse_from_bytes(data: &[u8]) -> Self {
406406
i16::from_be_bytes([data[0], data[1]])
407407
}
408408
}
409409

410-
impl<'a> NbtDeserializable<'a> for u16 {
410+
impl NbtDeserializable<'_> for u16 {
411411
fn parse_from_bytes(data: &[u8]) -> Self {
412412
u16::from_be_bytes([data[0], data[1]])
413413
}
414414
}
415415

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

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

428-
impl<'a> NbtDeserializable<'a> for i64 {
428+
impl NbtDeserializable<'_> for i64 {
429429
fn parse_from_bytes(data: &[u8]) -> Self {
430430
i64::from_be_bytes([
431431
data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7],
432432
])
433433
}
434434
}
435435

436-
impl<'a> NbtDeserializable<'a> for u64 {
436+
impl NbtDeserializable<'_> for u64 {
437437
fn parse_from_bytes(data: &[u8]) -> Self {
438438
u64::from_be_bytes([
439439
data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7],
440440
])
441441
}
442442
}
443443

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

450-
impl<'a> NbtDeserializable<'a> for f64 {
450+
impl NbtDeserializable<'_> for f64 {
451451
fn parse_from_bytes(data: &[u8]) -> Self {
452452
f64::from_be_bytes([
453453
data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7],
454454
])
455455
}
456456
}
457457

458-
impl<'a> NbtDeserializable<'a> for bool {
458+
impl NbtDeserializable<'_> for bool {
459459
fn parse_from_bytes(data: &[u8]) -> Self {
460460
data[0] != 0
461461
}
@@ -621,7 +621,7 @@ impl<'a> NetEncode for NbtTape<'a> {
621621
}
622622

623623

624-
impl<'a> NbtTapeElement<'a> {
624+
impl NbtTapeElement<'_> {
625625
pub fn serialize_as_network(&self, tape: &mut NbtTape, writer: &mut Vec<u8>, opts: &NBTSerializeOptions) -> NetEncodeResult<()> {
626626
/*if let NBTSerializeOptions::WithHeader(name) = opts {
627627
writer.write_all(&[self.nbt_id()])?;

src/lib/adapters/nbt/src/ser/impl.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl<T: NBTSerializable + std::fmt::Debug> NBTSerializable for Vec<T> {
9090
}
9191
}
9292

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

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

150150
impl<T: NBTSerializable> NBTSerializable for Option<T> {
151151
fn serialize(&self, buf: &mut Vec<u8>, options: &NBTSerializeOptions<'_>) {
152-
match self {
153-
Some(value) => {
154-
value.serialize(buf, options);
155-
}
156-
None => {}
152+
if let Some(value) = self {
153+
value.serialize(buf, options);
157154
}
158155
}
159156

src/lib/ecs/src/components/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl ComponentStorage {
3838
let mut components = self
3939
.components
4040
.entry(type_id)
41-
.or_insert_with(SparseSet::new);
41+
.or_default();
4242
components.insert(entity, RwLock::new(Box::new(component)));
4343
}
4444

@@ -127,36 +127,36 @@ mod debug {
127127
use std::fmt::Debug;
128128
use crate::components::{Component, ComponentRef, ComponentRefMut};
129129

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

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

143-
impl<'a, T: Component> Deref for ComponentRef<'a, T> {
143+
impl<T: Component> Deref for ComponentRef<'_, T> {
144144
type Target = T;
145145

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

151-
impl<'a, T: Component> Deref for ComponentRefMut<'a, T> {
151+
impl<T: Component> Deref for ComponentRefMut<'_, T> {
152152
type Target = T;
153153

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

159-
impl<'a, T: Component> DerefMut for ComponentRefMut<'a, T> {
159+
impl<T: Component> DerefMut for ComponentRefMut<'_, T> {
160160
fn deref_mut(&mut self) -> &mut Self::Target {
161161
unsafe { &mut *(&mut **self.write_guard as *mut dyn Component as *mut T) }
162162
}

src/lib/ecs/src/components/sparse_set.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ pub struct SparseSet<T> {
99
indices: HashMap<Entity, usize>,
1010
}
1111

12+
impl<T> Default for SparseSet<T> {
13+
fn default() -> Self {
14+
Self::new()
15+
}
16+
}
17+
1218
impl<T> SparseSet<T> {
1319
pub fn new() -> Self {
1420
SparseSet {

src/lib/ecs/src/query.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub struct Query<'a, Q: QueryItem> {
5858
_marker: std::marker::PhantomData<Q>,
5959
}
6060

61-
impl<'a, Q: QueryItem> Clone for Query<'a, Q> {
61+
impl<Q: QueryItem> Clone for Query<'_, Q> {
6262
fn clone(&self) -> Self {
6363
//! Clones the query, and re-calculates the entities
6464
Self {

src/lib/ecs/src/tests/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rayon::prelude::*;
77

88

99
#[derive(Debug)]
10+
#[expect(dead_code)]
1011
struct Position {
1112
x: u32,
1213
y: u32,
@@ -15,6 +16,7 @@ struct Position {
1516
unsafe impl Send for Position {}
1617

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

3840
let start = Instant::now();
39-
ParallelIterator::for_each(query.into_par_iter(), |(player, position)| {
41+
ParallelIterator::for_each(query.into_par_iter(), |(_player, position)| {
4042
let sleep_duration = Duration::from_millis(100 * (position.x as u64));
4143
thread::sleep(sleep_duration);
4244
});

src/lib/events/src/infrastructure.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ pub trait Event: Sized + Send + Sync + 'static {
159159
Ok(())
160160
}
161161
*/
162-
/// Register a a new event listener for this event
162+
/// Register a new event listener for this event
163163
fn register(listener: AsyncEventListener<Self>, priority: u8) {
164164
// Create the event listener structure
165165
let listener = EventListener::<Self> { listener, priority };

src/lib/events/src/tests/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub enum SomeEventError {}
1717

1818
impl Event for SomeEvent {
1919
type Data = Self;
20+
type State = ();
2021

2122
type Error = SomeEventError;
2223

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

32-
SomeEvent::trigger(event_data).await.unwrap();
33+
SomeEvent::trigger(event_data, ()).await.unwrap();
3334
}
3435

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

5758
#[ctor::ctor]
5859
fn __register_some_event_listener() {
59-
SomeEvent::register(|ev: SomeEvent| Box::pin(some_event_listener(ev)), 0);
60+
SomeEvent::register(|ev: SomeEvent, _: ()| Box::pin(some_event_listener(ev)), 0);
6061
}
6162

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

6869
#[ctor::ctor]
6970
fn __register_some_event_listener2() {
70-
SomeEvent::register(|ev: SomeEvent| Box::pin(some_event_listener2(ev)), 255);
71+
SomeEvent::register(|ev: SomeEvent, _: ()| Box::pin(some_event_listener2(ev)), 255);
7172
}
7273

7374
async fn some_event_listener2(event: SomeEvent) -> Result<SomeEvent, SomeEventError> {

src/lib/net/src/packets/outgoing/client_bound_known_packs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ pub struct Pack<'a> {
1616
pub version: &'a str,
1717
}
1818

19-
impl<'a> Default for ClientBoundKnownPacksPacket<'a> {
19+
impl Default for ClientBoundKnownPacksPacket<'_> {
2020
fn default() -> Self {
2121
Self::new()
2222
}
2323
}
2424

25-
impl<'a> ClientBoundKnownPacksPacket<'a> {
25+
impl ClientBoundKnownPacksPacket<'_> {
2626
pub fn new() -> Self {
2727
Self {
2828
packs: LengthPrefixedVec::new(vec![Pack::new("minecraft", "core", "1.21")]),

src/lib/net/src/packets/outgoing/login_play.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub struct LoginPlayPacket<'a> {
3030
pub enforces_secure_chat: bool,
3131
}
3232

33-
impl<'a> LoginPlayPacket<'a> {
33+
impl LoginPlayPacket<'_> {
3434
pub fn new(conn_id: usize) -> Self {
3535
Self {
3636
entity_id: conn_id as i32,

src/lib/net/src/packets/outgoing/registry_data.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub struct RegistryEntry<'a> {
2727
pub data: Vec<u8>,
2828
}
2929

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

83-
use ferrumc_nbt::NbtTape;
83+
use ferrumc_nbt::{NBTSerializeOptions, NbtTape};
8484
use ferrumc_net_codec::encode::{NetEncode, NetEncodeOpts};
8585
use tracing::debug;
8686

@@ -1235,7 +1235,7 @@ mod tests {
12351235
let has_data = true;
12361236
let mut data = vec![];
12371237
element
1238-
.serialize_as_network(&mut rewind_machine, &mut data)
1238+
.serialize_as_network(&mut rewind_machine, &mut data, &NBTSerializeOptions::Network)
12391239
.unwrap_or_else(|_| {
12401240
panic!("Failed to serialize entry for {}", registry_id)
12411241
});

src/lib/storage/src/backends/surrealkv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ impl DatabaseBackend for SurrealKVBackend {
182182
async fn create_table(&mut self, _: String) -> Result<(), StorageError> {
183183
Ok(())
184184
}
185+
#[expect(clippy::await_holding_lock)]
185186
async fn close(&mut self) -> Result<(), StorageError> {
186-
#[allow(clippy::await_holding_lock)]
187187
let write_guard = self.db.write();
188188
let res = write_guard.close().await;
189189
drop(write_guard);

src/lib/utils/config/src/server_config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ impl ServerConfig {
164164
std::io::stdin().read_line(&mut input)?;
165165

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

0 commit comments

Comments
 (0)