@@ -238,11 +238,14 @@ pub trait ToStableHashKey<HCX> {
238238/// The associated constant `CAN_USE_UNSTABLE_SORT` denotes whether
239239/// unstable sorting can be used for this type. Set to true if and
240240/// only if `a == b` implies `a` and `b` are fully indistinguishable.
241- pub unsafe trait StableOrd : Ord {
241+ ///
242+ /// **Be careful when implementing this trait, as an incorrect
243+ /// implementation can cause miscompilation!**
244+ pub trait StableOrd : Ord {
242245 const CAN_USE_UNSTABLE_SORT : bool ;
243246}
244247
245- unsafe impl < T : StableOrd > StableOrd for & T {
248+ impl < T : StableOrd > StableOrd for & T {
246249 const CAN_USE_UNSTABLE_SORT : bool = T :: CAN_USE_UNSTABLE_SORT ;
247250}
248251
@@ -290,7 +293,7 @@ macro_rules! impl_stable_traits_for_trivial_type {
290293 }
291294 }
292295
293- unsafe impl $crate:: stable_hasher:: StableOrd for $t {
296+ impl $crate:: stable_hasher:: StableOrd for $t {
294297 const CAN_USE_UNSTABLE_SORT : bool = true ;
295298 }
296299 } ;
@@ -327,7 +330,7 @@ impl<CTX> HashStable<CTX> for Hash128 {
327330 }
328331}
329332
330- unsafe impl StableOrd for Hash128 {
333+ impl StableOrd for Hash128 {
331334 const CAN_USE_UNSTABLE_SORT : bool = true ;
332335}
333336
@@ -392,7 +395,7 @@ impl<T1: HashStable<CTX>, T2: HashStable<CTX>, CTX> HashStable<CTX> for (T1, T2)
392395 }
393396}
394397
395- unsafe impl < T1 : StableOrd , T2 : StableOrd > StableOrd for ( T1 , T2 ) {
398+ impl < T1 : StableOrd , T2 : StableOrd > StableOrd for ( T1 , T2 ) {
396399 const CAN_USE_UNSTABLE_SORT : bool = T1 :: CAN_USE_UNSTABLE_SORT && T2 :: CAN_USE_UNSTABLE_SORT ;
397400}
398401
@@ -410,7 +413,7 @@ where
410413 }
411414}
412415
413- unsafe impl < T1 : StableOrd , T2 : StableOrd , T3 : StableOrd > StableOrd for ( T1 , T2 , T3 ) {
416+ impl < T1 : StableOrd , T2 : StableOrd , T3 : StableOrd > StableOrd for ( T1 , T2 , T3 ) {
414417 const CAN_USE_UNSTABLE_SORT : bool =
415418 T1 :: CAN_USE_UNSTABLE_SORT && T2 :: CAN_USE_UNSTABLE_SORT && T3 :: CAN_USE_UNSTABLE_SORT ;
416419}
@@ -431,9 +434,7 @@ where
431434 }
432435}
433436
434- unsafe impl < T1 : StableOrd , T2 : StableOrd , T3 : StableOrd , T4 : StableOrd > StableOrd
435- for ( T1 , T2 , T3 , T4 )
436- {
437+ impl < T1 : StableOrd , T2 : StableOrd , T3 : StableOrd , T4 : StableOrd > StableOrd for ( T1 , T2 , T3 , T4 ) {
437438 const CAN_USE_UNSTABLE_SORT : bool = T1 :: CAN_USE_UNSTABLE_SORT
438439 && T2 :: CAN_USE_UNSTABLE_SORT
439440 && T3 :: CAN_USE_UNSTABLE_SORT
@@ -530,7 +531,7 @@ impl<CTX> HashStable<CTX> for str {
530531 }
531532}
532533
533- unsafe impl StableOrd for & str {
534+ impl StableOrd for & str {
534535 const CAN_USE_UNSTABLE_SORT : bool = true ;
535536}
536537
@@ -541,9 +542,9 @@ impl<CTX> HashStable<CTX> for String {
541542 }
542543}
543544
544- // Safety: String comparison only depends on their contents and the
545+ // String comparison only depends on their contents and the
545546// contents are not changed by (de-)serialization.
546- unsafe impl StableOrd for String {
547+ impl StableOrd for String {
547548 const CAN_USE_UNSTABLE_SORT : bool = true ;
548549}
549550
@@ -570,8 +571,8 @@ impl<CTX> HashStable<CTX> for bool {
570571 }
571572}
572573
573- // Safety: sort order of bools is not changed by (de-)serialization.
574- unsafe impl StableOrd for bool {
574+ // sort order of bools is not changed by (de-)serialization.
575+ impl StableOrd for bool {
575576 const CAN_USE_UNSTABLE_SORT : bool = true ;
576577}
577578
@@ -590,8 +591,8 @@ where
590591 }
591592}
592593
593- // Safety: the Option wrapper does not add instability to comparison.
594- unsafe impl < T : StableOrd > StableOrd for Option < T > {
594+ // the Option wrapper does not add instability to comparison.
595+ impl < T : StableOrd > StableOrd for Option < T > {
595596 const CAN_USE_UNSTABLE_SORT : bool = T :: CAN_USE_UNSTABLE_SORT ;
596597}
597598
0 commit comments