@@ -1614,8 +1614,8 @@ fn all_ranges<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>], ty: Ty<'tcx>)
1614
1614
let rhs_val = rhs. int_value ( cx, ty) ?;
1615
1615
1616
1616
let rhs_bound = match range_end {
1617
- RangeEnd :: Included => Bound :: Included ( rhs_val) ,
1618
- RangeEnd :: Excluded => Bound :: Excluded ( rhs_val) ,
1617
+ RangeEnd :: Included => EndBound :: Included ( rhs_val) ,
1618
+ RangeEnd :: Excluded => EndBound :: Excluded ( rhs_val) ,
1619
1619
} ;
1620
1620
return Some ( SpannedRange {
1621
1621
span : pat. span ,
@@ -1627,7 +1627,7 @@ fn all_ranges<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>], ty: Ty<'tcx>)
1627
1627
let value = constant_full_int ( cx, cx. typeck_results ( ) , value) ?;
1628
1628
return Some ( SpannedRange {
1629
1629
span : pat. span ,
1630
- node : ( value, Bound :: Included ( value) ) ,
1630
+ node : ( value, EndBound :: Included ( value) ) ,
1631
1631
} ) ;
1632
1632
}
1633
1633
}
@@ -1636,16 +1636,16 @@ fn all_ranges<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>], ty: Ty<'tcx>)
1636
1636
. collect ( )
1637
1637
}
1638
1638
1639
- #[ derive( Copy , Clone , Debug , Eq , PartialEq ) ]
1640
- pub enum Bound < T > {
1639
+ #[ derive( Clone , Copy , Debug , Eq , PartialEq ) ]
1640
+ pub enum EndBound < T > {
1641
1641
Included ( T ) ,
1642
1642
Excluded ( T ) ,
1643
1643
}
1644
1644
1645
1645
#[ derive( Debug , Eq , PartialEq ) ]
1646
1646
pub struct SpannedRange < T > {
1647
1647
pub span : Span ,
1648
- pub node : ( T , Bound < T > ) ,
1648
+ pub node : ( T , EndBound < T > ) ,
1649
1649
}
1650
1650
1651
1651
// Checks if arm has the form `None => None`
@@ -1701,14 +1701,13 @@ where
1701
1701
#[ derive( Copy , Clone , Debug , Eq , PartialEq ) ]
1702
1702
enum Kind < ' a , T > {
1703
1703
Start ( T , & ' a SpannedRange < T > ) ,
1704
- End ( Bound < T > , & ' a SpannedRange < T > ) ,
1704
+ End ( EndBound < T > , & ' a SpannedRange < T > ) ,
1705
1705
}
1706
1706
1707
1707
impl < ' a , T : Copy > Kind < ' a , T > {
1708
- fn value ( self ) -> Bound < T > {
1708
+ fn value ( self ) -> T {
1709
1709
match self {
1710
- Kind :: Start ( t, _) => Bound :: Included ( t) ,
1711
- Kind :: End ( t, _) => t,
1710
+ Kind :: Start ( t, _) | Kind :: End ( EndBound :: Included ( t) | EndBound :: Excluded ( t) , _) => t,
1712
1711
}
1713
1712
}
1714
1713
}
@@ -1721,28 +1720,23 @@ where
1721
1720
1722
1721
impl < ' a , T : Copy + Ord > Ord for Kind < ' a , T > {
1723
1722
fn cmp ( & self , other : & Self ) -> Ordering {
1724
- match ( self . value ( ) , other. value ( ) ) {
1725
- ( Bound :: Included ( a) , Bound :: Included ( b) ) | ( Bound :: Excluded ( a) , Bound :: Excluded ( b) ) => {
1726
- let value_cmp = a. cmp ( & b) ;
1727
- // In the case of ties, starts come before ends
1728
- if value_cmp == Ordering :: Equal {
1729
- match ( self , other) {
1730
- ( Kind :: Start ( ..) , Kind :: End ( ..) ) => Ordering :: Less ,
1731
- ( Kind :: End ( ..) , Kind :: Start ( ..) ) => Ordering :: Greater ,
1732
- _ => Ordering :: Equal ,
1733
- }
1734
- } else {
1735
- value_cmp
1736
- }
1737
- } ,
1738
- ( Bound :: Included ( a) , Bound :: Excluded ( b) ) => match a. cmp ( & b) {
1739
- Ordering :: Equal => Ordering :: Greater ,
1740
- other => other,
1741
- } ,
1742
- ( Bound :: Excluded ( a) , Bound :: Included ( b) ) => match a. cmp ( & b) {
1743
- Ordering :: Equal => Ordering :: Less ,
1744
- other => other,
1723
+ match self . value ( ) . cmp ( & other. value ( ) ) {
1724
+ Ordering :: Equal => match ( self , other) {
1725
+ // End excluded before start and end included
1726
+ ( Kind :: End ( EndBound :: Excluded ( _) , _) , Kind :: Start ( ..) | Kind :: End ( EndBound :: Included ( _) , _) ) => {
1727
+ Ordering :: Less
1728
+ } ,
1729
+ ( Kind :: Start ( ..) | Kind :: End ( EndBound :: Included ( _) , _) , Kind :: End ( EndBound :: Excluded ( _) , _) ) => {
1730
+ Ordering :: Greater
1731
+ } ,
1732
+
1733
+ // Start before end included
1734
+ ( Kind :: Start ( ..) , Kind :: End ( EndBound :: Included ( _) , _) ) => Ordering :: Less ,
1735
+ ( Kind :: End ( EndBound :: Included ( _) , _) , Kind :: Start ( ..) ) => Ordering :: Greater ,
1736
+
1737
+ _ => Ordering :: Equal ,
1745
1738
} ,
1739
+ other => other,
1746
1740
}
1747
1741
}
1748
1742
}
@@ -2224,29 +2218,29 @@ fn test_overlapping() {
2224
2218
} ;
2225
2219
2226
2220
assert_eq ! ( None , overlapping:: <u8 >( & [ ] ) ) ;
2227
- assert_eq ! ( None , overlapping( & [ sp( 1 , Bound :: Included ( 4 ) ) ] ) ) ;
2221
+ assert_eq ! ( None , overlapping( & [ sp( 1 , EndBound :: Included ( 4 ) ) ] ) ) ;
2228
2222
assert_eq ! (
2229
2223
None ,
2230
- overlapping( & [ sp( 1 , Bound :: Included ( 4 ) ) , sp( 5 , Bound :: Included ( 6 ) ) ] )
2224
+ overlapping( & [ sp( 1 , EndBound :: Included ( 4 ) ) , sp( 5 , EndBound :: Included ( 6 ) ) ] )
2231
2225
) ;
2232
2226
assert_eq ! (
2233
2227
None ,
2234
2228
overlapping( & [
2235
- sp( 1 , Bound :: Included ( 4 ) ) ,
2236
- sp( 5 , Bound :: Included ( 6 ) ) ,
2237
- sp( 10 , Bound :: Included ( 11 ) )
2229
+ sp( 1 , EndBound :: Included ( 4 ) ) ,
2230
+ sp( 5 , EndBound :: Included ( 6 ) ) ,
2231
+ sp( 10 , EndBound :: Included ( 11 ) )
2238
2232
] , )
2239
2233
) ;
2240
2234
assert_eq ! (
2241
- Some ( ( & sp( 1 , Bound :: Included ( 4 ) ) , & sp( 3 , Bound :: Included ( 6 ) ) ) ) ,
2242
- overlapping( & [ sp( 1 , Bound :: Included ( 4 ) ) , sp( 3 , Bound :: Included ( 6 ) ) ] )
2235
+ Some ( ( & sp( 1 , EndBound :: Included ( 4 ) ) , & sp( 3 , EndBound :: Included ( 6 ) ) ) ) ,
2236
+ overlapping( & [ sp( 1 , EndBound :: Included ( 4 ) ) , sp( 3 , EndBound :: Included ( 6 ) ) ] )
2243
2237
) ;
2244
2238
assert_eq ! (
2245
- Some ( ( & sp( 5 , Bound :: Included ( 6 ) ) , & sp( 6 , Bound :: Included ( 11 ) ) ) ) ,
2239
+ Some ( ( & sp( 5 , EndBound :: Included ( 6 ) ) , & sp( 6 , EndBound :: Included ( 11 ) ) ) ) ,
2246
2240
overlapping( & [
2247
- sp( 1 , Bound :: Included ( 4 ) ) ,
2248
- sp( 5 , Bound :: Included ( 6 ) ) ,
2249
- sp( 6 , Bound :: Included ( 11 ) )
2241
+ sp( 1 , EndBound :: Included ( 4 ) ) ,
2242
+ sp( 5 , EndBound :: Included ( 6 ) ) ,
2243
+ sp( 6 , EndBound :: Included ( 11 ) )
2250
2244
] , )
2251
2245
) ;
2252
2246
}
0 commit comments