Skip to content

Commit

Permalink
Fix clippy warning related to IString PartialOrd implementation (#35)
Browse files Browse the repository at this point in the history
Clippy added a new lint `clippy::non_canonical_partial_ord_impl` (aka `incorrect_partial_ord_impl_on_ord_type`), hence it should now be followed.
  • Loading branch information
ColonelThirtyTwo authored Oct 22, 2023
1 parent b981974 commit 238d464
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,14 @@ impl Ord for IString {
}
}

impl_cmp_as_str!(PartialOrd::<IString, IString>);
// Manual implementation of PartialOrd that uses Ord to ensure it is consistent, as
// recommended by clippy.
impl PartialOrd for IString {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}

impl_cmp_as_str!(PartialOrd::<IString, str>);
impl_cmp_as_str!(PartialOrd::<str, IString>);
impl_cmp_as_str!(PartialOrd::<IString, &str>);
Expand Down

0 comments on commit 238d464

Please sign in to comment.