@@ -34,14 +34,14 @@ enum Issue {
34
34
Permutation ( Vec < Option < usize > > ) ,
35
35
}
36
36
37
- #[ derive( Clone , Debug ) ]
37
+ #[ derive( Clone , Debug , Eq , PartialEq ) ]
38
38
pub ( crate ) enum Compatibility < ' tcx > {
39
39
Compatible ,
40
40
Incompatible ( Option < TypeError < ' tcx > > ) ,
41
41
}
42
42
43
43
/// Similar to `Issue`, but contains some extra information
44
- #[ derive( Debug ) ]
44
+ #[ derive( Debug , PartialEq , Eq ) ]
45
45
pub ( crate ) enum Error < ' tcx > {
46
46
/// The provided argument is the invalid type for the expected input
47
47
Invalid ( ProvidedIdx , ExpectedIdx , Compatibility < ' tcx > ) ,
@@ -55,6 +55,34 @@ pub(crate) enum Error<'tcx> {
55
55
Permutation ( Vec < ( ExpectedIdx , ProvidedIdx ) > ) ,
56
56
}
57
57
58
+ impl Ord for Error < ' _ > {
59
+ fn cmp ( & self , other : & Self ) -> Ordering {
60
+ let key = |error : & Error < ' _ > | -> usize {
61
+ match error {
62
+ Error :: Invalid ( ..) => 0 ,
63
+ Error :: Extra ( _) => 1 ,
64
+ Error :: Missing ( _) => 2 ,
65
+ Error :: Swap ( ..) => 3 ,
66
+ Error :: Permutation ( ..) => 4 ,
67
+ }
68
+ } ;
69
+ match ( self , other) {
70
+ ( Error :: Invalid ( a, _, _) , Error :: Invalid ( b, _, _) ) => a. cmp ( b) ,
71
+ ( Error :: Extra ( a) , Error :: Extra ( b) ) => a. cmp ( b) ,
72
+ ( Error :: Missing ( a) , Error :: Missing ( b) ) => a. cmp ( b) ,
73
+ ( Error :: Swap ( a, b, ..) , Error :: Swap ( c, d, ..) ) => a. cmp ( c) . then ( b. cmp ( d) ) ,
74
+ ( Error :: Permutation ( a) , Error :: Permutation ( b) ) => a. cmp ( b) ,
75
+ _ => key ( self ) . cmp ( & key ( other) ) ,
76
+ }
77
+ }
78
+ }
79
+
80
+ impl PartialOrd for Error < ' _ > {
81
+ fn partial_cmp ( & self , other : & Self ) -> Option < Ordering > {
82
+ Some ( self . cmp ( other) )
83
+ }
84
+ }
85
+
58
86
pub ( crate ) struct ArgMatrix < ' tcx > {
59
87
/// Maps the indices in the `compatibility_matrix` rows to the indices of
60
88
/// the *user provided* inputs
@@ -378,11 +406,7 @@ impl<'tcx> ArgMatrix<'tcx> {
378
406
379
407
// sort errors with same type by the order they appear in the source
380
408
// so that suggestion will be handled properly, see #112507
381
- errors. sort_by ( |a, b| match ( a, b) {
382
- ( Error :: Missing ( i) , Error :: Missing ( j) ) => i. cmp ( j) ,
383
- ( Error :: Extra ( i) , Error :: Extra ( j) ) => i. cmp ( j) ,
384
- _ => Ordering :: Equal ,
385
- } ) ;
409
+ errors. sort ( ) ;
386
410
return ( errors, matched_inputs) ;
387
411
}
388
412
}
0 commit comments