@@ -1825,6 +1825,35 @@ fn should_treat_range_exhaustively(tcx: TyCtxt<'tcx>, ctor: &Constructor<'tcx>)
1825
1825
}
1826
1826
}
1827
1827
1828
+ fn constructor_intersects_pattern < ' p , ' tcx > (
1829
+ tcx : TyCtxt < ' tcx > ,
1830
+ param_env : ty:: ParamEnv < ' tcx > ,
1831
+ ctor : & Constructor < ' tcx > ,
1832
+ pat : & ' p Pat < ' tcx > ,
1833
+ ) -> Option < PatStack < ' p , ' tcx > > {
1834
+ if should_treat_range_exhaustively ( tcx, ctor) {
1835
+ match ( IntRange :: from_ctor ( tcx, param_env, ctor) , IntRange :: from_pat ( tcx, param_env, pat) ) {
1836
+ ( Some ( ctor) , Some ( pat) ) => ctor. intersection ( & pat) . map ( |_| {
1837
+ let ( pat_lo, pat_hi) = pat. range . into_inner ( ) ;
1838
+ let ( ctor_lo, ctor_hi) = ctor. range . into_inner ( ) ;
1839
+ assert ! ( pat_lo <= ctor_lo && ctor_hi <= pat_hi) ;
1840
+ PatStack :: default ( )
1841
+ } ) ,
1842
+ _ => None ,
1843
+ }
1844
+ } else {
1845
+ // Fallback for non-ranges and ranges that involve
1846
+ // floating-point numbers, which are not conveniently handled
1847
+ // by `IntRange`. For these cases, the constructor may not be a
1848
+ // range so intersection actually devolves into being covered
1849
+ // by the pattern.
1850
+ match constructor_covered_by_range ( tcx, param_env, ctor, pat) {
1851
+ Ok ( true ) => Some ( PatStack :: default ( ) ) ,
1852
+ Ok ( false ) | Err ( ErrorReported ) => None ,
1853
+ }
1854
+ }
1855
+ }
1856
+
1828
1857
fn constructor_covered_by_range < ' tcx > (
1829
1858
tcx : TyCtxt < ' tcx > ,
1830
1859
param_env : ty:: ParamEnv < ' tcx > ,
@@ -2016,30 +2045,7 @@ fn specialize_one_pattern<'p, 'a: 'p, 'p2: 'p, 'tcx>(
2016
2045
// If the constructor is a:
2017
2046
// - Single value: add a row if the pattern contains the constructor.
2018
2047
// - Range: add a row if the constructor intersects the pattern.
2019
- if should_treat_range_exhaustively ( cx. tcx , constructor) {
2020
- match (
2021
- IntRange :: from_ctor ( cx. tcx , cx. param_env , constructor) ,
2022
- IntRange :: from_pat ( cx. tcx , cx. param_env , pat) ,
2023
- ) {
2024
- ( Some ( ctor) , Some ( pat) ) => ctor. intersection ( & pat) . map ( |_| {
2025
- let ( pat_lo, pat_hi) = pat. range . into_inner ( ) ;
2026
- let ( ctor_lo, ctor_hi) = ctor. range . into_inner ( ) ;
2027
- assert ! ( pat_lo <= ctor_lo && ctor_hi <= pat_hi) ;
2028
- PatStack :: default ( )
2029
- } ) ,
2030
- _ => None ,
2031
- }
2032
- } else {
2033
- // Fallback for non-ranges and ranges that involve
2034
- // floating-point numbers, which are not conveniently handled
2035
- // by `IntRange`. For these cases, the constructor may not be a
2036
- // range so intersection actually devolves into being covered
2037
- // by the pattern.
2038
- match constructor_covered_by_range ( cx. tcx , cx. param_env , constructor, pat) {
2039
- Ok ( true ) => Some ( PatStack :: default ( ) ) ,
2040
- Ok ( false ) | Err ( ErrorReported ) => None ,
2041
- }
2042
- }
2048
+ constructor_intersects_pattern ( cx. tcx , cx. param_env , constructor, pat)
2043
2049
}
2044
2050
2045
2051
PatKind :: Array { ref prefix, ref slice, ref suffix }
0 commit comments