Skip to content

Commit 9cb807a

Browse files
committed
Run clippy in CI and fail if warnings found
1 parent 44ef1a4 commit 9cb807a

6 files changed

Lines changed: 37 additions & 18 deletions

File tree

.azure-pipelines.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,21 @@ steps:
1515
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain $RUSTUP_TOOLCHAIN
1616
echo "##vso[task.setvariable variable=PATH;]$PATH:$HOME/.cargo/bin"
1717
displayName: Install Rust
18+
1819
- script: cargo install --debug cargo-make
1920
displayName: Install cargo-make
21+
2022
- script: cargo make --no-workspace workspace-ci-flow
2123
displayName: Build and test
24+
2225
- script: rustup component add rustfmt
2326
displayName: Install rustfmt
27+
2428
- script: cargo fmt -- --check
25-
displayName: Verify formatting
29+
displayName: Verify formatting
30+
31+
- script: rustup component add clippy
32+
displayName: Install clippy
33+
34+
- script: cargo clippy --all-targets --all-features -- -D warnings
35+
displayName: Run clippy

codegen/src/lib.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,12 @@ pub fn derive_packet(_item: TokenStream) -> TokenStream {
136136

137137
let parameter_type = PARAMETER_MAPPINGS
138138
.get(ty_ident.to_string().as_str())
139-
.expect(&format!(
140-
"Couldn't find packet parameter type corresponding to {}",
141-
ty_ident
142-
));
139+
.unwrap_or_else(|| {
140+
panic!(
141+
"Couldn't find packet parameter type corresponding to {}",
142+
ty_ident
143+
)
144+
});
143145
let function_ident = Ident::new(
144146
FUNCTION_MAPPINGS.get(parameter_type).unwrap(),
145147
Span::call_site(),

server/src/chunkworker.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ struct RegionFile {
5353
/// value is used to close
5454
/// the file after it isn't used for
5555
/// some period of time.
56-
last_used: u64,
56+
///
57+
/// TODO actually implement this
58+
_last_used: u64,
5759
}
5860

5961
struct ChunkWorker {
@@ -131,7 +133,10 @@ fn load_chunk(worker: &mut ChunkWorker, pos: ChunkPosition) -> Reply {
131133
.unwrap()
132134
.as_secs();
133135

134-
let file = RegionFile { handle, last_used };
136+
let file = RegionFile {
137+
handle,
138+
_last_used: last_used,
139+
};
135140

136141
worker.open_regions.insert(rpos, file);
137142
}

server/src/io/initialhandler.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ mod tests {
502502
Action::SendPacket(_response) => {
503503
assert_eq!(_response.ty(), PacketType::Response);
504504

505-
let response = cast_packet::<Response>(&_response);
505+
let response = cast_packet::<Response>(&**_response);
506506
let _: serde_json::Value = serde_json::from_str(&response.json_response).unwrap();
507507
}
508508
_ => panic!(),
@@ -520,7 +520,7 @@ mod tests {
520520
match _pong {
521521
Action::SendPacket(_pong) => {
522522
assert_eq!(_pong.ty(), PacketType::Pong);
523-
let pong = cast_packet::<Pong>(&_pong);
523+
let pong = cast_packet::<Pong>(&*_pong);
524524
assert_eq!(pong.payload, payload);
525525
}
526526
_ => panic!(),
@@ -562,7 +562,7 @@ mod tests {
562562
Action::SendPacket(_set_compression) => {
563563
assert_eq!(_set_compression.ty(), PacketType::SetCompression);
564564

565-
let set_compression = cast_packet::<SetCompression>(&_set_compression);
565+
let set_compression = cast_packet::<SetCompression>(&*_set_compression);
566566
assert_eq!(set_compression.threshold, config.io.compression_threshold);
567567
}
568568
_ => panic!(),
@@ -582,7 +582,7 @@ mod tests {
582582
Action::SendPacket(_login_success) => {
583583
assert_eq!(_login_success.ty(), PacketType::LoginSuccess);
584584

585-
let login_success = cast_packet::<LoginSuccess>(&_login_success);
585+
let login_success = cast_packet::<LoginSuccess>(&*_login_success);
586586
assert_eq!(login_success.username, username.to_string());
587587
}
588588
_ => panic!(),

server/src/testframework.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,8 @@ pub fn received_packets(player: &Player, cap: Option<usize>) -> Vec<Box<Packet>>
9494
break;
9595
}
9696
}
97-
match msg {
98-
ServerToWorkerMessage::SendPacket(pack) => result.push(pack),
99-
_ => (),
97+
if let ServerToWorkerMessage::SendPacket(pack) = msg {
98+
result.push(pack);
10099
}
101100
}
102101

server/src/worldupdate.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,12 @@ mod tests {
180180
.iter()
181181
.find(|packet| packet.ty() == PacketType::BlockChange)
182182
.unwrap();
183-
let block_change = cast_packet::<BlockChange>(&_block_change);
183+
let block_change = cast_packet::<BlockChange>(&**_block_change);
184184
assert_eq!(block_change.location, pos);
185-
assert_eq!(block_change.block_id, Block::Air.native_state_id() as i32);
185+
assert_eq!(
186+
block_change.block_id,
187+
i32::from(Block::Air.native_state_id())
188+
);
186189

187190
// Make sure block was actually updated
188191
assert_eq!(
@@ -249,9 +252,9 @@ mod tests {
249252
// player did not
250253
let packet = t::assert_packet_received(&player, PacketType::BlockChange);
251254

252-
let packet = cast_packet::<BlockChange>(&packet);
255+
let packet = cast_packet::<BlockChange>(&*packet);
253256
assert_eq!(packet.location, BlockPosition::new(0, 0, 0));
254-
assert_eq!(packet.block_id, Block::Sand.native_state_id() as i32);
257+
assert_eq!(packet.block_id, i32::from(Block::Sand.native_state_id()));
255258

256259
let p2_packets = t::received_packets(&player2, None);
257260
assert_eq!(p2_packets.len(), 0);

0 commit comments

Comments
 (0)