@@ -26,6 +26,7 @@ mod simplify;
2626mod test;
2727mod util;
2828
29+ use itertools:: Itertools ;
2930use std:: convert:: TryFrom ;
3031
3132impl < ' a , ' tcx > Builder < ' a , ' tcx > {
@@ -258,11 +259,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
258259 scrutinee_span,
259260 match_scope,
260261 ) ;
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) ;
266263 }
267264 }
268265
@@ -278,11 +275,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
278275 let end_block = self . cfg . start_new_block ( ) ;
279276
280277 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) ;
286279 }
287280
288281 self . source_scope = outer_source_info. scope ;
@@ -822,45 +815,34 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
822815 ) ;
823816 let ( matched_candidates, unmatched_candidates) = candidates. split_at_mut ( fully_matched) ;
824817
825- let block: BasicBlock ;
826-
827- if !matched_candidates. is_empty ( ) {
818+ let block: BasicBlock = if !matched_candidates. is_empty ( ) {
828819 let otherwise_block = self . select_matched_candidates (
829820 matched_candidates,
830821 start_block,
831822 fake_borrows,
832823 ) ;
833824
834825 if let Some ( last_otherwise_block) = otherwise_block {
835- block = last_otherwise_block
826+ last_otherwise_block
836827 } else {
837828 // Any remaining candidates are unreachable.
838829 if unmatched_candidates. is_empty ( ) {
839830 return ;
840831 }
841- block = self . cfg . start_new_block ( ) ;
842- } ;
832+ self . cfg . start_new_block ( )
833+ }
843834 } 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+ } ;
846837
847838 // If there are no candidates that still need testing, we're
848839 // done. Since all matches are exhaustive, execution should
849840 // never reach this point.
850841 if unmatched_candidates. is_empty ( ) {
851842 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 ) ,
864846 }
865847 return ;
866848 }
@@ -885,7 +867,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
885867 /// ...
886868 ///
887869 /// 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,
889871 /// * the otherwise block of the first pattern to the second pattern,
890872 /// * the otherwise block of the third pattern to the a block with an
891873 /// Unreachable terminator.
@@ -948,32 +930,25 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
948930 let first_candidate = & reachable_candidates[ 0 ] ;
949931 let first_prebinding_block = first_candidate. pre_binding_block ;
950932
933+ // `goto -> first_prebinding_block` from the `start_block` if there is one.
951934 if let Some ( start_block) = * start_block {
952935 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) ;
958937 } else {
959938 * start_block = Some ( first_prebinding_block) ;
960939 }
961940
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+ ) ;
975950 } else {
976- bug ! ( "<[_]>::windows returned incorrectly sized window " ) ;
951+ bug ! ( "candidate other than the last has no guard " ) ;
977952 }
978953 }
979954
@@ -992,8 +967,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
992967 }
993968 }
994969
995- let last_candidate = reachable_candidates. last ( ) . unwrap ( ) ;
996970
971+ let last_candidate = reachable_candidates. last ( ) . unwrap ( ) ;
997972 if let Some ( otherwise) = last_candidate. otherwise_block {
998973 let source_info = self . source_info ( last_candidate. span ) ;
999974 let block = self . cfg . start_new_block ( ) ;
0 commit comments