← All Workshops

MudEngine Part 9: The Twin Guardians

Step 10 / 12

Lint with Clippy

The quest feature adds a lot of new logic — perfect material for Clippy to chew on. The project sets [lints.clippy] in Cargo.toml, so cargo clippy must be zero-warning before you move on.

Run it from mud-engine/ (the crate directory):

cargo check
cargo clippy

Approach any warnings the workshop's teaching way first:

  • collapsible_if — Clippy suggests folding a nested if !room.exits.iter().any(…) into the outer if let Some(room) = … guard with &&. Do it — it reads better and matches the quest code's intent ("push the exit if it isn't there yet").
  • unnecessary_map_or — .map_or(false, |items| …) → .is_some_and(|items| …). The ground lookup in check_quest_completion is the exact case (was the earlier .get(&room_id).map_or(false, …)).
  • Borrow-order in the disconnect handler — dropping a player's carried items mutates state.ground while player is still borrowed from state.players. Copy the (room_id, carried) pair out first (the Step 8 block already shows this shape), then mutate.

The style honours what Parts 7–8 already taught: cargo clippy runs from the crate root with no extra flags, and a clean tree is part of the definition of "done" for every part.

Lint the quest code
cargo clippy
💡 The `[lints.clippy]` crate lint

Cargo.toml in mud-engine/ sets:

[lints.clippy]

That makes Clippy run as part of cargo check/cargo build too. Keeping cargo clippy at zero warnings means the workspace stays consistent for whoever picks the project up next — including the next part of this workshop.

Step 10 / 12