1
+ use crate :: cmp:: Ordering ;
1
2
use crate :: ffi:: CStr ;
2
3
use crate :: fmt;
4
+ use crate :: hash:: { Hash , Hasher } ;
3
5
use crate :: marker:: PhantomData ;
4
6
use crate :: ptr:: NonNull ;
5
7
@@ -32,7 +34,7 @@ use crate::ptr::NonNull;
32
34
/// Files are compared as strings, not `Path`, which could be unexpected.
33
35
/// See [`Location::file`]'s documentation for more discussion.
34
36
#[ lang = "panic_location" ]
35
- #[ derive( Copy , Clone , Eq , Hash , Ord , PartialEq , PartialOrd ) ]
37
+ #[ derive( Copy , Clone ) ]
36
38
#[ stable( feature = "panic_hooks" , since = "1.10.0" ) ]
37
39
pub struct Location < ' a > {
38
40
// A raw pointer is used rather than a reference because the pointer is valid for one more byte
@@ -44,6 +46,44 @@ pub struct Location<'a> {
44
46
_filename : PhantomData < & ' a str > ,
45
47
}
46
48
49
+ #[ stable( feature = "panic_hooks" , since = "1.10.0" ) ]
50
+ impl PartialEq for Location < ' _ > {
51
+ fn eq ( & self , other : & Self ) -> bool {
52
+ // Compare col / line first as they're cheaper to compare and more likely to differ,
53
+ // while not impacting the result.
54
+ self . col == other. col && self . line == other. line && self . file ( ) == other. file ( )
55
+ }
56
+ }
57
+
58
+ #[ stable( feature = "panic_hooks" , since = "1.10.0" ) ]
59
+ impl Eq for Location < ' _ > { }
60
+
61
+ #[ stable( feature = "panic_hooks" , since = "1.10.0" ) ]
62
+ impl Ord for Location < ' _ > {
63
+ fn cmp ( & self , other : & Self ) -> Ordering {
64
+ self . file ( )
65
+ . cmp ( other. file ( ) )
66
+ . then_with ( || self . line . cmp ( & other. line ) )
67
+ . then_with ( || self . col . cmp ( & other. col ) )
68
+ }
69
+ }
70
+
71
+ #[ stable( feature = "panic_hooks" , since = "1.10.0" ) ]
72
+ impl PartialOrd for Location < ' _ > {
73
+ fn partial_cmp ( & self , other : & Self ) -> Option < Ordering > {
74
+ Some ( self . cmp ( other) )
75
+ }
76
+ }
77
+
78
+ #[ stable( feature = "panic_hooks" , since = "1.10.0" ) ]
79
+ impl Hash for Location < ' _ > {
80
+ fn hash < H : Hasher > ( & self , state : & mut H ) {
81
+ self . file ( ) . hash ( state) ;
82
+ self . line . hash ( state) ;
83
+ self . col . hash ( state) ;
84
+ }
85
+ }
86
+
47
87
#[ stable( feature = "panic_hooks" , since = "1.10.0" ) ]
48
88
impl fmt:: Debug for Location < ' _ > {
49
89
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
0 commit comments