File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -341,11 +341,29 @@ pub struct RangeInclusive<Idx> {
341341 // accept non-PartialOrd types, also we want the constructor to be const.
342342}
343343
344+ trait RangeInclusiveEquality : Sized {
345+ fn canonicalized_is_empty ( range : & RangeInclusive < Self > ) -> bool ;
346+ }
347+ impl < T > RangeInclusiveEquality for T {
348+ #[ inline]
349+ default fn canonicalized_is_empty ( range : & RangeInclusive < Self > ) -> bool {
350+ !range. is_iterating . unwrap_or ( false )
351+ }
352+ }
353+ impl < T : PartialOrd > RangeInclusiveEquality for T {
354+ #[ inline]
355+ fn canonicalized_is_empty ( range : & RangeInclusive < Self > ) -> bool {
356+ range. is_empty ( )
357+ }
358+ }
359+
344360#[ stable( feature = "inclusive_range" , since = "1.26.0" ) ]
345361impl < Idx : PartialEq > PartialEq for RangeInclusive < Idx > {
346362 #[ inline]
347363 fn eq ( & self , other : & Self ) -> bool {
348364 self . start == other. start && self . end == other. end
365+ && RangeInclusiveEquality :: canonicalized_is_empty ( self )
366+ == RangeInclusiveEquality :: canonicalized_is_empty ( other)
349367 }
350368}
351369
@@ -357,6 +375,7 @@ impl<Idx: Hash> Hash for RangeInclusive<Idx> {
357375 fn hash < H : Hasher > ( & self , state : & mut H ) {
358376 self . start . hash ( state) ;
359377 self . end . hash ( state) ;
378+ RangeInclusiveEquality :: canonicalized_is_empty ( self ) . hash ( state) ;
360379 }
361380}
362381
You can’t perform that action at this time.
0 commit comments