Skip to content

Commit 56dbd4d

Browse files
committed
fix: Ord of Ident
1 parent b1b379e commit 56dbd4d

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

src/ast/mod.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use core::{
3333
fmt::{self, Display},
3434
hash,
3535
};
36+
use std::cmp::Ordering;
3637

3738
#[cfg(feature = "serde")]
3839
use serde::{Deserialize, Serialize};
@@ -172,7 +173,7 @@ fn format_statement_list(f: &mut fmt::Formatter, statements: &[Statement]) -> fm
172173
}
173174

174175
/// An identifier, decomposed into its value or character data and the quote style.
175-
#[derive(Debug, Clone, PartialOrd, Ord)]
176+
#[derive(Debug, Clone)]
176177
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
177178
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
178179
pub struct Ident {
@@ -214,6 +215,34 @@ impl core::hash::Hash for Ident {
214215

215216
impl Eq for Ident {}
216217

218+
impl PartialOrd for Ident {
219+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
220+
Some(self.cmp(other))
221+
}
222+
}
223+
224+
impl Ord for Ident {
225+
fn cmp(&self, other: &Self) -> Ordering {
226+
let Ident {
227+
value,
228+
quote_style,
229+
// exhaustiveness check; we ignore spans in ordering
230+
span: _,
231+
} = self;
232+
233+
let Ident {
234+
value: other_value,
235+
quote_style: other_quote_style,
236+
// exhaustiveness check; we ignore spans in ordering
237+
span: _,
238+
} = other;
239+
240+
// First compare by value, then by quote_style
241+
value.cmp(other_value)
242+
.then_with(|| quote_style.cmp(other_quote_style))
243+
}
244+
}
245+
217246
impl Ident {
218247
/// Create a new identifier with the given value and no quotes and an empty span.
219248
pub fn new<S>(value: S) -> Self
@@ -4181,7 +4210,7 @@ pub enum Statement {
41814210
/// ```sql
41824211
/// NOTIFY channel [ , payload ]
41834212
/// ```
4184-
/// send a notification event together with an optional payload string to channel
4213+
/// send a notification event together with an optional "payload" string to channel
41854214
///
41864215
/// See Postgres <https://www.postgresql.org/docs/current/sql-notify.html>
41874216
NOTIFY {

0 commit comments

Comments
 (0)