22
33use crate :: build:: expr:: category:: { Category , RvalueFunc } ;
44use crate :: build:: { BlockAnd , BlockAndExtension , BlockFrame , Builder } ;
5- use crate :: build:: scope:: DropKind ;
65use crate :: hair:: * ;
7- use rustc:: middle:: region;
86use rustc:: mir:: * ;
97use rustc:: ty;
108
@@ -13,18 +11,15 @@ use rustc_target::spec::abi::Abi;
1311impl < ' a , ' tcx > Builder < ' a , ' tcx > {
1412 /// Compile `expr`, storing the result into `destination`, which
1513 /// is assumed to be uninitialized.
16- /// If a `drop_scope` is provided, `destination` is scheduled to be dropped
17- /// in `scope` once it has been initialized.
1814 pub fn into_expr (
1915 & mut self ,
2016 destination : & Place < ' tcx > ,
21- scope : Option < region:: Scope > ,
2217 mut block : BasicBlock ,
2318 expr : Expr < ' tcx > ,
2419 ) -> BlockAnd < ( ) > {
2520 debug ! (
26- "into_expr(destination={:?}, scope={:?}, block={:?}, expr={:?})" ,
27- destination, scope , block, expr
21+ "into_expr(destination={:?}, block={:?}, expr={:?})" ,
22+ destination, block, expr
2823 ) ;
2924
3025 // since we frequently have to reference `self` from within a
@@ -40,14 +35,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
4035 _ => false ,
4136 } ;
4237
43- let schedule_drop = move |this : & mut Self | {
44- if let Some ( drop_scope) = scope {
45- let local = destination. as_local ( )
46- . expect ( "cannot schedule drop of non-Local place" ) ;
47- this. schedule_drop ( expr_span, drop_scope, local, DropKind :: Value ) ;
48- }
49- } ;
50-
5138 if !expr_is_block_or_scope {
5239 this. block_context . push ( BlockFrame :: SubExpr ) ;
5340 }
@@ -60,14 +47,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
6047 } => {
6148 let region_scope = ( region_scope, source_info) ;
6249 this. in_scope ( region_scope, lint_level, |this| {
63- this. into ( destination, scope , block, value)
50+ this. into ( destination, block, value)
6451 } )
6552 }
6653 ExprKind :: Block { body : ast_block } => {
67- this. ast_block ( destination, scope , block, ast_block, source_info)
54+ this. ast_block ( destination, block, ast_block, source_info)
6855 }
6956 ExprKind :: Match { scrutinee, arms } => {
70- this. match_expr ( destination, scope , expr_span, block, scrutinee, arms)
57+ this. match_expr ( destination, expr_span, block, scrutinee, arms)
7158 }
7259 ExprKind :: NeverToAny { source } => {
7360 let source = this. hir . mirror ( source) ;
@@ -80,7 +67,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
8067
8168 // This is an optimization. If the expression was a call then we already have an
8269 // unreachable block. Don't bother to terminate it and create a new one.
83- schedule_drop ( this) ;
8470 if is_call {
8571 block. unit ( )
8672 } else {
@@ -178,9 +164,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
178164 TerminatorKind :: Goto { target : loop_block } ,
179165 ) ;
180166
181- // Loops assign to their destination on each `break`. Since we
182- // can't easily unschedule drops, we schedule the drop now.
183- schedule_drop ( this) ;
184167 this. in_breakable_scope (
185168 Some ( loop_block) ,
186169 exit_block,
@@ -202,8 +185,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
202185 // introduce a unit temporary as the destination for the loop body.
203186 let tmp = this. get_unit_temp ( ) ;
204187 // Execute the body, branching back to the test.
205- // No scope is provided, since we've scheduled the drop above.
206- let body_block_end = unpack ! ( this. into( & tmp, None , body_block, body) ) ;
188+ let body_block_end = unpack ! ( this. into( & tmp, body_block, body) ) ;
207189 this. cfg . terminate (
208190 body_block_end,
209191 source_info,
@@ -252,14 +234,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
252234 is_block_tail : None ,
253235 } ) ;
254236 let ptr_temp = Place :: from ( ptr_temp) ;
255- // No need for a scope, ptr_temp doesn't need drop
256- let block = unpack ! ( this. into( & ptr_temp, None , block, ptr) ) ;
257- // Maybe we should provide a scope here so that
258- // `move_val_init` wouldn't leak on panic even with an
259- // arbitrary `val` expression, but `schedule_drop`,
260- // borrowck and drop elaboration all prevent us from
261- // dropping `ptr_temp.deref()`.
262- this. into ( & ptr_temp. deref ( ) , None , block, val)
237+ let block = unpack ! ( this. into( & ptr_temp, block, ptr) ) ;
238+ this. into ( & ptr_temp. deref ( ) , block, val)
263239 } else {
264240 let args: Vec < _ > = args
265241 . into_iter ( )
@@ -289,12 +265,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
289265 from_hir_call,
290266 } ,
291267 ) ;
292- schedule_drop ( this) ;
293268 success. unit ( )
294269 }
295270 }
296271 ExprKind :: Use { source } => {
297- this. into ( destination, scope , block, source)
272+ this. into ( destination, block, source)
298273 }
299274
300275 // These cases don't actually need a destination
@@ -321,7 +296,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
321296 let rvalue = Rvalue :: Use ( this. consume_by_copy_or_move ( place) ) ;
322297 this. cfg
323298 . push_assign ( block, source_info, destination, rvalue) ;
324- schedule_drop ( this) ;
325299 block. unit ( )
326300 }
327301 ExprKind :: Index { .. } | ExprKind :: Deref { .. } | ExprKind :: Field { .. } => {
@@ -341,7 +315,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
341315 let rvalue = Rvalue :: Use ( this. consume_by_copy_or_move ( place) ) ;
342316 this. cfg
343317 . push_assign ( block, source_info, destination, rvalue) ;
344- schedule_drop ( this) ;
345318 block. unit ( )
346319 }
347320
@@ -373,7 +346,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
373346
374347 let rvalue = unpack ! ( block = this. as_local_rvalue( block, expr) ) ;
375348 this. cfg . push_assign ( block, source_info, destination, rvalue) ;
376- schedule_drop ( this) ;
377349 block. unit ( )
378350 }
379351 } ;
0 commit comments