22
22
//! sort of test: for example, testing which variant an enum is, or
23
23
//! testing a value against a constant.
24
24
25
- use build:: Builder ;
25
+ use build:: { BlockAnd , Builder } ;
26
26
use build:: matches:: { Binding , MatchPair , Candidate } ;
27
27
use hair:: * ;
28
28
use repr:: * ;
@@ -31,20 +31,25 @@ use std::mem;
31
31
32
32
impl < H : Hair > Builder < H > {
33
33
pub fn simplify_candidate ( & mut self ,
34
+ mut block : BasicBlock ,
34
35
candidate : & mut Candidate < H > )
36
+ -> BlockAnd < ( ) >
35
37
{
36
38
// repeatedly simplify match pairs until fixed point is reached
37
39
loop {
38
40
let match_pairs = mem:: replace ( & mut candidate. match_pairs , vec ! [ ] ) ;
39
41
let mut progress = match_pairs. len ( ) ; // count how many were simplified
40
42
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
+ }
44
49
}
45
50
}
46
51
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.
48
53
}
49
54
}
50
55
}
@@ -54,14 +59,15 @@ impl<H:Hair> Builder<H> {
54
59
/// have been pushed into the candidate. On failure (if false is
55
60
/// returned), no changes are made to candidate.
56
61
fn simplify_match_pair ( & mut self ,
62
+ mut block : BasicBlock ,
57
63
match_pair : MatchPair < H > ,
58
64
candidate : & mut Candidate < H > )
59
- -> Result < ( ) , MatchPair < H > > // returns Err() if cannot simplify
65
+ -> Result < BasicBlock , MatchPair < H > > // returns Err() if cannot simplify
60
66
{
61
67
match match_pair. pattern . kind {
62
68
PatternKind :: Wild ( ..) => {
63
69
// nothing left to do
64
- Ok ( ( ) )
70
+ Ok ( block )
65
71
}
66
72
67
73
PatternKind :: Binding { name, mutability, mode, var, ty, subpattern } => {
@@ -81,24 +87,22 @@ impl<H:Hair> Builder<H> {
81
87
candidate. match_pairs . push ( MatchPair :: new ( match_pair. lvalue , subpattern) ) ;
82
88
}
83
89
84
- Ok ( ( ) )
90
+ Ok ( block )
85
91
}
86
92
87
93
PatternKind :: Constant { .. } => {
88
94
// FIXME normalize patterns when possible
89
95
Err ( match_pair)
90
96
}
91
97
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)
102
106
}
103
107
104
108
PatternKind :: Slice { .. } |
@@ -112,14 +116,14 @@ impl<H:Hair> Builder<H> {
112
116
// tuple struct, match subpats (if any)
113
117
candidate. match_pairs . extend (
114
118
self . field_match_pairs ( match_pair. lvalue , subpatterns) ) ;
115
- Ok ( ( ) )
119
+ Ok ( block )
116
120
}
117
121
118
122
PatternKind :: Deref { subpattern } => {
119
123
let lvalue = match_pair. lvalue . deref ( ) ;
120
124
let subpattern = self . hir . mirror ( subpattern) ;
121
125
candidate. match_pairs . push ( MatchPair :: new ( lvalue, subpattern) ) ;
122
- Ok ( ( ) )
126
+ Ok ( block )
123
127
}
124
128
}
125
129
}
0 commit comments