@@ -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 > {
@@ -822,27 +823,25 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
822
823
) ;
823
824
let ( matched_candidates, unmatched_candidates) = candidates. split_at_mut ( fully_matched) ;
824
825
825
- let block: BasicBlock ;
826
-
827
- if !matched_candidates. is_empty ( ) {
826
+ let block: BasicBlock = if !matched_candidates. is_empty ( ) {
828
827
let otherwise_block = self . select_matched_candidates (
829
828
matched_candidates,
830
829
start_block,
831
830
fake_borrows,
832
831
) ;
833
832
834
833
if let Some ( last_otherwise_block) = otherwise_block {
835
- block = last_otherwise_block
834
+ last_otherwise_block
836
835
} else {
837
836
// Any remaining candidates are unreachable.
838
837
if unmatched_candidates. is_empty ( ) {
839
838
return ;
840
839
}
841
- block = self . cfg . start_new_block ( ) ;
842
- } ;
840
+ self . cfg . start_new_block ( )
841
+ }
843
842
} 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
+ } ;
846
845
847
846
// If there are no candidates that still need testing, we're
848
847
// done. Since all matches are exhaustive, execution should
@@ -885,7 +884,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
885
884
/// ...
886
885
///
887
886
/// 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,
889
888
/// * the otherwise block of the first pattern to the second pattern,
890
889
/// * the otherwise block of the third pattern to the a block with an
891
890
/// Unreachable terminator.
@@ -948,6 +947,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
948
947
let first_candidate = & reachable_candidates[ 0 ] ;
949
948
let first_prebinding_block = first_candidate. pre_binding_block ;
950
949
950
+ // `goto -> first_prebinding_block` from the `start_block` if there is one.
951
951
if let Some ( start_block) = * start_block {
952
952
let source_info = self . source_info ( first_candidate. span ) ;
953
953
self . cfg . terminate (
@@ -959,21 +959,17 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
959
959
* start_block = Some ( first_prebinding_block) ;
960
960
}
961
961
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
+ ) ;
975
971
} else {
976
- bug ! ( "<[_]>::windows returned incorrectly sized window " ) ;
972
+ bug ! ( "candidate other than the last has no guard " ) ;
977
973
}
978
974
}
979
975
0 commit comments