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,44 @@ 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+         // 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+ 
4787#[ stable( feature = "panic_hooks" ,  since = "1.10.0" ) ]  
4888impl  fmt:: Debug  for  Location < ' _ >  { 
4989    fn  fmt ( & self ,  f :  & mut  fmt:: Formatter < ' _ > )  -> fmt:: Result  { 
0 commit comments