@@ -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 > {
@@ -822,27 +823,25 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
822823 ) ;
823824 let ( matched_candidates, unmatched_candidates) = candidates. split_at_mut ( fully_matched) ;
824825
825- let block: BasicBlock ;
826-
827- if !matched_candidates. is_empty ( ) {
826+ let block: BasicBlock = if !matched_candidates. is_empty ( ) {
828827 let otherwise_block = self . select_matched_candidates (
829828 matched_candidates,
830829 start_block,
831830 fake_borrows,
832831 ) ;
833832
834833 if let Some ( last_otherwise_block) = otherwise_block {
835- block = last_otherwise_block
834+ last_otherwise_block
836835 } else {
837836 // Any remaining candidates are unreachable.
838837 if unmatched_candidates. is_empty ( ) {
839838 return ;
840839 }
841- block = self . cfg . start_new_block ( ) ;
842- } ;
840+ self . cfg . start_new_block ( )
841+ }
843842 } else {
844- block = * start_block. get_or_insert_with ( || self . cfg . start_new_block ( ) ) ;
845- }
843+ * start_block. get_or_insert_with ( || self . cfg . start_new_block ( ) )
844+ } ;
846845
847846 // If there are no candidates that still need testing, we're
848847 // done. Since all matches are exhaustive, execution should
@@ -885,7 +884,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
885884 /// ...
886885 ///
887886 /// We generate real edges from:
888- /// * `block ` to the prebinding_block of the first pattern,
887+ /// * `start_block ` to the ` prebinding_block` of the first pattern,
889888 /// * the otherwise block of the first pattern to the second pattern,
890889 /// * the otherwise block of the third pattern to the a block with an
891890 /// Unreachable terminator.
@@ -948,6 +947,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
948947 let first_candidate = & reachable_candidates[ 0 ] ;
949948 let first_prebinding_block = first_candidate. pre_binding_block ;
950949
950+ // `goto -> first_prebinding_block` from the `start_block` if there is one.
951951 if let Some ( start_block) = * start_block {
952952 let source_info = self . source_info ( first_candidate. span ) ;
953953 self . cfg . terminate (
@@ -959,21 +959,17 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
959959 * start_block = Some ( first_prebinding_block) ;
960960 }
961961
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- }
962+ for ( first_candidate, second_candidate) in reachable_candidates. iter ( ) . tuple_windows ( ) {
963+ let source_info = self . source_info ( first_candidate. span ) ;
964+ if let Some ( otherwise_block) = first_candidate. otherwise_block {
965+ self . false_edges (
966+ otherwise_block,
967+ second_candidate. pre_binding_block ,
968+ first_candidate. next_candidate_pre_binding_block ,
969+ source_info,
970+ ) ;
975971 } else {
976- bug ! ( "<[_]>::windows returned incorrectly sized window " ) ;
972+ bug ! ( "candidate other than the last has no guard " ) ;
977973 }
978974 }
979975
0 commit comments