Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[refactoring] Fix more instances of non-canonical PartialOrd implementations #11475

Merged
merged 3 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions execution/block-partitioner/src/v2/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ impl Ord for SubBlockIdx {
}
}

#[allow(clippy::non_canonical_partial_ord_impl)]
impl PartialOrd for SubBlockIdx {
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
(self.round_id, self.shard_id).partial_cmp(&(other.round_id, other.shard_id))
Some(self.cmp(other))
}
}

Expand Down Expand Up @@ -69,11 +68,9 @@ impl Ord for ShardedTxnIndexV2 {
}
}

#[allow(clippy::non_canonical_partial_ord_impl)]
impl PartialOrd for ShardedTxnIndexV2 {
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
(self.sub_block_idx, self.pre_partitioned_txn_idx)
.partial_cmp(&(other.sub_block_idx, other.pre_partitioned_txn_idx))
Some(self.cmp(other))
}
}

Expand Down
3 changes: 1 addition & 2 deletions storage/backup/backup-cli/src/metadata/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,9 @@ impl PartialEq<Self> for CompactionTimestampsMeta {
}
}

#[allow(clippy::non_canonical_partial_ord_impl)]
impl PartialOrd<Self> for CompactionTimestampsMeta {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.file_compacted_at.partial_cmp(&other.file_compacted_at)
Some(self.cmp(other))
}
}

Expand Down
18 changes: 6 additions & 12 deletions third_party/move/move-analyzer/src/symbols.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) The Move Contributors
// SPDX-License-Identifier: Apache-2.0

#![allow(clippy::unwrap_or_default)]
#![allow(clippy::non_canonical_partial_ord_impl)]

//! This module is responsible for building symbolication information on top of compiler's typed
Expand Down Expand Up @@ -171,12 +170,13 @@
field_defs: Vec<FieldDef>,
}

#[derive(Derivative, Debug, Clone, PartialEq, Eq)]
#[derivative(PartialOrd, Ord)]
#[derive(Derivative)]
#[derivative(Debug, Clone, Eq, PartialEq, PartialOrd, Ord)]

Check warning on line 174 in third_party/move/move-analyzer/src/symbols.rs

View check run for this annotation

Codecov / codecov/patch

third_party/move/move-analyzer/src/symbols.rs#L173-L174

Added lines #L173 - L174 were not covered by tests
pub struct FunctionDef {
name: Symbol,
start: Position,
attrs: Vec<String>,
#[derivative(PartialEq = "ignore")]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementations PartialEq, PartialOrd, and Ord should agree with each other: https://docs.rs/rust-libcore/latest/core/cmp/trait.PartialOrd.html#how-can-i-implement-partialord

#[derivative(PartialOrd = "ignore")]
#[derivative(Ord = "ignore")]
ident_type: IdentType,
Expand Down Expand Up @@ -525,10 +525,7 @@
col_end,
};

references
.entry(def_loc)
.or_insert_with(BTreeSet::new)
.insert(use_loc);
references.entry(def_loc).or_default().insert(use_loc);
Self {
col_start: use_start.character,
col_end,
Expand Down Expand Up @@ -564,7 +561,7 @@
}

fn insert(&mut self, key: u32, val: UseDef) {
self.0.entry(key).or_insert_with(BTreeSet::new).insert(val);
self.0.entry(key).or_default().insert(val);
}

fn get(&self, key: u32) -> Option<BTreeSet<UseDef>> {
Expand Down Expand Up @@ -597,10 +594,7 @@
impl Symbols {
pub fn merge(&mut self, other: Self) {
for (k, v) in other.references {
self.references
.entry(k)
.or_insert_with(BTreeSet::new)
.extend(v);
self.references.entry(k).or_default().extend(v);

Check warning on line 597 in third_party/move/move-analyzer/src/symbols.rs

View check run for this annotation

Codecov / codecov/patch

third_party/move/move-analyzer/src/symbols.rs#L597

Added line #L597 was not covered by tests
}
self.file_use_defs.extend(other.file_use_defs);
self.file_name_mapping.extend(other.file_name_mapping);
Expand Down
3 changes: 1 addition & 2 deletions third_party/move/move-borrow-graph/src/references.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,9 @@

impl<Loc: Copy, Lbl: Clone + Ord> Eq for BorrowEdge<Loc, Lbl> {}

#[allow(clippy::non_canonical_partial_ord_impl)]
impl<Loc: Copy, Lbl: Clone + Ord> PartialOrd for BorrowEdge<Loc, Lbl> {
fn partial_cmp(&self, other: &BorrowEdge<Loc, Lbl>) -> Option<Ordering> {
BorrowEdgeNoLoc::new(self).partial_cmp(&BorrowEdgeNoLoc::new(other))
Some(self.cmp(other))

Check warning on line 214 in third_party/move/move-borrow-graph/src/references.rs

View check run for this annotation

Codecov / codecov/patch

third_party/move/move-borrow-graph/src/references.rs#L214

Added line #L214 was not covered by tests
}
}

Expand Down
3 changes: 1 addition & 2 deletions third_party/move/move-compiler/src/shared/unique_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,9 @@
}
impl<T: TName> Eq for UniqueSet<T> {}

#[allow(clippy::non_canonical_partial_ord_impl)]
impl<T: TName> PartialOrd for UniqueSet<T> {
fn partial_cmp(&self, other: &UniqueSet<T>) -> Option<Ordering> {
(self.0).0.keys().partial_cmp((other.0).0.keys())
Some(self.cmp(other))

Check warning on line 123 in third_party/move/move-compiler/src/shared/unique_set.rs

View check run for this annotation

Codecov / codecov/patch

third_party/move/move-compiler/src/shared/unique_set.rs#L123

Added line #L123 was not covered by tests
}
}

Expand Down
3 changes: 1 addition & 2 deletions third_party/move/move-core/types/src/gas_algebra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,9 @@ impl<U> PartialEq for GasQuantity<U> {

impl<U> Eq for GasQuantity<U> {}

#[allow(clippy::non_canonical_partial_ord_impl)]
impl<U> PartialOrd for GasQuantity<U> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp_impl(other))
Some(self.cmp(other))
}
}

Expand Down
Loading