@@ -34,7 +34,6 @@ use rustc_span::source_map::{Span, Spanned};
3434use rustc_span:: sym;
3535use std:: cmp:: Ordering ;
3636use std:: collections:: hash_map:: Entry ;
37- use std:: iter;
3837use std:: ops:: Bound ;
3938
4039declare_clippy_lint ! {
@@ -1703,12 +1702,6 @@ where
17031702 }
17041703
17051704 impl < ' a , T : Copy > Kind < ' a , T > {
1706- fn range ( & self ) -> & ' a SpannedRange < T > {
1707- match * self {
1708- Kind :: Start ( _, r) | Kind :: End ( _, r) => r,
1709- }
1710- }
1711-
17121705 fn value ( self ) -> Bound < T > {
17131706 match self {
17141707 Kind :: Start ( t, _) => Bound :: Included ( t) ,
@@ -1726,7 +1719,19 @@ where
17261719 impl < ' a , T : Copy + Ord > Ord for Kind < ' a , T > {
17271720 fn cmp ( & self , other : & Self ) -> Ordering {
17281721 match ( self . value ( ) , other. value ( ) ) {
1729- ( Bound :: Included ( a) , Bound :: Included ( b) ) | ( Bound :: Excluded ( a) , Bound :: Excluded ( b) ) => a. cmp ( & b) ,
1722+ ( Bound :: Included ( a) , Bound :: Included ( b) ) | ( Bound :: Excluded ( a) , Bound :: Excluded ( b) ) => {
1723+ let value_cmp = a. cmp ( & b) ;
1724+ // In the case of ties, starts come before ends
1725+ if value_cmp == Ordering :: Equal {
1726+ match ( self , other) {
1727+ ( Kind :: Start ( ..) , Kind :: End ( ..) ) => Ordering :: Less ,
1728+ ( Kind :: End ( ..) , Kind :: Start ( ..) ) => Ordering :: Greater ,
1729+ _ => Ordering :: Equal ,
1730+ }
1731+ } else {
1732+ value_cmp
1733+ }
1734+ } ,
17301735 // Range patterns cannot be unbounded (yet)
17311736 ( Bound :: Unbounded , _) | ( _, Bound :: Unbounded ) => unimplemented ! ( ) ,
17321737 ( Bound :: Included ( a) , Bound :: Excluded ( b) ) => match a. cmp ( & b) {
@@ -1750,24 +1755,17 @@ where
17501755
17511756 values. sort ( ) ;
17521757
1753- for ( a, b) in iter:: zip ( & values, values. iter ( ) . skip ( 1 ) ) {
1754- match ( a, b) {
1755- ( & Kind :: Start ( _, ra) , & Kind :: End ( _, rb) ) => {
1756- if ra. node != rb. node {
1757- return Some ( ( ra, rb) ) ;
1758- }
1759- } ,
1760- ( & Kind :: End ( a, _) , & Kind :: Start ( b, _) ) if a != Bound :: Included ( b) => ( ) ,
1761- _ => {
1762- // skip if the range `a` is completely included into the range `b`
1763- if let Ordering :: Equal | Ordering :: Less = a. cmp ( b) {
1764- let kind_a = Kind :: End ( a. range ( ) . node . 1 , a. range ( ) ) ;
1765- let kind_b = Kind :: End ( b. range ( ) . node . 1 , b. range ( ) ) ;
1766- if let Ordering :: Equal | Ordering :: Greater = kind_a. cmp ( & kind_b) {
1767- return None ;
1758+ let mut started = vec ! [ ] ;
1759+
1760+ for value in values {
1761+ match value {
1762+ Kind :: Start ( _, r) => started. push ( r) ,
1763+ Kind :: End ( _, er) => {
1764+ if let Some ( sr) = started. pop ( ) {
1765+ if sr != er {
1766+ return Some ( ( er, sr) ) ;
17681767 }
17691768 }
1770- return Some ( ( a. range ( ) , b. range ( ) ) ) ;
17711769 } ,
17721770 }
17731771 }
0 commit comments