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

Reword impl of partial_cmp for Ident, LocIdent #1697

Merged
merged 1 commit into from
Oct 24, 2023
Merged

Conversation

giorgiga
Copy link
Contributor

This rewords the implementation of partial_cmp for Ident and LocalIdent in a way that pleases clippy.

Note that the implementation was correct and that this does not change its behavior.

Of course another way to get rid of the lint error would be #[allow(clippy::incorrect_partial_ord_impl_on_ord_type)], but I think (more as a matter of principle than for any practical reason in this specific case) following clippy's advice and have partial_cmp call cmp is preferable to repeating the implementation, and... I also thing the annotation would be ugly 😃.

Anyway, in case they help clarify, here's clippy complains about Ident:

error: incorrect implementation of `partial_cmp` on an `Ord` type
  --> core/src/identifier.rs:60:1
   |
60 | /  impl PartialOrd for Ident {
61 | |      fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
   | | _______________________________________________________________________-
62 | ||         self.label().partial_cmp(other.label())
63 | ||     }
   | ||_____- help: change this to: `{ Some(self.cmp(other)) }`
64 | |  }
   | |__^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#incorrect_partial_ord_impl_on_ord_type

and LocIdent:

error: incorrect implementation of `partial_cmp` on an `Ord` type
   --> core/src/identifier.rs:152:1
    |
152 | /  impl PartialOrd for LocIdent {
153 | |      fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
    | | _______________________________________________________________________-
154 | ||         self.label().partial_cmp(other.label())
155 | ||     }
    | ||_____- help: change this to: `{ Some(self.cmp(other)) }`
156 | |  }
    | |__^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#incorrect_partial_ord_impl_on_ord_type

This rewords the implementation of partial_cmp for Ident and LocalIdent in a way that pleases clippy.

Note that the implementation was correct and that this does not change its behaviour.
Copy link
Member

@yannham yannham left a comment

Choose a reason for hiding this comment

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

Thanks! Is this a new clippy warning? We have clippy enabled on the CI, so I wonder why we didn't catch that earlier.

@yannham yannham added this pull request to the merge queue Oct 24, 2023
Merged via the queue into tweag:master with commit 75107c1 Oct 24, 2023
4 checks passed
@giorgiga giorgiga deleted the clippy branch October 26, 2023 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants