From 4939d23bd354a1357727fe46ce1205895ffbe2b6 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Thu, 14 Mar 2024 17:55:57 -0400 Subject: [PATCH] Enable `clippy::derive_ord_xor_partial_ord` (#9371) This PR enables the [`clippy::derive_ord_xor_partial_ord`](https://rust-lang.github.io/rust-clippy/master/index.html#/derive_ord_xor_partial_ord) rule and fixes the outstanding violations. Release Notes: - N/A --- Cargo.toml | 1 - crates/ai/src/prompts/base.rs | 16 +++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 77118bce3f..458bf0c064 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -411,7 +411,6 @@ style = "allow" almost_complete_range = "allow" arc_with_non_send_sync = "allow" borrowed_box = "allow" -derive_ord_xor_partial_ord = "allow" let_underscore_future = "allow" map_entry = "allow" non_canonical_clone_impl = "allow" diff --git a/crates/ai/src/prompts/base.rs b/crates/ai/src/prompts/base.rs index 529f775ae8..da7f707040 100644 --- a/crates/ai/src/prompts/base.rs +++ b/crates/ai/src/prompts/base.rs @@ -49,7 +49,7 @@ pub trait PromptTemplate { } #[repr(i8)] -#[derive(PartialEq, Eq, Ord)] +#[derive(PartialEq, Eq)] pub enum PromptPriority { /// Ignores truncation. Mandatory, @@ -59,11 +59,17 @@ pub enum PromptPriority { impl PartialOrd for PromptPriority { fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +impl Ord for PromptPriority { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { match (self, other) { - (Self::Mandatory, Self::Mandatory) => Some(std::cmp::Ordering::Equal), - (Self::Mandatory, Self::Ordered { .. }) => Some(std::cmp::Ordering::Greater), - (Self::Ordered { .. }, Self::Mandatory) => Some(std::cmp::Ordering::Less), - (Self::Ordered { order: a }, Self::Ordered { order: b }) => b.partial_cmp(a), + (Self::Mandatory, Self::Mandatory) => std::cmp::Ordering::Equal, + (Self::Mandatory, Self::Ordered { .. }) => std::cmp::Ordering::Greater, + (Self::Ordered { .. }, Self::Mandatory) => std::cmp::Ordering::Less, + (Self::Ordered { order: a }, Self::Ordered { order: b }) => b.cmp(a), } } }