@@ -1625,36 +1625,6 @@ fn split_grouped_constructors<'p, 'tcx>(
1625
1625
split_ctors
1626
1626
}
1627
1627
1628
- /// Checks whether there exists any shared value in either `ctor` or `pat` by intersecting them.
1629
- fn constructor_intersects_pattern < ' p , ' tcx > (
1630
- tcx : TyCtxt < ' tcx > ,
1631
- param_env : ty:: ParamEnv < ' tcx > ,
1632
- ctor : & Constructor < ' tcx > ,
1633
- pat : & ' p Pat < ' tcx > ,
1634
- ) -> Option < SmallVec < [ & ' p Pat < ' tcx > ; 2 ] > > {
1635
- if should_treat_range_exhaustively ( tcx, ctor) {
1636
- match ( IntRange :: from_ctor ( tcx, param_env, ctor) , IntRange :: from_pat ( tcx, param_env, pat) ) {
1637
- ( Some ( ctor) , Some ( pat) ) => {
1638
- ctor. intersection ( & pat) . map ( |_| {
1639
- let ( pat_lo, pat_hi) = pat. range . into_inner ( ) ;
1640
- let ( ctor_lo, ctor_hi) = ctor. range . into_inner ( ) ;
1641
- assert ! ( pat_lo <= ctor_lo && ctor_hi <= pat_hi) ;
1642
- smallvec ! [ ]
1643
- } )
1644
- }
1645
- _ => None ,
1646
- }
1647
- } else {
1648
- // Fallback for non-ranges and ranges that involve floating-point numbers, which are not
1649
- // conveniently handled by `IntRange`. For these cases, the constructor may not be a range
1650
- // so intersection actually devolves into being covered by the pattern.
1651
- match constructor_covered_by_range ( tcx, param_env, ctor, pat) {
1652
- Ok ( true ) => Some ( smallvec ! [ ] ) ,
1653
- Ok ( false ) | Err ( ErrorReported ) => None ,
1654
- }
1655
- }
1656
- }
1657
-
1658
1628
fn constructor_covered_by_range < ' tcx > (
1659
1629
tcx : TyCtxt < ' tcx > ,
1660
1630
param_env : ty:: ParamEnv < ' tcx > ,
@@ -1845,9 +1815,32 @@ fn specialize<'p, 'a: 'p, 'tcx>(
1845
1815
PatKind :: Constant { .. } |
1846
1816
PatKind :: Range { .. } => {
1847
1817
// If the constructor is a:
1848
- // Single value: add a row if the pattern contains the constructor.
1849
- // Range: add a row if the constructor intersects the pattern.
1850
- constructor_intersects_pattern ( cx. tcx , cx. param_env , constructor, pat)
1818
+ // - Single value: add a row if the pattern contains the constructor.
1819
+ // - Range: add a row if the constructor intersects the pattern.
1820
+ if should_treat_range_exhaustively ( cx. tcx , constructor) {
1821
+ match ( IntRange :: from_ctor ( cx. tcx , cx. param_env , constructor) ,
1822
+ IntRange :: from_pat ( cx. tcx , cx. param_env , pat) ) {
1823
+ ( Some ( ctor) , Some ( pat) ) => {
1824
+ ctor. intersection ( & pat) . map ( |_| {
1825
+ let ( pat_lo, pat_hi) = pat. range . into_inner ( ) ;
1826
+ let ( ctor_lo, ctor_hi) = ctor. range . into_inner ( ) ;
1827
+ assert ! ( pat_lo <= ctor_lo && ctor_hi <= pat_hi) ;
1828
+ smallvec ! [ ]
1829
+ } )
1830
+ }
1831
+ _ => None ,
1832
+ }
1833
+ } else {
1834
+ // Fallback for non-ranges and ranges that involve
1835
+ // floating-point numbers, which are not conveniently handled
1836
+ // by `IntRange`. For these cases, the constructor may not be a
1837
+ // range so intersection actually devolves into being covered
1838
+ // by the pattern.
1839
+ match constructor_covered_by_range ( cx. tcx , cx. param_env , constructor, pat) {
1840
+ Ok ( true ) => Some ( smallvec ! [ ] ) ,
1841
+ Ok ( false ) | Err ( ErrorReported ) => None ,
1842
+ }
1843
+ }
1851
1844
}
1852
1845
1853
1846
PatKind :: Array { ref prefix, ref slice, ref suffix } |
0 commit comments