@@ -127,21 +127,21 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
127
127
match_start_span : Span ,
128
128
scrutinee_span : Span ,
129
129
block : BasicBlock ,
130
+ otherwise_block : BasicBlock ,
130
131
place_builder : & PlaceBuilder < ' tcx > ,
131
132
test : & Test < ' tcx > ,
132
133
target_blocks : FxIndexMap < TestBranch < ' tcx > , BasicBlock > ,
133
134
) {
134
135
let place = place_builder. to_place ( self ) ;
135
136
let place_ty = place. ty ( & self . local_decls , self . tcx ) ;
136
137
debug ! ( ?place, ?place_ty) ;
137
- let target_block = |branch| target_blocks[ & branch] ;
138
+ let target_block = |branch| target_blocks. get ( & branch) . copied ( ) . unwrap_or ( otherwise_block ) ;
138
139
139
140
let source_info = self . source_info ( test. span ) ;
140
141
match test. kind {
141
142
TestKind :: Switch { adt_def, ref variants } => {
142
143
// Variants is a BitVec of indexes into adt_def.variants.
143
144
let num_enum_variants = adt_def. variants ( ) . len ( ) ;
144
- debug_assert_eq ! ( target_blocks. len( ) , num_enum_variants + 1 ) ;
145
145
let otherwise_block = target_block ( TestBranch :: Failure ) ;
146
146
let tcx = self . tcx ;
147
147
let switch_targets = SwitchTargets :: new (
@@ -185,7 +185,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
185
185
186
186
TestKind :: SwitchInt { ref options } => {
187
187
// The switch may be inexhaustive so we have a catch-all block
188
- debug_assert_eq ! ( options. len( ) + 1 , target_blocks. len( ) ) ;
189
188
let otherwise_block = target_block ( TestBranch :: Failure ) ;
190
189
let switch_targets = SwitchTargets :: new (
191
190
options
@@ -201,7 +200,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
201
200
}
202
201
203
202
TestKind :: If => {
204
- debug_assert_eq ! ( target_blocks. len( ) , 2 ) ;
205
203
let success_block = target_block ( TestBranch :: Success ) ;
206
204
let fail_block = target_block ( TestBranch :: Failure ) ;
207
205
let terminator =
@@ -211,7 +209,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
211
209
212
210
TestKind :: Eq { value, ty } => {
213
211
let tcx = self . tcx ;
214
- debug_assert_eq ! ( target_blocks. len( ) , 2 ) ;
215
212
let success_block = target_block ( TestBranch :: Success ) ;
216
213
let fail_block = target_block ( TestBranch :: Failure ) ;
217
214
if let ty:: Adt ( def, _) = ty. kind ( )
@@ -290,7 +287,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
290
287
}
291
288
292
289
TestKind :: Range ( ref range) => {
293
- debug_assert_eq ! ( target_blocks. len( ) , 2 ) ;
294
290
let success = target_block ( TestBranch :: Success ) ;
295
291
let fail = target_block ( TestBranch :: Failure ) ;
296
292
// Test `val` by computing `lo <= val && val <= hi`, using primitive comparisons.
@@ -337,7 +333,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
337
333
// expected = <N>
338
334
let expected = self . push_usize ( block, source_info, len) ;
339
335
340
- debug_assert_eq ! ( target_blocks. len( ) , 2 ) ;
341
336
let success_block = target_block ( TestBranch :: Success ) ;
342
337
let fail_block = target_block ( TestBranch :: Failure ) ;
343
338
// result = actual == expected OR result = actual < expected
@@ -753,33 +748,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
753
748
}
754
749
}
755
750
756
- impl < ' tcx > Test < ' tcx > {
757
- pub ( super ) fn targets ( & self ) -> Vec < TestBranch < ' tcx > > {
758
- match self . kind {
759
- TestKind :: Eq { .. } | TestKind :: Range ( _) | TestKind :: Len { .. } | TestKind :: If => {
760
- vec ! [ TestBranch :: Success , TestBranch :: Failure ]
761
- }
762
- TestKind :: Switch { adt_def, .. } => {
763
- // While the switch that we generate doesn't test for all
764
- // variants, we have a target for each variant and the
765
- // otherwise case, and we make sure that all of the cases not
766
- // specified have the same block.
767
- adt_def
768
- . variants ( )
769
- . indices ( )
770
- . map ( |idx| TestBranch :: Variant ( idx) )
771
- . chain ( [ TestBranch :: Failure ] )
772
- . collect ( )
773
- }
774
- TestKind :: SwitchInt { ref options } => options
775
- . iter ( )
776
- . map ( |( val, bits) | TestBranch :: Constant ( * val, * bits) )
777
- . chain ( [ TestBranch :: Failure ] )
778
- . collect ( ) ,
779
- }
780
- }
781
- }
782
-
783
751
fn is_switch_ty ( ty : Ty < ' _ > ) -> bool {
784
752
ty. is_integral ( ) || ty. is_char ( )
785
753
}
0 commit comments