@@ -649,9 +649,7 @@ impl<'tcx> Constructor<'tcx> {
649
649
match self {
650
650
// Any base constructor can be used unchanged.
651
651
Single | Variant ( _) | ConstantValue ( _) | FixedLenSlice ( _) => smallvec ! [ self ] ,
652
- ConstantRange ( ..) | IntRange ( ..)
653
- if IntRange :: should_treat_range_exhaustively ( cx. tcx , ty) =>
654
- {
652
+ IntRange ( ..) if IntRange :: should_treat_range_exhaustively ( cx. tcx , ty) => {
655
653
// Splitting up a range naïvely would mean creating a separate constructor for
656
654
// every single value in the range, which is clearly impractical. We therefore want
657
655
// to keep together subranges for which the specialisation will be identical across
@@ -736,6 +734,7 @@ impl<'tcx> Constructor<'tcx> {
736
734
. map ( |range| IntRange :: range_to_ctor ( cx. tcx , ty, range) )
737
735
. collect ( )
738
736
}
737
+ // When not treated exhaustively, don't split ranges.
739
738
ConstantRange ( ..) | IntRange ( ..) => smallvec ! [ self ] ,
740
739
VarLenSlice ( self_prefix, self_suffix) => {
741
740
// A variable-length slice pattern is matched by an infinite collection of
@@ -927,12 +926,8 @@ impl<'tcx> Constructor<'tcx> {
927
926
match self {
928
927
// Those constructors can't intersect with a non-wildcard meta-constructor, so we're
929
928
// fine just comparing for equality.
930
- Single | Variant ( _) => {
931
- if used_ctors. iter ( ) . any ( |c| c == & self ) {
932
- smallvec ! [ ]
933
- } else {
934
- smallvec ! [ self ]
935
- }
929
+ Single | Variant ( _) | ConstantRange ( ..) | ConstantValue ( ..) => {
930
+ if used_ctors. iter ( ) . any ( |c| c == & self ) { smallvec ! [ ] } else { smallvec ! [ self ] }
936
931
}
937
932
FixedLenSlice ( self_len) => {
938
933
let overlaps = |c : & Constructor < ' _ > | match c {
@@ -1047,7 +1042,7 @@ impl<'tcx> Constructor<'tcx> {
1047
1042
1048
1043
remaining_ctors
1049
1044
}
1050
- ConstantRange ( .. ) | ConstantValue ( .. ) | IntRange ( ..) => {
1045
+ IntRange ( ..) => {
1051
1046
let mut remaining_ctors = smallvec ! [ self ] ;
1052
1047
1053
1048
// For each used ctor, subtract from the current set of constructors.
@@ -1603,16 +1598,12 @@ impl<'tcx> IntRange<'tcx> {
1603
1598
}
1604
1599
1605
1600
fn from_ctor (
1606
- tcx : TyCtxt < ' tcx > ,
1607
- param_env : ty:: ParamEnv < ' tcx > ,
1601
+ _tcx : TyCtxt < ' tcx > ,
1602
+ _param_env : ty:: ParamEnv < ' tcx > ,
1608
1603
ctor : & Constructor < ' tcx > ,
1609
1604
) -> Option < IntRange < ' tcx > > {
1610
- // Floating-point ranges are permitted and we don't want
1611
- // to consider them when constructing integer ranges.
1612
1605
match ctor {
1613
1606
IntRange ( range) => Some ( range. clone ( ) ) ,
1614
- ConstantRange ( lo, hi, end) => Self :: from_range ( tcx, param_env, lo, hi, end) ,
1615
- ConstantValue ( val) => Self :: from_const ( tcx, param_env, val) ,
1616
1607
_ => None ,
1617
1608
}
1618
1609
}
@@ -2001,17 +1992,6 @@ fn slice_pat_covered_by_const<'tcx>(
2001
1992
Ok ( true )
2002
1993
}
2003
1994
2004
- // Whether a constructor is a range or constant with an integer type.
2005
- fn is_integral_range ( ctor : & Constructor < ' tcx > ) -> bool {
2006
- let ty = match ctor {
2007
- IntRange ( _) => return true ,
2008
- ConstantValue ( value) => value. ty ,
2009
- ConstantRange ( lo, _, _) => lo. ty ,
2010
- _ => return false ,
2011
- } ;
2012
- IntRange :: is_integral ( ty)
2013
- }
2014
-
2015
1995
/// Checks whether there exists any shared value in either `ctor` or `pat` by intersecting them.
2016
1996
// This has a single call site that can be hot
2017
1997
#[ inline( always) ]
@@ -2024,21 +2004,21 @@ fn constructor_intersects_pattern<'p, 'tcx>(
2024
2004
trace ! ( "constructor_intersects_pattern {:#?}, {:#?}" , ctor, pat) ;
2025
2005
if let Single = ctor {
2026
2006
Some ( PatStack :: default ( ) )
2027
- } else if is_integral_range ( ctor) {
2028
- let range = match * pat. kind {
2029
- PatKind :: Constant { value } => ConstantValue ( value) ,
2030
- PatKind :: Range ( PatRange { lo, hi, end } ) => ConstantRange ( lo, hi, end) ,
2007
+ } else if let IntRange ( ctor) = ctor {
2008
+ let pat = match * pat. kind {
2009
+ PatKind :: Constant { value } => IntRange :: from_const ( tcx, param_env, value) ?,
2010
+ PatKind :: Range ( PatRange { lo, hi, end } ) => {
2011
+ IntRange :: from_range ( tcx, param_env, lo, hi, & end) ?
2012
+ }
2031
2013
_ => bug ! ( "`constructor_intersects_pattern` called with {:?}" , pat) ,
2032
2014
} ;
2033
2015
2034
- let pat = IntRange :: from_ctor ( tcx, param_env, & range) ?;
2035
- let ctor = IntRange :: from_ctor ( tcx, param_env, ctor) ?;
2036
2016
ctor. intersection ( tcx, & pat) ?;
2037
2017
2038
2018
// Constructor splitting should ensure that all intersections we encounter are actually
2039
2019
// inclusions.
2040
2020
let ( pat_lo, pat_hi) = pat. range . into_inner ( ) ;
2041
- let ( ctor_lo, ctor_hi) = ctor. range . into_inner ( ) ;
2021
+ let ( ctor_lo, ctor_hi) = ctor. range . clone ( ) . into_inner ( ) ;
2042
2022
assert ! ( pat_lo <= ctor_lo && ctor_hi <= pat_hi) ;
2043
2023
2044
2024
Some ( PatStack :: default ( ) )
0 commit comments