2222//! sort of test: for example, testing which variant an enum is, or
2323//! testing a value against a constant.
2424
25- use build:: Builder ;
25+ use build:: { BlockAnd , Builder } ;
2626use build:: matches:: { Binding , MatchPair , Candidate } ;
2727use hair:: * ;
2828use repr:: * ;
@@ -31,20 +31,25 @@ use std::mem;
3131
3232impl < H : Hair > Builder < H > {
3333 pub fn simplify_candidate ( & mut self ,
34+ mut block : BasicBlock ,
3435 candidate : & mut Candidate < H > )
36+ -> BlockAnd < ( ) >
3537 {
3638 // repeatedly simplify match pairs until fixed point is reached
3739 loop {
3840 let match_pairs = mem:: replace ( & mut candidate. match_pairs , vec ! [ ] ) ;
3941 let mut progress = match_pairs. len ( ) ; // count how many were simplified
4042 for match_pair in match_pairs {
41- if let Err ( match_pair) = self . simplify_match_pair ( match_pair, candidate) {
42- candidate. match_pairs . push ( match_pair) ;
43- progress -= 1 ; // this one was not simplified
43+ match self . simplify_match_pair ( block, match_pair, candidate) {
44+ Ok ( b) => { block = b; }
45+ Err ( match_pair) => {
46+ candidate. match_pairs . push ( match_pair) ;
47+ progress -= 1 ; // this one was not simplified
48+ }
4449 }
4550 }
4651 if progress == 0 {
47- return ; // if we were not able to simplify any, done.
52+ return block . unit ( ) ; // if we were not able to simplify any, done.
4853 }
4954 }
5055 }
@@ -54,14 +59,15 @@ impl<H:Hair> Builder<H> {
5459 /// have been pushed into the candidate. On failure (if false is
5560 /// returned), no changes are made to candidate.
5661 fn simplify_match_pair ( & mut self ,
62+ mut block : BasicBlock ,
5763 match_pair : MatchPair < H > ,
5864 candidate : & mut Candidate < H > )
59- -> Result < ( ) , MatchPair < H > > // returns Err() if cannot simplify
65+ -> Result < BasicBlock , MatchPair < H > > // returns Err() if cannot simplify
6066 {
6167 match match_pair. pattern . kind {
6268 PatternKind :: Wild ( ..) => {
6369 // nothing left to do
64- Ok ( ( ) )
70+ Ok ( block )
6571 }
6672
6773 PatternKind :: Binding { name, mutability, mode, var, ty, subpattern } => {
@@ -81,24 +87,22 @@ impl<H:Hair> Builder<H> {
8187 candidate. match_pairs . push ( MatchPair :: new ( match_pair. lvalue , subpattern) ) ;
8288 }
8389
84- Ok ( ( ) )
90+ Ok ( block )
8591 }
8692
8793 PatternKind :: Constant { .. } => {
8894 // FIXME normalize patterns when possible
8995 Err ( match_pair)
9096 }
9197
92- PatternKind :: Array { prefix, slice : None , suffix } => {
93- self . append_prefix_suffix_pairs (
94- & mut candidate. match_pairs , match_pair. lvalue . clone ( ) , prefix, suffix) ;
95- Ok ( ( ) )
96- }
97-
98- PatternKind :: Array { prefix : _, slice : Some ( _) , suffix : _ } => {
99- self . hir . span_bug (
100- match_pair. pattern . span ,
101- & format ! ( "slice patterns not implemented in MIR" ) ) ;
98+ PatternKind :: Array { prefix, slice, suffix } => {
99+ unpack ! ( block = self . prefix_suffix_slice( & mut candidate. match_pairs,
100+ block,
101+ match_pair. lvalue. clone( ) ,
102+ prefix,
103+ slice,
104+ suffix) ) ;
105+ Ok ( block)
102106 }
103107
104108 PatternKind :: Slice { .. } |
@@ -112,14 +116,14 @@ impl<H:Hair> Builder<H> {
112116 // tuple struct, match subpats (if any)
113117 candidate. match_pairs . extend (
114118 self . field_match_pairs ( match_pair. lvalue , subpatterns) ) ;
115- Ok ( ( ) )
119+ Ok ( block )
116120 }
117121
118122 PatternKind :: Deref { subpattern } => {
119123 let lvalue = match_pair. lvalue . deref ( ) ;
120124 let subpattern = self . hir . mirror ( subpattern) ;
121125 candidate. match_pairs . push ( MatchPair :: new ( lvalue, subpattern) ) ;
122- Ok ( ( ) )
126+ Ok ( block )
123127 }
124128 }
125129 }
0 commit comments