@@ -1910,7 +1910,10 @@ fn constructor_intersects_pattern<'p, 'tcx>(
1910
1910
ctor : & Constructor < ' tcx > ,
1911
1911
pat : & ' p Pat < ' tcx > ,
1912
1912
) -> Option < PatStack < ' p , ' tcx > > {
1913
- if should_treat_range_exhaustively ( tcx, ctor) {
1913
+ trace ! ( "constructor_intersects_pattern {:#?}, {:#?}" , ctor, pat) ;
1914
+ if let Single = ctor {
1915
+ Some ( PatStack :: default ( ) )
1916
+ } else if should_treat_range_exhaustively ( tcx, ctor) {
1914
1917
let range = match * pat. kind {
1915
1918
PatKind :: Constant { value } => ConstantValue ( value) ,
1916
1919
PatKind :: Range ( PatRange { lo, hi, end } ) => ConstantRange ( lo, hi, end) ,
@@ -1929,34 +1932,22 @@ fn constructor_intersects_pattern<'p, 'tcx>(
1929
1932
// Fallback for non-ranges and ranges that involve floating-point numbers, which are not
1930
1933
// conveniently handled by `IntRange`. For these cases, the constructor may not be a range
1931
1934
// so intersection actually devolves into being covered by the pattern.
1932
- let ( from , to , end ) = match * pat. kind {
1935
+ let ( pat_from , pat_to , pat_end ) = match * pat. kind {
1933
1936
PatKind :: Constant { value } => ( value, value, RangeEnd :: Included ) ,
1934
1937
PatKind :: Range ( PatRange { lo, hi, end } ) => ( lo, hi, end) ,
1935
1938
_ => bug ! ( "`constructor_intersects_pattern` called with {:?}" , pat) ,
1936
1939
} ;
1937
- let ty = from. ty ;
1938
- trace ! ( "constructor_intersects_pattern {:#?}, {:#?}, {:#?}, {}" , ctor, from, to, ty) ;
1939
- let cmp_from = |c_from| compare_const_vals ( tcx, c_from, from, param_env, ty) ;
1940
- let cmp_to = |c_to| compare_const_vals ( tcx, c_to, to, param_env, ty) ;
1941
- let result = match * ctor {
1942
- ConstantValue ( value) => {
1943
- let to = cmp_to ( value) ?;
1944
- let from = cmp_from ( value) ?;
1945
- let end =
1946
- ( to == Ordering :: Less ) || ( end == RangeEnd :: Included && to == Ordering :: Equal ) ;
1947
- ( from != Ordering :: Less ) && end
1948
- }
1949
- ConstantRange ( from, to, range_end) => {
1950
- let to = cmp_to ( to) ?;
1951
- let from = cmp_from ( from) ?;
1952
- let end = ( to == Ordering :: Less ) || ( end == range_end && to == Ordering :: Equal ) ;
1953
- ( from != Ordering :: Less ) && end
1954
- }
1955
- Single => true ,
1956
- _ => bug ! ( ) ,
1940
+ let ( ctor_from, ctor_to, ctor_end) = match * ctor {
1941
+ ConstantValue ( value) => ( value, value, RangeEnd :: Included ) ,
1942
+ ConstantRange ( from, to, range_end) => ( from, to, range_end) ,
1943
+ _ => bug ! ( "`constructor_intersects_pattern` called with {:?}" , ctor) ,
1957
1944
} ;
1958
-
1959
- if result { Some ( PatStack :: default ( ) ) } else { None }
1945
+ let order_to = compare_const_vals ( tcx, ctor_to, pat_to, param_env, pat_from. ty ) ?;
1946
+ let order_from = compare_const_vals ( tcx, ctor_from, pat_from, param_env, pat_from. ty ) ?;
1947
+ let intersects = ( order_from != Ordering :: Less )
1948
+ && ( ( order_to == Ordering :: Less )
1949
+ || ( pat_end == ctor_end && order_to == Ordering :: Equal ) ) ;
1950
+ if intersects { Some ( PatStack :: default ( ) ) } else { None }
1960
1951
}
1961
1952
}
1962
1953
0 commit comments