From d0eed0297cbb07c638cb3dafd27aaa7e26bc59c7 Mon Sep 17 00:00:00 2001 From: Martin Indra Date: Sat, 7 Oct 2023 18:34:20 +0200 Subject: [PATCH] Fix a Clippy warning error: incorrect implementation of `partial_cmp` on an `Ord` type --> crates/types/src/player.rs:43:1 | 43 | / impl PartialOrd for Player { 44 | | fn partial_cmp(&self, other: &Self) -> Option { | | _____________________________________________________________- 45 | || self.to_num().partial_cmp(&other.to_num()) 46 | || } | ||_____- help: change this to: `{ Some(self.cmp(other)) }` 47 | | } | |__^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#incorrect_partial_ord_impl_on_ord_type = note: `#[deny(clippy::incorrect_partial_ord_impl_on_ord_type)]` on by default error: could not compile `de_types` (lib) due to previous error warning: build failed, waiting for other jobs to finish... Error: Process completed with exit code 101. --- crates/controller/src/hud/minimap/fill.rs | 4 ++-- crates/index/src/grid.rs | 6 +----- crates/map/src/content.rs | 4 +--- crates/types/src/player.rs | 4 ++-- crates/uom/src/quantity.rs | 6 +----- 5 files changed, 7 insertions(+), 17 deletions(-) diff --git a/crates/controller/src/hud/minimap/fill.rs b/crates/controller/src/hud/minimap/fill.rs index b797dfe36..547bf7889 100644 --- a/crates/controller/src/hud/minimap/fill.rs +++ b/crates/controller/src/hud/minimap/fill.rs @@ -139,8 +139,8 @@ fn draw_camera_system(mut drawing: DrawingParam, camera: CameraPoint) { /// contained by rectangle (0, 0) -> (1, 1), b) is fully contained by the /// original line segment. fn endpoints_to_line(start: Option, end: Option) -> Option<(Vec2, Vec2)> { - let Some(start) = start else { return None }; - let Some(end) = end else { return None }; + let start = start?; + let end = end?; let mut start: Point = start.into(); let mut end: Point = end.into(); diff --git a/crates/index/src/grid.rs b/crates/index/src/grid.rs index b9fcd9a5d..3025ee2d0 100644 --- a/crates/index/src/grid.rs +++ b/crates/index/src/grid.rs @@ -112,11 +112,7 @@ impl TileGrid { } fn insert_to_tile(&mut self, entity: Entity, tile_coords: IVec2) { - let inserted = self - .tiles - .entry(tile_coords) - .or_insert_with(AHashSet::new) - .insert(entity); + let inserted = self.tiles.entry(tile_coords).or_default().insert(entity); debug_assert!(inserted); } diff --git a/crates/map/src/content.rs b/crates/map/src/content.rs index c74a5a52c..52540fe32 100644 --- a/crates/map/src/content.rs +++ b/crates/map/src/content.rs @@ -58,9 +58,7 @@ impl MapContent { for (i, object) in self.objects.iter().enumerate() { if let InnerObject::Active(object) = object.inner() { - let counter = counts - .entry(object.player()) - .or_insert_with(Counter::default); + let counter = counts.entry(object.player()).or_default(); match object.object_type() { ActiveObjectType::Building(_) => counter.buildings += 1, diff --git a/crates/types/src/player.rs b/crates/types/src/player.rs index 5e2fb0686..2d1de10fd 100644 --- a/crates/types/src/player.rs +++ b/crates/types/src/player.rs @@ -42,13 +42,13 @@ impl fmt::Display for Player { impl PartialOrd for Player { fn partial_cmp(&self, other: &Self) -> Option { - self.to_num().partial_cmp(&other.to_num()) + Some(self.cmp(other)) } } impl Ord for Player { fn cmp(&self, other: &Self) -> Ordering { - self.partial_cmp(other).unwrap() + self.to_num().partial_cmp(&other.to_num()).unwrap() } } diff --git a/crates/uom/src/quantity.rs b/crates/uom/src/quantity.rs index b62e3886e..e1921b441 100644 --- a/crates/uom/src/quantity.rs +++ b/crates/uom/src/quantity.rs @@ -89,11 +89,7 @@ impl Eq for Quantity {} impl PartialOrd for Quantity { fn partial_cmp(&self, other: &Self) -> Option { - #[cfg(debug_assertions)] - panic_on_invalid(self.0); - #[cfg(debug_assertions)] - panic_on_invalid(other.0); - self.0.partial_cmp(&other.0) + Some(self.cmp(other)) } }