@@ -2137,57 +2137,34 @@ fn constructor_covered_by_range<'tcx>(
2137
2137
param_env : ty:: ParamEnv < ' tcx > ,
2138
2138
ctor : & Constructor < ' tcx > ,
2139
2139
pat : & Pat < ' tcx > ,
2140
- ) -> Result < bool , ErrorReported > {
2141
- let ( from, to, end, ty) = match pat. kind {
2142
- box PatKind :: Constant { value } => ( value, value, RangeEnd :: Included , value. ty ) ,
2143
- box PatKind :: Range ( PatRange { lo, hi, end } ) => ( lo, hi, end, lo. ty ) ,
2140
+ ) -> bool {
2141
+ if let Single = ctor {
2142
+ return true ;
2143
+ }
2144
+
2145
+ let ( pat_from, pat_to, pat_end, ty) = match * pat. kind {
2146
+ PatKind :: Constant { value } => ( value, value, RangeEnd :: Included , value. ty ) ,
2147
+ PatKind :: Range ( PatRange { lo, hi, end } ) => ( lo, hi, end, lo. ty ) ,
2144
2148
_ => bug ! ( "`constructor_covered_by_range` called with {:?}" , pat) ,
2145
2149
} ;
2146
- trace ! ( "constructor_covered_by_range {:#?}, {:#?}, {:#?}, {}" , ctor, from, to, ty) ;
2147
- let cmp_from = |c_from| {
2148
- compare_const_vals ( tcx, c_from, from, param_env, ty) . map ( |res| res != Ordering :: Less )
2150
+ let from_bits = |bits| ty:: Const :: from_bits ( tcx, bits, ty:: ParamEnv :: empty ( ) . and ( ty) ) ;
2151
+ let ( ctor_from, ctor_to, ctor_end) = match * ctor {
2152
+ ConstantValue ( value, _) => ( value, value, RangeEnd :: Included ) ,
2153
+ ConstantRange ( from, to, _, ctor_end, _) => ( from_bits ( from) , from_bits ( to) , ctor_end) ,
2154
+ _ => bug ! ( "`constructor_covered_by_range` called with {:?}" , ctor) ,
2149
2155
} ;
2150
- let cmp_to = |c_to| compare_const_vals ( tcx, c_to, to, param_env, ty) ;
2151
- macro_rules! some_or_ok {
2152
- ( $e: expr) => {
2153
- match $e {
2154
- Some ( to) => to,
2155
- None => return Ok ( false ) , // not char or int
2156
- }
2157
- } ;
2158
- }
2159
- match * ctor {
2160
- ConstantValue ( value, _) => {
2161
- let to = some_or_ok ! ( cmp_to( value) ) ;
2162
- let end =
2163
- ( to == Ordering :: Less ) || ( end == RangeEnd :: Included && to == Ordering :: Equal ) ;
2164
- Ok ( some_or_ok ! ( cmp_from( value) ) && end)
2165
- }
2166
- ConstantRange ( from, to, ty, RangeEnd :: Included , _) => {
2167
- let to =
2168
- some_or_ok ! ( cmp_to( ty:: Const :: from_bits( tcx, to, ty:: ParamEnv :: empty( ) . and( ty) , ) ) ) ;
2169
- let end =
2170
- ( to == Ordering :: Less ) || ( end == RangeEnd :: Included && to == Ordering :: Equal ) ;
2171
- Ok ( some_or_ok ! ( cmp_from( ty:: Const :: from_bits(
2172
- tcx,
2173
- from,
2174
- ty:: ParamEnv :: empty( ) . and( ty) ,
2175
- ) ) ) && end)
2176
- }
2177
- ConstantRange ( from, to, ty, RangeEnd :: Excluded , _) => {
2178
- let to =
2179
- some_or_ok ! ( cmp_to( ty:: Const :: from_bits( tcx, to, ty:: ParamEnv :: empty( ) . and( ty) ) ) ) ;
2180
- let end =
2181
- ( to == Ordering :: Less ) || ( end == RangeEnd :: Excluded && to == Ordering :: Equal ) ;
2182
- Ok ( some_or_ok ! ( cmp_from( ty:: Const :: from_bits(
2183
- tcx,
2184
- from,
2185
- ty:: ParamEnv :: empty( ) . and( ty)
2186
- ) ) ) && end)
2187
- }
2188
- Single => Ok ( true ) ,
2189
- _ => bug ! ( ) ,
2190
- }
2156
+ trace ! ( "constructor_covered_by_range {:#?}, {:#?}, {:#?}, {}" , ctor, pat_from, pat_to, ty) ;
2157
+
2158
+ let to = match compare_const_vals ( tcx, ctor_to, pat_to, param_env, ty) {
2159
+ Some ( to) => to,
2160
+ None => return false ,
2161
+ } ;
2162
+ let from = match compare_const_vals ( tcx, ctor_from, pat_from, param_env, ty) {
2163
+ Some ( from) => from,
2164
+ None => return false ,
2165
+ } ;
2166
+ ( from == Ordering :: Greater || from == Ordering :: Equal )
2167
+ && ( to == Ordering :: Less || ( pat_end == ctor_end && to == Ordering :: Equal ) )
2191
2168
}
2192
2169
2193
2170
fn patterns_for_variant < ' p , ' a : ' p , ' tcx > (
@@ -2336,9 +2313,10 @@ fn specialize_one_pattern<'p, 'a: 'p, 'q: 'p, 'tcx>(
2336
2313
// by `IntRange`. For these cases, the constructor may not be a
2337
2314
// range so intersection actually devolves into being covered
2338
2315
// by the pattern.
2339
- match constructor_covered_by_range ( cx. tcx , cx. param_env , constructor, pat) {
2340
- Ok ( true ) => Some ( PatStack :: default ( ) ) ,
2341
- Ok ( false ) | Err ( ErrorReported ) => None ,
2316
+ if constructor_covered_by_range ( cx. tcx , cx. param_env , constructor, pat) {
2317
+ Some ( PatStack :: default ( ) )
2318
+ } else {
2319
+ None
2342
2320
}
2343
2321
}
2344
2322
}
0 commit comments