@@ -26,6 +26,7 @@ mod simplify;
26
26
mod test;
27
27
mod util;
28
28
29
+ use itertools:: Itertools ;
29
30
use std:: convert:: TryFrom ;
30
31
31
32
impl < ' a , ' tcx > Builder < ' a , ' tcx > {
@@ -258,11 +259,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
258
259
scrutinee_span,
259
260
match_scope,
260
261
) ;
261
- this. cfg . terminate (
262
- binding_end,
263
- source_info,
264
- TerminatorKind :: Goto { target : arm_block } ,
265
- ) ;
262
+ this. cfg . goto ( binding_end, source_info, arm_block) ;
266
263
}
267
264
}
268
265
@@ -278,11 +275,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
278
275
let end_block = self . cfg . start_new_block ( ) ;
279
276
280
277
for arm_block in arm_end_blocks {
281
- self . cfg . terminate (
282
- unpack ! ( arm_block) ,
283
- outer_source_info,
284
- TerminatorKind :: Goto { target : end_block } ,
285
- ) ;
278
+ self . cfg . goto ( unpack ! ( arm_block) , outer_source_info, end_block) ;
286
279
}
287
280
288
281
self . source_scope = outer_source_info. scope ;
@@ -822,45 +815,34 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
822
815
) ;
823
816
let ( matched_candidates, unmatched_candidates) = candidates. split_at_mut ( fully_matched) ;
824
817
825
- let block: BasicBlock ;
826
-
827
- if !matched_candidates. is_empty ( ) {
818
+ let block: BasicBlock = if !matched_candidates. is_empty ( ) {
828
819
let otherwise_block = self . select_matched_candidates (
829
820
matched_candidates,
830
821
start_block,
831
822
fake_borrows,
832
823
) ;
833
824
834
825
if let Some ( last_otherwise_block) = otherwise_block {
835
- block = last_otherwise_block
826
+ last_otherwise_block
836
827
} else {
837
828
// Any remaining candidates are unreachable.
838
829
if unmatched_candidates. is_empty ( ) {
839
830
return ;
840
831
}
841
- block = self . cfg . start_new_block ( ) ;
842
- } ;
832
+ self . cfg . start_new_block ( )
833
+ }
843
834
} else {
844
- block = * start_block. get_or_insert_with ( || self . cfg . start_new_block ( ) ) ;
845
- }
835
+ * start_block. get_or_insert_with ( || self . cfg . start_new_block ( ) )
836
+ } ;
846
837
847
838
// If there are no candidates that still need testing, we're
848
839
// done. Since all matches are exhaustive, execution should
849
840
// never reach this point.
850
841
if unmatched_candidates. is_empty ( ) {
851
842
let source_info = self . source_info ( span) ;
852
- if let Some ( otherwise) = otherwise_block {
853
- self . cfg . terminate (
854
- block,
855
- source_info,
856
- TerminatorKind :: Goto { target : otherwise } ,
857
- ) ;
858
- } else {
859
- self . cfg . terminate (
860
- block,
861
- source_info,
862
- TerminatorKind :: Unreachable ,
863
- )
843
+ match otherwise_block {
844
+ Some ( otherwise) => self . cfg . goto ( block, source_info, otherwise) ,
845
+ None => self . cfg . terminate ( block, source_info, TerminatorKind :: Unreachable ) ,
864
846
}
865
847
return ;
866
848
}
@@ -885,7 +867,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
885
867
/// ...
886
868
///
887
869
/// We generate real edges from:
888
- /// * `block ` to the prebinding_block of the first pattern,
870
+ /// * `start_block ` to the ` prebinding_block` of the first pattern,
889
871
/// * the otherwise block of the first pattern to the second pattern,
890
872
/// * the otherwise block of the third pattern to the a block with an
891
873
/// Unreachable terminator.
@@ -948,32 +930,25 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
948
930
let first_candidate = & reachable_candidates[ 0 ] ;
949
931
let first_prebinding_block = first_candidate. pre_binding_block ;
950
932
933
+ // `goto -> first_prebinding_block` from the `start_block` if there is one.
951
934
if let Some ( start_block) = * start_block {
952
935
let source_info = self . source_info ( first_candidate. span ) ;
953
- self . cfg . terminate (
954
- start_block,
955
- source_info,
956
- TerminatorKind :: Goto { target : first_prebinding_block } ,
957
- ) ;
936
+ self . cfg . goto ( start_block, source_info, first_prebinding_block) ;
958
937
} else {
959
938
* start_block = Some ( first_prebinding_block) ;
960
939
}
961
940
962
- for window in reachable_candidates. windows ( 2 ) {
963
- if let [ first_candidate, second_candidate] = window {
964
- let source_info = self . source_info ( first_candidate. span ) ;
965
- if let Some ( otherwise_block) = first_candidate. otherwise_block {
966
- self . false_edges (
967
- otherwise_block,
968
- second_candidate. pre_binding_block ,
969
- first_candidate. next_candidate_pre_binding_block ,
970
- source_info,
971
- ) ;
972
- } else {
973
- bug ! ( "candidate other than the last has no guard" ) ;
974
- }
941
+ for ( first_candidate, second_candidate) in reachable_candidates. iter ( ) . tuple_windows ( ) {
942
+ let source_info = self . source_info ( first_candidate. span ) ;
943
+ if let Some ( otherwise_block) = first_candidate. otherwise_block {
944
+ self . false_edges (
945
+ otherwise_block,
946
+ second_candidate. pre_binding_block ,
947
+ first_candidate. next_candidate_pre_binding_block ,
948
+ source_info,
949
+ ) ;
975
950
} else {
976
- bug ! ( "<[_]>::windows returned incorrectly sized window " ) ;
951
+ bug ! ( "candidate other than the last has no guard " ) ;
977
952
}
978
953
}
979
954
@@ -992,8 +967,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
992
967
}
993
968
}
994
969
995
- let last_candidate = reachable_candidates. last ( ) . unwrap ( ) ;
996
970
971
+ let last_candidate = reachable_candidates. last ( ) . unwrap ( ) ;
997
972
if let Some ( otherwise) = last_candidate. otherwise_block {
998
973
let source_info = self . source_info ( last_candidate. span ) ;
999
974
let block = self . cfg . start_new_block ( ) ;
0 commit comments