| 167 | |
| 168 | impl PartialOrd for dyn HigherOrderUDFImpl { |
| 169 | fn partial_cmp(&self, other: &Self) -> Option<Ordering> { |
| 170 | let mut cmp = self.name().cmp(other.name()); |
| 171 | if cmp == Ordering::Equal { |
| 172 | cmp = self.signature().partial_cmp(other.signature())?; |
| 173 | } |
| 174 | if cmp == Ordering::Equal { |
| 175 | cmp = self.aliases().partial_cmp(other.aliases())?; |
| 176 | } |
| 177 | // Contract for PartialOrd and PartialEq consistency requires that |
| 178 | // a == b if and only if partial_cmp(a, b) == Some(Equal). |
| 179 | if cmp == Ordering::Equal && self != other { |
| 180 | // Functions may have other properties besides name and signature |
| 181 | // that differentiate two instances (e.g. type, or arbitrary parameters). |
| 182 | // We cannot return Some(Equal) in such case. |
| 183 | return None; |
| 184 | } |
| 185 | debug_assert!( |
| 186 | cmp == Ordering::Equal || self != other, |
| 187 | "Detected incorrect implementation of PartialEq when comparing functions: '{}' and '{}'. \ |
| 188 | The functions compare as equal, but they are not equal based on general properties that \ |
| 189 | the PartialOrd implementation observes,", |
| 190 | self.name(), |
| 191 | other.name() |
| 192 | ); |
| 193 | Some(cmp) |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | impl Eq for dyn HigherOrderUDFImpl {} |