2
2
3
3
use crate :: build:: expr:: category:: { Category , RvalueFunc } ;
4
4
use crate :: build:: { BlockAnd , BlockAndExtension , BlockFrame , Builder } ;
5
- use crate :: build:: scope:: DropKind ;
6
5
use crate :: hair:: * ;
7
- use rustc:: middle:: region;
8
6
use rustc:: mir:: * ;
9
7
use rustc:: ty;
10
8
@@ -13,18 +11,15 @@ use rustc_target::spec::abi::Abi;
13
11
impl < ' a , ' tcx > Builder < ' a , ' tcx > {
14
12
/// Compile `expr`, storing the result into `destination`, which
15
13
/// 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.
18
14
pub fn into_expr (
19
15
& mut self ,
20
16
destination : & Place < ' tcx > ,
21
- scope : Option < region:: Scope > ,
22
17
mut block : BasicBlock ,
23
18
expr : Expr < ' tcx > ,
24
19
) -> BlockAnd < ( ) > {
25
20
debug ! (
26
- "into_expr(destination={:?}, scope={:?}, block={:?}, expr={:?})" ,
27
- destination, scope , block, expr
21
+ "into_expr(destination={:?}, block={:?}, expr={:?})" ,
22
+ destination, block, expr
28
23
) ;
29
24
30
25
// since we frequently have to reference `self` from within a
@@ -40,14 +35,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
40
35
_ => false ,
41
36
} ;
42
37
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
-
51
38
if !expr_is_block_or_scope {
52
39
this. block_context . push ( BlockFrame :: SubExpr ) ;
53
40
}
@@ -60,14 +47,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
60
47
} => {
61
48
let region_scope = ( region_scope, source_info) ;
62
49
this. in_scope ( region_scope, lint_level, |this| {
63
- this. into ( destination, scope , block, value)
50
+ this. into ( destination, block, value)
64
51
} )
65
52
}
66
53
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)
68
55
}
69
56
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)
71
58
}
72
59
ExprKind :: NeverToAny { source } => {
73
60
let source = this. hir . mirror ( source) ;
@@ -80,7 +67,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
80
67
81
68
// This is an optimization. If the expression was a call then we already have an
82
69
// unreachable block. Don't bother to terminate it and create a new one.
83
- schedule_drop ( this) ;
84
70
if is_call {
85
71
block. unit ( )
86
72
} else {
@@ -178,9 +164,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
178
164
TerminatorKind :: Goto { target : loop_block } ,
179
165
) ;
180
166
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) ;
184
167
this. in_breakable_scope (
185
168
Some ( loop_block) ,
186
169
exit_block,
@@ -202,8 +185,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
202
185
// introduce a unit temporary as the destination for the loop body.
203
186
let tmp = this. get_unit_temp ( ) ;
204
187
// 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) ) ;
207
189
this. cfg . terminate (
208
190
body_block_end,
209
191
source_info,
@@ -252,14 +234,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
252
234
is_block_tail : None ,
253
235
} ) ;
254
236
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)
263
239
} else {
264
240
let args: Vec < _ > = args
265
241
. into_iter ( )
@@ -289,12 +265,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
289
265
from_hir_call,
290
266
} ,
291
267
) ;
292
- schedule_drop ( this) ;
293
268
success. unit ( )
294
269
}
295
270
}
296
271
ExprKind :: Use { source } => {
297
- this. into ( destination, scope , block, source)
272
+ this. into ( destination, block, source)
298
273
}
299
274
300
275
// These cases don't actually need a destination
@@ -321,7 +296,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
321
296
let rvalue = Rvalue :: Use ( this. consume_by_copy_or_move ( place) ) ;
322
297
this. cfg
323
298
. push_assign ( block, source_info, destination, rvalue) ;
324
- schedule_drop ( this) ;
325
299
block. unit ( )
326
300
}
327
301
ExprKind :: Index { .. } | ExprKind :: Deref { .. } | ExprKind :: Field { .. } => {
@@ -341,7 +315,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
341
315
let rvalue = Rvalue :: Use ( this. consume_by_copy_or_move ( place) ) ;
342
316
this. cfg
343
317
. push_assign ( block, source_info, destination, rvalue) ;
344
- schedule_drop ( this) ;
345
318
block. unit ( )
346
319
}
347
320
@@ -373,7 +346,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
373
346
374
347
let rvalue = unpack ! ( block = this. as_local_rvalue( block, expr) ) ;
375
348
this. cfg . push_assign ( block, source_info, destination, rvalue) ;
376
- schedule_drop ( this) ;
377
349
block. unit ( )
378
350
}
379
351
} ;
0 commit comments