@@ -28,6 +28,7 @@ use helpers::{
28
28
stmt_data_loading:: { FileStagingCommand , StageLoadSelectItemKind } ,
29
29
} ;
30
30
31
+ use core:: cmp:: Ordering ;
31
32
use core:: ops:: Deref ;
32
33
use core:: {
33
34
fmt:: { self , Display } ,
@@ -172,7 +173,7 @@ fn format_statement_list(f: &mut fmt::Formatter, statements: &[Statement]) -> fm
172
173
}
173
174
174
175
/// An identifier, decomposed into its value or character data and the quote style.
175
- #[ derive( Debug , Clone , PartialOrd , Ord ) ]
176
+ #[ derive( Debug , Clone ) ]
176
177
#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
177
178
#[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
178
179
pub struct Ident {
@@ -214,6 +215,35 @@ impl core::hash::Hash for Ident {
214
215
215
216
impl Eq for Ident { }
216
217
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
242
+ . cmp ( other_value)
243
+ . then_with ( || quote_style. cmp ( other_quote_style) )
244
+ }
245
+ }
246
+
217
247
impl Ident {
218
248
/// Create a new identifier with the given value and no quotes and an empty span.
219
249
pub fn new < S > ( value : S ) -> Self
@@ -4214,7 +4244,7 @@ pub enum Statement {
4214
4244
/// ```sql
4215
4245
/// NOTIFY channel [ , payload ]
4216
4246
/// ```
4217
- /// send a notification event together with an optional “ payload” string to channel
4247
+ /// send a notification event together with an optional " payload" string to channel
4218
4248
///
4219
4249
/// See Postgres <https://www.postgresql.org/docs/current/sql-notify.html>
4220
4250
NOTIFY {
@@ -9771,6 +9801,8 @@ impl fmt::Display for NullInclusion {
9771
9801
9772
9802
#[ cfg( test) ]
9773
9803
mod tests {
9804
+ use crate :: tokenizer:: Location ;
9805
+
9774
9806
use super :: * ;
9775
9807
9776
9808
#[ test]
@@ -10066,4 +10098,16 @@ mod tests {
10066
10098
test_steps ( OneOrManyWithParens :: Many ( vec ! [ 2 ] ) , vec ! [ 2 ] , 3 ) ;
10067
10099
test_steps ( OneOrManyWithParens :: Many ( vec ! [ 3 , 4 ] ) , vec ! [ 3 , 4 ] , 4 ) ;
10068
10100
}
10101
+
10102
+ // Tests that the position in the code of an `Ident` does not affect its
10103
+ // ordering.
10104
+ #[ test]
10105
+ fn test_ident_ord ( ) {
10106
+ let mut a = Ident :: with_span ( Span :: new ( Location :: new ( 1 , 1 ) , Location :: new ( 1 , 1 ) ) , "a" ) ;
10107
+ let mut b = Ident :: with_span ( Span :: new ( Location :: new ( 2 , 2 ) , Location :: new ( 2 , 2 ) ) , "b" ) ;
10108
+
10109
+ assert ! ( a < b) ;
10110
+ std:: mem:: swap ( & mut a. span , & mut b. span ) ;
10111
+ assert ! ( a < b) ;
10112
+ }
10069
10113
}
0 commit comments