@@ -122,6 +122,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
122
122
PatternKind :: Binding { mode : BindingMode :: ByValue ,
123
123
var,
124
124
subpattern : None , .. } => {
125
+ self . storage_live_for_bindings ( block, & irrefutable_pat) ;
125
126
let lvalue = Lvalue :: Var ( self . var_indices [ & var] ) ;
126
127
return self . into ( & lvalue, block, initializer) ;
127
128
}
@@ -206,6 +207,43 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
206
207
}
207
208
var_scope
208
209
}
210
+
211
+ /// Emit `StorageLive` for every binding in the pattern.
212
+ pub fn storage_live_for_bindings ( & mut self ,
213
+ block : BasicBlock ,
214
+ pattern : & Pattern < ' tcx > ) {
215
+ match * pattern. kind {
216
+ PatternKind :: Binding { var, ref subpattern, .. } => {
217
+ let lvalue = Lvalue :: Var ( self . var_indices [ & var] ) ;
218
+ let source_info = self . source_info ( pattern. span ) ;
219
+ self . cfg . push ( block, Statement {
220
+ source_info : source_info,
221
+ kind : StatementKind :: StorageLive ( lvalue)
222
+ } ) ;
223
+
224
+ if let Some ( subpattern) = subpattern. as_ref ( ) {
225
+ self . storage_live_for_bindings ( block, subpattern) ;
226
+ }
227
+ }
228
+ PatternKind :: Array { ref prefix, ref slice, ref suffix } |
229
+ PatternKind :: Slice { ref prefix, ref slice, ref suffix } => {
230
+ for subpattern in prefix. iter ( ) . chain ( slice) . chain ( suffix) {
231
+ self . storage_live_for_bindings ( block, subpattern) ;
232
+ }
233
+ }
234
+ PatternKind :: Constant { .. } | PatternKind :: Range { .. } | PatternKind :: Wild => {
235
+ }
236
+ PatternKind :: Deref { ref subpattern } => {
237
+ self . storage_live_for_bindings ( block, subpattern) ;
238
+ }
239
+ PatternKind :: Leaf { ref subpatterns } |
240
+ PatternKind :: Variant { ref subpatterns, .. } => {
241
+ for subpattern in subpatterns {
242
+ self . storage_live_for_bindings ( block, & subpattern. pattern ) ;
243
+ }
244
+ }
245
+ }
246
+ }
209
247
}
210
248
211
249
/// List of blocks for each arm (and potentially other metadata in the
@@ -665,6 +703,10 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
665
703
} ;
666
704
667
705
let source_info = self . source_info ( binding. span ) ;
706
+ self . cfg . push ( block, Statement {
707
+ source_info : source_info,
708
+ kind : StatementKind :: StorageLive ( Lvalue :: Var ( var_index) )
709
+ } ) ;
668
710
self . cfg . push_assign ( block, source_info,
669
711
& Lvalue :: Var ( var_index) , rvalue) ;
670
712
}
0 commit comments