From 3077e4a1a48670e3704c5bb049eaf2faf32b2033 Mon Sep 17 00:00:00 2001 From: Martin Indra Date: Wed, 19 Jun 2024 13:50:52 +0200 Subject: [PATCH] Fix Clippy warnings --- crates/controller/src/hud/minimap/fill.rs | 12 +++--------- crates/lobby_model/src/auth.rs | 4 ++-- crates/multiplayer/src/playermsg.rs | 5 +---- crates/net/src/connection/databuf.rs | 9 +++------ crates/pathing/src/polyanya.rs | 4 +--- 5 files changed, 10 insertions(+), 24 deletions(-) diff --git a/crates/controller/src/hud/minimap/fill.rs b/crates/controller/src/hud/minimap/fill.rs index 547bf7889..ec59f6727 100644 --- a/crates/controller/src/hud/minimap/fill.rs +++ b/crates/controller/src/hud/minimap/fill.rs @@ -103,9 +103,7 @@ struct CameraPoint<'w, 's> { impl<'w, 's> CameraPoint<'w, 's> { fn point(&self, ndc: Vec2) -> Option { let ray = self.ray.ray(ndc); - let Some(intersection) = self.terrain.cast_ray_msl(&ray, f32::INFINITY) else { - return None; - }; + let intersection = self.terrain.cast_ray_msl(&ray, f32::INFINITY)?; let point = ray.origin + ray.dir * intersection.toi; Some(self.ui_coords.flat_to_rel(point.to_flat())) } @@ -148,16 +146,12 @@ fn endpoints_to_line(start: Option, end: Option) -> Option<(Vec2, Ve let aabb = Aabb::new(Point::new(0., 0.), Point::new(1., 1.)); if !aabb.contains_local_point(&start) { let ray = Ray::new(start, end - start); - let Some(toi) = aabb.cast_local_ray(&ray, 1., false) else { - return None; - }; + let toi = aabb.cast_local_ray(&ray, 1., false)?; start = ray.origin + toi * ray.dir; } if !aabb.contains_local_point(&end) { let ray = Ray::new(end, start - end); - let Some(toi) = aabb.cast_local_ray(&ray, 1., false) else { - return None; - }; + let toi = aabb.cast_local_ray(&ray, 1., false)?; end = ray.origin + toi * ray.dir; } diff --git a/crates/lobby_model/src/auth.rs b/crates/lobby_model/src/auth.rs index 15920689b..db2e00820 100644 --- a/crates/lobby_model/src/auth.rs +++ b/crates/lobby_model/src/auth.rs @@ -140,10 +140,10 @@ mod tests { "Password must have at least 6 characters." ); - user.password = "Long-enough-pwd".to_owned(); + user.password = "Long-enough-pwd".to_string(); assert!(user.validate().is_ok()); - user.user.username = "Indy ".to_owned(); + user.user.username = "Indy ".to_string(); assert_eq!( user.validate().err().unwrap().to_string(), "Username starting or ending with whitespace is not allowed." diff --git a/crates/multiplayer/src/playermsg.rs b/crates/multiplayer/src/playermsg.rs index 6706dae57..1d31c0cc5 100644 --- a/crates/multiplayer/src/playermsg.rs +++ b/crates/multiplayer/src/playermsg.rs @@ -298,10 +298,7 @@ impl EntityIdMapRes { /// This should not be called unless the player leaves the multiplayer /// game. fn remove_player(&mut self, player: Player) -> Option { - let Some(map) = self.remote_to_local.remove(&player) else { - return None; - }; - + let map = self.remote_to_local.remove(&player)?; for local in map.locals() { self.local_to_remote.remove(&local).unwrap(); } diff --git a/crates/net/src/connection/databuf.rs b/crates/net/src/connection/databuf.rs index bcd7ee324..e8b435d95 100644 --- a/crates/net/src/connection/databuf.rs +++ b/crates/net/src/connection/databuf.rs @@ -71,9 +71,7 @@ impl DataBuf { /// /// Panics if `buf` len is smaller than length of found data. pub(super) fn get(&self, id: PackageId, buf: &mut [u8]) -> Option { - let Some(slot_index) = self.slot_index(id) else { - return None; - }; + let slot_index = self.slot_index(id)?; let front = self.slots.front().unwrap(); let slot = self.slots.get(slot_index).unwrap(); @@ -111,9 +109,8 @@ impl DataBuf { /// Get index (withing slots deque) of the slot with ID `id`. fn slot_index(&self, id: PackageId) -> Option { - let Some(&ordinal) = self.ordinals.get(&id) else { - return None; - }; + let ordinal = self.ordinals.get(&id)?; + // Slots can't be empty since the ordinal was found. let front = self.slots.front().unwrap(); Some(ordinal.wrapping_sub(front.ordinal)) diff --git a/crates/pathing/src/polyanya.rs b/crates/pathing/src/polyanya.rs index e9df30cd4..26713704a 100644 --- a/crates/pathing/src/polyanya.rs +++ b/crates/pathing/src/polyanya.rs @@ -43,9 +43,7 @@ pub(crate) fn find_path( )); } - let Some(mut best) = open_set.peek().cloned() else { - return None; - }; + let mut best = open_set.peek().cloned()?; let mut counter = 0; while let Some(node) = open_set.pop() {