Skip to content

Commit f9495a3

Browse files
refactor: cargo clippy improvements
1 parent 85e1f08 commit f9495a3

9 files changed

Lines changed: 42 additions & 47 deletions

File tree

src/lua/client/world/mod.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,20 @@ pub fn get_block_state(_lua: &Lua, client: &Client, position: Vec3) -> Result<Op
3232
.map(|block| block.id))
3333
}
3434

35+
#[allow(clippy::cast_possible_truncation)]
3536
pub fn get_fluid_state(lua: &Lua, client: &Client, position: Vec3) -> Result<Option<Table>> {
36-
#[allow(clippy::cast_possible_truncation)]
37-
Ok(
38-
if let Some(state) = client.world().read().get_fluid_state(&BlockPos::new(
39-
position.x as i32,
40-
position.y as i32,
41-
position.z as i32,
42-
)) {
43-
let table = lua.create_table()?;
44-
table.set("kind", state.kind as u8)?;
45-
table.set("amount", state.amount)?;
46-
table.set("falling", state.falling)?;
47-
Some(table)
48-
} else {
49-
None
50-
},
51-
)
37+
let fluid_state = client.world().read().get_fluid_state(&BlockPos::new(
38+
position.x as i32,
39+
position.y as i32,
40+
position.z as i32,
41+
));
42+
Ok(if let Some(state) = fluid_state {
43+
let table = lua.create_table()?;
44+
table.set("kind", state.kind as u8)?;
45+
table.set("amount", state.amount)?;
46+
table.set("falling", state.falling)?;
47+
Some(table)
48+
} else {
49+
None
50+
})
5251
}

src/lua/container/item_stack.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ impl UserData for ItemStack {
7171
}
7272

7373
fn add_methods<M: UserDataMethods<Self>>(m: &mut M) {
74-
m.add_method_mut("split", |_, this, count: u32| {
75-
Ok(ItemStack(this.0.split(count)))
76-
});
74+
m.add_method_mut("split", |_, this, count: u32| Ok(Self(this.0.split(count))));
7775
m.add_method_mut("update_empty", |_, this, (): ()| {
7876
this.0.update_empty();
7977
Ok(())

src/lua/events.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ pub fn register_globals(lua: &Lua, globals: &Table, event_listeners: ListenerMap
1313
move |_, (event_type, callback, optional_id): (String, Function, Option<String>)| {
1414
let m = m.clone();
1515
let id = optional_id.unwrap_or_else(|| {
16-
callback.info().name.unwrap_or(format!(
17-
"anonymous @ {}",
18-
SystemTime::now()
19-
.duration_since(UNIX_EPOCH)
20-
.unwrap_or_default()
21-
.as_millis()
22-
))
16+
callback.info().name.unwrap_or_else(|| {
17+
format!(
18+
"anonymous @ {}",
19+
SystemTime::now()
20+
.duration_since(UNIX_EPOCH)
21+
.unwrap_or_default()
22+
.as_millis()
23+
)
24+
})
2325
});
2426
tokio::spawn(async move {
2527
m.write()
@@ -40,12 +42,10 @@ pub fn register_globals(lua: &Lua, globals: &Table, event_listeners: ListenerMap
4042
let m = m.clone();
4143
tokio::spawn(async move {
4244
let mut m = m.write().await;
43-
let empty = if let Some(listeners) = m.get_mut(&event_type) {
45+
let empty = m.get_mut(&event_type).is_some_and(|listeners| {
4446
listeners.retain(|(id, _)| target_id != *id);
4547
listeners.is_empty()
46-
} else {
47-
false
48-
};
48+
});
4949
if empty {
5050
m.remove(&event_type);
5151
}

src/lua/matrix/room.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,7 @@ impl UserData for Room {
3737
.members(RoomMemberships::all())
3838
.await
3939
.map_err(Error::external)
40-
.map(|members| {
41-
members
42-
.into_iter()
43-
.map(|member| Member(member.clone()))
44-
.collect::<Vec<_>>()
45-
})
40+
.map(|members| members.into_iter().map(Member).collect::<Vec<_>>())
4641
});
4742
m.add_async_method(
4843
"kick_user",

src/lua/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ impl Display for Error {
3838
formatter,
3939
"failed to {}",
4040
match self {
41-
Error::CreateEnv(error) => format!("create environment: {error}"),
42-
Error::EvalChunk(error) => format!("evaluate chunk: {error}"),
43-
Error::ExecChunk(error) => format!("execute chunk: {error}"),
44-
Error::LoadChunk(error) => format!("load chunk: {error}"),
45-
Error::MissingPath(error) => format!("get SCRIPT_PATH global: {error}"),
46-
Error::ReadFile(error) => format!("read script file: {error}"),
41+
Self::CreateEnv(error) => format!("create environment: {error}"),
42+
Self::EvalChunk(error) => format!("evaluate chunk: {error}"),
43+
Self::ExecChunk(error) => format!("execute chunk: {error}"),
44+
Self::LoadChunk(error) => format!("load chunk: {error}"),
45+
Self::MissingPath(error) => format!("get SCRIPT_PATH global: {error}"),
46+
Self::ReadFile(error) => format!("read script file: {error}"),
4747
}
4848
)
4949
}

src/lua/vec3.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl From<&Position> for Vec3 {
4040

4141
impl From<BlockPos> for Vec3 {
4242
fn from(p: BlockPos) -> Self {
43-
Vec3 {
43+
Self {
4444
x: f64::from(p.x),
4545
y: f64::from(p.y),
4646
z: f64::from(p.z),

src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#![feature(if_let_guard, let_chains)]
2+
#![warn(clippy::pedantic, clippy::nursery)]
3+
#![allow(clippy::significant_drop_tightening)]
24

35
mod arguments;
46
mod build_info;

src/particle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use azalea::{entity::particle::Particle, registry::ParticleKind};
22

33
#[allow(clippy::too_many_lines)]
4-
pub fn to_kind(particle: &Particle) -> ParticleKind {
4+
pub const fn to_kind(particle: &Particle) -> ParticleKind {
55
match particle {
66
Particle::AngryVillager => ParticleKind::AngryVillager,
77
Particle::Block(_) => ParticleKind::Block,

src/replay/plugin.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use azalea::{
1212
protocol::packets::login::ClientboundLoginPacket,
1313
raw_connection::RawConnection,
1414
};
15-
use bevy_app::{First, Plugin};
15+
use bevy_app::{App, First, Plugin};
1616
use bevy_ecs::{schedule::IntoSystemConfigs, system::ResMut};
1717
use log::error;
1818
use parking_lot::Mutex;
@@ -24,8 +24,9 @@ pub struct RecordPlugin {
2424
}
2525

2626
impl Plugin for RecordPlugin {
27-
fn build(&self, app: &mut bevy_app::App) {
28-
if let Some(recorder) = self.recorder.lock().take() {
27+
fn build(&self, app: &mut App) {
28+
let recorder = self.recorder.lock().take();
29+
if let Some(recorder) = recorder {
2930
app.insert_resource(recorder)
3031
.add_systems(First, record_login_packets.before(process_packet_events))
3132
.add_systems(First, record_configuration_packets)

0 commit comments

Comments
 (0)