@@ -138,13 +138,9 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
138
138
panic ! ( "you should have called add_variants_to_switch instead!" ) ;
139
139
}
140
140
PatternKind :: Range { ty, lo, hi, end } => {
141
- indices
142
- . keys ( )
143
- . all ( |value| {
144
- !self
145
- . const_range_contains ( ty, lo, hi, end, value)
146
- . unwrap_or ( true )
147
- } )
141
+ // Check that none of the switch values are in the range.
142
+ self . values_not_contained_in_range ( ty, lo, hi, end, indices)
143
+ . unwrap_or ( false )
148
144
}
149
145
PatternKind :: Slice { .. } |
150
146
PatternKind :: Array { .. } |
@@ -541,16 +537,12 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
541
537
542
538
( & TestKind :: SwitchInt { switch_ty : _, ref options, ref indices } ,
543
539
& PatternKind :: Range { ty, lo, hi, end } ) => {
544
- let not_contained = indices
545
- . keys ( )
546
- . all ( |value| {
547
- !self
548
- . const_range_contains ( ty, lo, hi, end, value)
549
- . unwrap_or ( true )
550
- } ) ;
540
+ let not_contained = self
541
+ . values_not_contained_in_range ( ty, lo, hi, end, indices)
542
+ . unwrap_or ( false ) ;
551
543
552
544
if not_contained {
553
- // No values are contained in the pattern range,
545
+ // No switch values are contained in the pattern range,
554
546
// so the pattern can be matched only if this test fails.
555
547
let otherwise = options. len ( ) ;
556
548
resulting_candidates[ otherwise] . push ( candidate. clone ( ) ) ;
@@ -835,6 +827,23 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
835
827
_ => Some ( false ) ,
836
828
}
837
829
}
830
+
831
+ fn values_not_contained_in_range (
832
+ & self ,
833
+ ty : Ty < ' tcx > ,
834
+ lo : & ' tcx ty:: Const < ' tcx > ,
835
+ hi : & ' tcx ty:: Const < ' tcx > ,
836
+ end : RangeEnd ,
837
+ indices : & FxHashMap < & ' tcx ty:: Const < ' tcx > , usize > ,
838
+ ) -> Option < bool > {
839
+ for val in indices. keys ( ) {
840
+ if self . const_range_contains ( ty, lo, hi, end, val) ? {
841
+ return Some ( false ) ;
842
+ }
843
+ }
844
+
845
+ Some ( true )
846
+ }
838
847
}
839
848
840
849
fn is_switch_ty < ' tcx > ( ty : Ty < ' tcx > ) -> bool {
0 commit comments