File tree 1 file changed +19
-0
lines changed
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> {
341
341
// accept non-PartialOrd types, also we want the constructor to be const.
342
342
}
343
343
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
+
344
360
#[ stable( feature = "inclusive_range" , since = "1.26.0" ) ]
345
361
impl < Idx : PartialEq > PartialEq for RangeInclusive < Idx > {
346
362
#[ inline]
347
363
fn eq ( & self , other : & Self ) -> bool {
348
364
self . start == other. start && self . end == other. end
365
+ && RangeInclusiveEquality :: canonicalized_is_empty ( self )
366
+ == RangeInclusiveEquality :: canonicalized_is_empty ( other)
349
367
}
350
368
}
351
369
@@ -357,6 +375,7 @@ impl<Idx: Hash> Hash for RangeInclusive<Idx> {
357
375
fn hash < H : Hasher > ( & self , state : & mut H ) {
358
376
self . start . hash ( state) ;
359
377
self . end . hash ( state) ;
378
+ RangeInclusiveEquality :: canonicalized_is_empty ( self ) . hash ( state) ;
360
379
}
361
380
}
362
381
You can’t perform that action at this time.
0 commit comments