Skip to content

Commit

Permalink
Fix a Clippy warning
Browse files Browse the repository at this point in the history
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<Ordering> {
   | | _____________________________________________________________-
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.
  • Loading branch information
Indy2222 committed Oct 7, 2023
1 parent ab3ba9b commit d0eed02
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 17 deletions.
4 changes: 2 additions & 2 deletions crates/controller/src/hud/minimap/fill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec2>, end: Option<Vec2>) -> 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<f32> = start.into();
let mut end: Point<f32> = end.into();
Expand Down
6 changes: 1 addition & 5 deletions crates/index/src/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
4 changes: 1 addition & 3 deletions crates/map/src/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions crates/types/src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ impl fmt::Display for Player {

impl PartialOrd for Player {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
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()
}
}

Expand Down
6 changes: 1 addition & 5 deletions crates/uom/src/quantity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,7 @@ impl<const U: Unit> Eq for Quantity<U> {}

impl<const U: Unit> PartialOrd for Quantity<U> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
#[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))
}
}

Expand Down

0 comments on commit d0eed02

Please sign in to comment.