@@ -72,16 +72,11 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
72
72
}
73
73
}
74
74
75
- PatternKind :: Range { lo , hi , ty , end } => {
76
- assert ! ( ty == match_pair. pattern. ty) ;
75
+ PatternKind :: Range ( range ) => {
76
+ assert ! ( range . ty == match_pair. pattern. ty) ;
77
77
Test {
78
78
span : match_pair. pattern . span ,
79
- kind : TestKind :: Range {
80
- lo,
81
- hi,
82
- ty,
83
- end,
84
- } ,
79
+ kind : TestKind :: Range ( range) ,
85
80
}
86
81
}
87
82
@@ -137,9 +132,9 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
137
132
PatternKind :: Variant { .. } => {
138
133
panic ! ( "you should have called add_variants_to_switch instead!" ) ;
139
134
}
140
- PatternKind :: Range { ty , lo , hi , end } => {
135
+ PatternKind :: Range ( range ) => {
141
136
// Check that none of the switch values are in the range.
142
- self . values_not_contained_in_range ( ty , lo , hi , end , indices)
137
+ self . values_not_contained_in_range ( range , indices)
143
138
. unwrap_or ( false )
144
139
}
145
140
PatternKind :: Slice { .. } |
@@ -381,7 +376,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
381
376
}
382
377
}
383
378
384
- TestKind :: Range { ref lo, ref hi, ty, ref end } => {
379
+ TestKind :: Range ( PatternRange { ref lo, ref hi, ty, ref end } ) => {
385
380
// Test `val` by computing `lo <= val && val <= hi`, using primitive comparisons.
386
381
let lo = self . literal_operand ( test. span , ty. clone ( ) , lo. clone ( ) ) ;
387
382
let hi = self . literal_operand ( test. span , ty. clone ( ) , hi. clone ( ) ) ;
@@ -536,9 +531,9 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
536
531
}
537
532
538
533
( & TestKind :: SwitchInt { switch_ty : _, ref options, ref indices } ,
539
- & PatternKind :: Range { ty , lo , hi , end } ) => {
534
+ & PatternKind :: Range ( range ) ) => {
540
535
let not_contained = self
541
- . values_not_contained_in_range ( ty , lo , hi , end , indices)
536
+ . values_not_contained_in_range ( range , indices)
542
537
. unwrap_or ( false ) ;
543
538
544
539
if not_contained {
@@ -630,12 +625,9 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
630
625
}
631
626
}
632
627
633
- ( & TestKind :: Range {
634
- lo : test_lo, hi : test_hi, ty : test_ty, end : test_end,
635
- } , & PatternKind :: Range {
636
- lo : pat_lo, hi : pat_hi, ty : _, end : pat_end,
637
- } ) => {
638
- if ( test_lo, test_hi, test_end) == ( pat_lo, pat_hi, pat_end) {
628
+ ( & TestKind :: Range ( test) ,
629
+ & PatternKind :: Range ( pat) ) => {
630
+ if test == pat {
639
631
resulting_candidates[ 0 ]
640
632
. push ( self . candidate_without_match_pair (
641
633
match_pair_index,
@@ -648,13 +640,13 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
648
640
use std:: cmp:: Ordering :: * ;
649
641
use rustc:: hir:: RangeEnd :: * ;
650
642
651
- let param_env = ty:: ParamEnv :: empty ( ) . and ( test_ty ) ;
643
+ let param_env = ty:: ParamEnv :: empty ( ) . and ( test . ty ) ;
652
644
let tcx = self . hir . tcx ( ) ;
653
645
654
- let lo = compare_const_vals ( tcx, test_lo , pat_hi , param_env) ?;
655
- let hi = compare_const_vals ( tcx, test_hi , pat_lo , param_env) ?;
646
+ let lo = compare_const_vals ( tcx, test . lo , pat . hi , param_env) ?;
647
+ let hi = compare_const_vals ( tcx, test . hi , pat . lo , param_env) ?;
656
648
657
- match ( test_end , pat_end , lo, hi) {
649
+ match ( test . end , pat . end , lo, hi) {
658
650
// pat < test
659
651
( _, _, Greater , _) |
660
652
( _, Excluded , Equal , _) |
@@ -675,12 +667,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
675
667
}
676
668
}
677
669
678
- ( & TestKind :: Range {
679
- lo, hi, ty, end
680
- } , & PatternKind :: Constant {
681
- ref value
682
- } ) => {
683
- if self . const_range_contains ( ty, lo, hi, end, value) == Some ( false ) {
670
+ ( & TestKind :: Range ( range) , & PatternKind :: Constant { ref value } ) => {
671
+ if self . const_range_contains ( range, value) == Some ( false ) {
684
672
// `value` is not contained in the testing range,
685
673
// so `value` can be matched only if this test fails.
686
674
resulting_candidates[ 1 ] . push ( candidate. clone ( ) ) ;
@@ -807,21 +795,18 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
807
795
808
796
fn const_range_contains (
809
797
& self ,
810
- ty : Ty < ' tcx > ,
811
- lo : & ' tcx ty:: Const < ' tcx > ,
812
- hi : & ' tcx ty:: Const < ' tcx > ,
813
- end : RangeEnd ,
798
+ range : PatternRange < ' tcx > ,
814
799
value : & ' tcx ty:: Const < ' tcx > ,
815
800
) -> Option < bool > {
816
801
use std:: cmp:: Ordering :: * ;
817
802
818
- let param_env = ty:: ParamEnv :: empty ( ) . and ( ty) ;
803
+ let param_env = ty:: ParamEnv :: empty ( ) . and ( range . ty ) ;
819
804
let tcx = self . hir . tcx ( ) ;
820
805
821
- let a = compare_const_vals ( tcx, lo, value, param_env) ?;
822
- let b = compare_const_vals ( tcx, value, hi, param_env) ?;
806
+ let a = compare_const_vals ( tcx, range . lo , value, param_env) ?;
807
+ let b = compare_const_vals ( tcx, value, range . hi , param_env) ?;
823
808
824
- match ( b, end) {
809
+ match ( b, range . end ) {
825
810
( Less , _) |
826
811
( Equal , RangeEnd :: Included ) if a != Greater => Some ( true ) ,
827
812
_ => Some ( false ) ,
@@ -830,14 +815,11 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
830
815
831
816
fn values_not_contained_in_range (
832
817
& self ,
833
- ty : Ty < ' tcx > ,
834
- lo : & ' tcx ty:: Const < ' tcx > ,
835
- hi : & ' tcx ty:: Const < ' tcx > ,
836
- end : RangeEnd ,
818
+ range : PatternRange < ' tcx > ,
837
819
indices : & FxHashMap < & ' tcx ty:: Const < ' tcx > , usize > ,
838
820
) -> Option < bool > {
839
821
for val in indices. keys ( ) {
840
- if self . const_range_contains ( ty , lo , hi , end , val) ? {
822
+ if self . const_range_contains ( range , val) ? {
841
823
return Some ( false ) ;
842
824
}
843
825
}
0 commit comments