1+ use crate :: cmp:: Ordering ;
12use crate :: ffi:: CStr ;
23use crate :: fmt;
4+ use crate :: hash:: { Hash , Hasher } ;
35use crate :: marker:: PhantomData ;
46use crate :: ptr:: NonNull ;
57
@@ -32,7 +34,7 @@ use crate::ptr::NonNull;
3234/// Files are compared as strings, not `Path`, which could be unexpected.
3335/// See [`Location::file`]'s documentation for more discussion.
3436#[ lang = "panic_location" ]
35- #[ derive( Copy , Clone , Eq , Hash , Ord , PartialEq , PartialOrd ) ]
37+ #[ derive( Copy , Clone ) ]
3638#[ stable( feature = "panic_hooks" , since = "1.10.0" ) ]
3739pub struct Location < ' a > {
3840 // A raw pointer is used rather than a reference because the pointer is valid for one more byte
@@ -44,6 +46,42 @@ pub struct Location<'a> {
4446 _filename : PhantomData < & ' a str > ,
4547}
4648
49+ #[ stable( feature = "panic_hooks" , since = "1.10.0" ) ]
50+ impl PartialEq for Location < ' _ > {
51+ fn eq ( & self , other : & Self ) -> bool {
52+ self . file ( ) == other. file ( ) && self . line == other. line && self . col == other. col
53+ }
54+ }
55+
56+ #[ stable( feature = "panic_hooks" , since = "1.10.0" ) ]
57+ impl Eq for Location < ' _ > { }
58+
59+ #[ stable( feature = "panic_hooks" , since = "1.10.0" ) ]
60+ impl Ord for Location < ' _ > {
61+ fn cmp ( & self , other : & Self ) -> Ordering {
62+ self . file ( )
63+ . cmp ( other. file ( ) )
64+ . then_with ( || self . line . cmp ( & other. line ) )
65+ . then_with ( || self . col . cmp ( & other. col ) )
66+ }
67+ }
68+
69+ #[ stable( feature = "panic_hooks" , since = "1.10.0" ) ]
70+ impl PartialOrd for Location < ' _ > {
71+ fn partial_cmp ( & self , other : & Self ) -> Option < Ordering > {
72+ Some ( self . cmp ( other) )
73+ }
74+ }
75+
76+ #[ stable( feature = "panic_hooks" , since = "1.10.0" ) ]
77+ impl Hash for Location < ' _ > {
78+ fn hash < H : Hasher > ( & self , state : & mut H ) {
79+ self . file ( ) . hash ( state) ;
80+ self . line . hash ( state) ;
81+ self . col . hash ( state) ;
82+ }
83+ }
84+
4785#[ stable( feature = "panic_hooks" , since = "1.10.0" ) ]
4886impl fmt:: Debug for Location < ' _ > {
4987 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
0 commit comments