Skip to content

Commit 67bc206

Browse files
authored
Clippy 1.59 (#541)
* Fixed clippy 1.59 lints * cargo fmt
1 parent 4d756b3 commit 67bc206

File tree

8 files changed

+21
-16
lines changed

8 files changed

+21
-16
lines changed

feather/common/src/world.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ impl ChunkMap {
199199
/// Retrieves a handle to the chunk at the given
200200
/// position, or `None` if it is not loaded.
201201
pub fn chunk_at_mut(&self, pos: ChunkPosition) -> Option<RwLockWriteGuard<Chunk>> {
202-
self.0.get(&pos).map(|lock| lock.write()).flatten()
202+
self.0.get(&pos).and_then(|lock| lock.write())
203203
}
204204

205205
/// Returns an `Arc<RwLock<Chunk>>` at the given position.
@@ -212,8 +212,7 @@ impl ChunkMap {
212212

213213
let (x, y, z) = chunk_relative_pos(pos.into());
214214
self.chunk_at(pos.chunk())
215-
.map(|chunk| chunk.block_at(x, y, z))
216-
.flatten()
215+
.and_then(|chunk| chunk.block_at(x, y, z))
217216
}
218217

219218
pub fn set_block_at(&self, pos: ValidBlockPosition, block: BlockId) -> bool {

feather/protocol/src/io.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ impl Readable for Slot {
565565
Ok(Filled(
566566
ItemStackBuilder::with_item(item)
567567
.count(count)
568-
.apply_damage(tags.map(|t| t.damage).flatten())
568+
.apply_damage(tags.and_then(|t| t.damage))
569569
.into(),
570570
))
571571
} else {

feather/server/src/initial_handler/proxy/bungeecord.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(clippy::octal_escapes)]
12
use std::str::FromStr;
23

34
use anyhow::bail;
@@ -50,7 +51,7 @@ mod tests {
5051
fn extract_bungeecord_data_normal() {
5152
let handshake = Handshake {
5253
protocol_version: PROTOCOL_VERSION,
53-
server_address: "192.168.1.87\0192.168.1.67\0905c7e4fb96b45139645d123225575e2\0[{\"name\":\"textures\",\"value\":\"textures_value\",\"signature\":\"textures_signature\"}]".to_string(),
54+
server_address: "192.168.1.87\x00192.168.1.67\x00905c7e4fb96b45139645d123225575e2\x00[{\"name\":\"textures\",\"value\":\"textures_value\",\"signature\":\"textures_signature\"}]".to_string(),
5455
server_port: 25565,
5556
next_state: HandshakeState::Login,
5657
};
@@ -74,7 +75,7 @@ mod tests {
7475
fn extract_bungeecord_data_too_short() {
7576
let handshake = Handshake {
7677
protocol_version: PROTOCOL_VERSION,
77-
server_address: "192.168.1.87\0192.168.1.67\0905c7e4fb96b45139645d123225575e2"
78+
server_address: "192.168.1.87\x00192.168.1.67\x00905c7e4fb96b45139645d123225575e2"
7879
.to_string(),
7980
server_port: 25565,
8081
next_state: HandshakeState::Login,
@@ -87,8 +88,9 @@ mod tests {
8788
fn extract_bungeecord_data_too_long() {
8889
let handshake = Handshake {
8990
protocol_version: PROTOCOL_VERSION,
90-
server_address: "192.168.1.87\0192.168.1.67\0905c7e4fb96b45139645d123225575e2\0a\0b"
91-
.to_string(),
91+
server_address:
92+
"192.168.1.87\x00192.168.1.67\x00905c7e4fb96b45139645d123225575e2\x00a\x00b"
93+
.to_string(),
9294
server_port: 25565,
9395
next_state: HandshakeState::Login,
9496
};
@@ -100,7 +102,7 @@ mod tests {
100102
fn extract_bungeecord_data_localhost_host_ip() {
101103
let handshake = Handshake {
102104
protocol_version: PROTOCOL_VERSION,
103-
server_address: "localhost\0192.168.1.67\0905c7e4fb96b45139645d123225575e2\0[{\"name\":\"textures\",\"value\":\"textures_value\",\"signature\":\"textures_signature\"}]".to_string(),
105+
server_address: "localhost\x00192.168.1.67\x00905c7e4fb96b45139645d123225575e2\x00[{\"name\":\"textures\",\"value\":\"textures_value\",\"signature\":\"textures_signature\"}]".to_string(),
104106
server_port: 25565,
105107
next_state: HandshakeState::Login,
106108
};
@@ -124,7 +126,7 @@ mod tests {
124126
fn extract_bungeecord_data_localhost_client_ip() {
125127
let handshake = Handshake {
126128
protocol_version: PROTOCOL_VERSION,
127-
server_address: "192.168.1.87\0localhost\0905c7e4fb96b45139645d123225575e2\0[{\"name\":\"textures\",\"value\":\"textures_value\",\"signature\":\"textures_signature\"}]".to_string(),
129+
server_address: "192.168.1.87\x00localhost\x00905c7e4fb96b45139645d123225575e2\x00[{\"name\":\"textures\",\"value\":\"textures_value\",\"signature\":\"textures_signature\"}]".to_string(),
128130
server_port: 25565,
129131
next_state: HandshakeState::Login,
130132
};
@@ -148,7 +150,7 @@ mod tests {
148150
fn extract_bungeecord_data_invalid_uuid() {
149151
let handshake = Handshake {
150152
protocol_version: PROTOCOL_VERSION,
151-
server_address: "192.168.1.87\0192.168.1.67\005c7e4fb9675e2\0[{\"name\":\"textures\",\"value\":\"textures_value\",\"signature\":\"textures_signature\"}]".to_string(),
153+
server_address: "192.168.1.87\x00192.168.1.67\x0005c7e4fb9675e2\x00[{\"name\":\"textures\",\"value\":\"textures_value\",\"signature\":\"textures_signature\"}]".to_string(),
152154
server_port: 25565,
153155
next_state: HandshakeState::Login,
154156
};
@@ -160,7 +162,7 @@ mod tests {
160162
fn extract_bungeecord_data_invalid_properties() {
161163
let handshake = Handshake {
162164
protocol_version: PROTOCOL_VERSION,
163-
server_address: "192.168.1.87\0192.168.1.67\0905c7e4fb96b45139645d123225575e2\0[{\"name\":\"textures\",\"value\":\"textures_value\",\"sinature\":\"textures_signature\"}]".to_string(),
165+
server_address: "192.168.1.87\x00192.168.1.67\x00905c7e4fb96b45139645d123225575e2\x00[{\"name\":\"textures\",\"value\":\"textures_value\",\"sinature\":\"textures_signature\"}]".to_string(),
164166
server_port: 25565,
165167
next_state: HandshakeState::Login,
166168
};

libcraft/blocks/src/data.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl BlockReportEntry {
121121
<T as FromStr>::Err: std::fmt::Debug,
122122
{
123123
if let Some(vec) = self.properties.get(name) {
124-
vec.iter().map(|s| T::from_str(s).ok()).flatten().collect()
124+
vec.iter().filter_map(|s| T::from_str(s).ok()).collect()
125125
} else {
126126
Vec::new()
127127
}

libcraft/generators/src/common.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ pub fn compress_and_write<T: Serialize>(data: Vec<T>, path: &str) -> Result<()>
3232
pub fn state_name_to_block_kind(name: &str) -> Result<BlockKind> {
3333
name.split(':')
3434
.last()
35-
.map(BlockKind::from_name)
36-
.flatten()
35+
.and_then(BlockKind::from_name)
3736
.ok_or_else(|| anyhow!("Could not convert state name to BlockKind"))
3837
}

libcraft/items/src/inventory_slot.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,13 @@ impl InventorySlot {
4949
}
5050

5151
/// Takes all items and makes self empty.
52+
#[must_use]
5253
pub fn take_all(&mut self) -> Self {
5354
mem::take(self)
5455
}
5556

5657
/// Takes half (rounded down) of the items in self.
58+
#[must_use]
5759
pub fn take_half(&mut self) -> Self {
5860
let half = (self.count() + 1) / 2;
5961
self.try_take(half)
@@ -63,6 +65,7 @@ impl InventorySlot {
6365
/// and put it into the output. If amount is bigger
6466
/// then what self can provide then this is the same
6567
/// as calling take.
68+
#[must_use]
6669
#[allow(clippy::missing_panics_doc)]
6770
pub fn try_take(&mut self, amount: u32) -> Self {
6871
if amount == 0 {

libcraft/items/src/item_stack.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,12 +455,14 @@ impl ItemStackBuilder {
455455
}
456456

457457
/// Set the item `title`.
458+
#[must_use]
458459
pub fn title(mut self, title: impl AsRef<str>) -> Self {
459460
self.get_or_init_meta().title = title.as_ref().to_owned();
460461
self
461462
}
462463

463464
/// Set the item `lore`.
465+
#[must_use]
464466
pub fn lore(mut self, lore: impl AsRef<str>) -> Self {
465467
self.get_or_init_meta().lore = lore.as_ref().to_owned();
466468
self

quill/cargo-quill/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl Build {
7373

7474
pub fn module_path(&self, cargo_meta: &Metadata, plugin_meta: &PluginMetadata) -> PathBuf {
7575
let target_dir = self.target_dir(cargo_meta);
76-
let module_filename = plugin_meta.identifier.replace("-", "_");
76+
let module_filename = plugin_meta.identifier.replace('-', "_");
7777

7878
let module_extension = self.module_extension();
7979
let lib_prefix = if self.native && cfg!(unix) { "lib" } else { "" };

0 commit comments

Comments
 (0)