1
1
//! See docs in build/expr/mod.rs
2
2
3
3
use crate :: build:: expr:: category:: { Category , RvalueFunc } ;
4
- use crate :: build:: scope:: DropKind ;
5
4
use crate :: build:: { BlockAnd , BlockAndExtension , BlockFrame , Builder } ;
6
5
use crate :: thir:: * ;
7
6
use rustc_ast:: InlineAsmOptions ;
8
7
use rustc_data_structures:: fx:: FxHashMap ;
9
8
use rustc_data_structures:: stack:: ensure_sufficient_stack;
10
9
use rustc_hir as hir;
11
- use rustc_middle:: middle:: region;
12
10
use rustc_middle:: mir:: * ;
13
11
use rustc_middle:: ty:: { CanonicalUserTypeAnnotation } ;
14
12
@@ -17,19 +15,13 @@ use std::slice;
17
15
impl < ' a , ' tcx > Builder < ' a , ' tcx > {
18
16
/// Compile `expr`, storing the result into `destination`, which
19
17
/// is assumed to be uninitialized.
20
- /// If a `drop_scope` is provided, `destination` is scheduled to be dropped
21
- /// in `scope` once it has been initialized.
22
18
crate fn into_expr (
23
19
& mut self ,
24
20
destination : Place < ' tcx > ,
25
- scope : Option < region:: Scope > ,
26
21
mut block : BasicBlock ,
27
22
expr : Expr < ' tcx > ,
28
23
) -> BlockAnd < ( ) > {
29
- debug ! (
30
- "into_expr(destination={:?}, scope={:?}, block={:?}, expr={:?})" ,
31
- destination, scope, block, expr
32
- ) ;
24
+ debug ! ( "into_expr(destination={:?}, block={:?}, expr={:?})" , destination, block, expr) ;
33
25
34
26
// since we frequently have to reference `self` from within a
35
27
// closure, where `self` would be shadowed, it's easier to
@@ -40,14 +32,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
40
32
41
33
let expr_is_block_or_scope = matches ! ( expr. kind, ExprKind :: Block { .. } | ExprKind :: Scope { .. } ) ;
42
34
43
- let schedule_drop = move |this : & mut Self | {
44
- if let Some ( drop_scope) = scope {
45
- let local =
46
- destination. as_local ( ) . expect ( "cannot schedule drop of non-Local place" ) ;
47
- this. schedule_drop ( expr_span, drop_scope, local, DropKind :: Value ) ;
48
- }
49
- } ;
50
-
51
35
if !expr_is_block_or_scope {
52
36
this. block_context . push ( BlockFrame :: SubExpr ) ;
53
37
}
@@ -57,15 +41,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
57
41
let region_scope = ( region_scope, source_info) ;
58
42
ensure_sufficient_stack ( || {
59
43
this. in_scope ( region_scope, lint_level, |this| {
60
- this. into ( destination, scope , block, value)
44
+ this. into ( destination, block, value)
61
45
} )
62
46
} )
63
47
}
64
48
ExprKind :: Block { body : ast_block } => {
65
- this. ast_block ( destination, scope , block, ast_block, source_info)
49
+ this. ast_block ( destination, block, ast_block, source_info)
66
50
}
67
51
ExprKind :: Match { scrutinee, arms } => {
68
- this. match_expr ( destination, scope , expr_span, block, scrutinee, arms)
52
+ this. match_expr ( destination, expr_span, block, scrutinee, arms)
69
53
}
70
54
ExprKind :: If { cond, then, else_opt } => {
71
55
let place = unpack ! ( block = this. as_temp( block, Some ( this. local_scope( ) ) , cond, Mutability :: Mut ) ) ;
@@ -76,9 +60,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
76
60
let term = TerminatorKind :: if_ ( this. hir . tcx ( ) , operand, then_block, else_block) ;
77
61
this. cfg . terminate ( block, source_info, term) ;
78
62
79
- unpack ! ( then_block = this. into( destination, scope , then_block, then) ) ;
63
+ unpack ! ( then_block = this. into( destination, then_block, then) ) ;
80
64
else_block = if let Some ( else_opt) = else_opt {
81
- unpack ! ( this. into( destination, None , else_block, else_opt) )
65
+ unpack ! ( this. into( destination, else_block, else_opt) )
82
66
} else {
83
67
// Body of the `if` expression without an `else` clause must return `()`, thus
84
68
// we implicitly generate a `else {}` if it is not specified.
@@ -111,7 +95,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
111
95
112
96
// This is an optimization. If the expression was a call then we already have an
113
97
// unreachable block. Don't bother to terminate it and create a new one.
114
- schedule_drop ( this) ;
115
98
if is_call {
116
99
block. unit ( )
117
100
} else {
@@ -187,35 +170,26 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
187
170
// Start the loop.
188
171
this. cfg . goto ( block, source_info, loop_block) ;
189
172
190
- this. in_breakable_scope (
191
- Some ( loop_block) ,
192
- destination,
193
- scope,
194
- expr_span,
195
- move |this| {
196
- // conduct the test, if necessary
197
- let body_block = this. cfg . start_new_block ( ) ;
198
- this. cfg . terminate (
199
- loop_block,
200
- source_info,
201
- TerminatorKind :: FalseUnwind { real_target : body_block, unwind : None } ,
202
- ) ;
203
- this. diverge_from ( loop_block) ;
204
-
205
- // The “return” value of the loop body must always be an unit. We therefore
206
- // introduce a unit temporary as the destination for the loop body.
207
- let tmp = this. get_unit_temp ( ) ;
208
- // Execute the body, branching back to the test.
209
- // We don't need to provide a drop scope because `tmp`
210
- // has type `()`.
211
- let body_block_end = unpack ! ( this. into( tmp, None , body_block, body) ) ;
212
- this. cfg . goto ( body_block_end, source_info, loop_block) ;
213
- schedule_drop ( this) ;
214
-
215
- // Loops are only exited by `break` expressions.
216
- None
217
- } ,
218
- )
173
+ this. in_breakable_scope ( Some ( loop_block) , destination, expr_span, move |this| {
174
+ // conduct the test, if necessary
175
+ let body_block = this. cfg . start_new_block ( ) ;
176
+ this. cfg . terminate (
177
+ loop_block,
178
+ source_info,
179
+ TerminatorKind :: FalseUnwind { real_target : body_block, unwind : None } ,
180
+ ) ;
181
+ this. diverge_from ( loop_block) ;
182
+
183
+ // The “return” value of the loop body must always be an unit. We therefore
184
+ // introduce a unit temporary as the destination for the loop body.
185
+ let tmp = this. get_unit_temp ( ) ;
186
+ // Execute the body, branching back to the test.
187
+ let body_block_end = unpack ! ( this. into( tmp, body_block, body) ) ;
188
+ this. cfg . goto ( body_block_end, source_info, loop_block) ;
189
+
190
+ // Loops are only exited by `break` expressions.
191
+ None
192
+ } )
219
193
}
220
194
ExprKind :: Call { ty : _, fun, args, from_hir_call, fn_span } => {
221
195
let fun = unpack ! ( block = this. as_local_operand( block, fun) ) ;
@@ -250,10 +224,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
250
224
} ,
251
225
) ;
252
226
this. diverge_from ( block) ;
253
- schedule_drop ( this) ;
254
227
success. unit ( )
255
228
}
256
- ExprKind :: Use { source } => this. into ( destination, scope , block, source) ,
229
+ ExprKind :: Use { source } => this. into ( destination, block, source) ,
257
230
ExprKind :: Borrow { arg, borrow_kind } => {
258
231
// We don't do this in `as_rvalue` because we use `as_place`
259
232
// for borrow expressions, so we cannot create an `RValue` that
@@ -337,7 +310,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
337
310
destination,
338
311
Rvalue :: Aggregate ( adt, fields) ,
339
312
) ;
340
- schedule_drop ( this) ;
341
313
block. unit ( )
342
314
}
343
315
ExprKind :: InlineAsm { template, operands, options, line_spans } => {
@@ -434,7 +406,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
434
406
let place = unpack ! ( block = this. as_place( block, expr) ) ;
435
407
let rvalue = Rvalue :: Use ( this. consume_by_copy_or_move ( place) ) ;
436
408
this. cfg . push_assign ( block, source_info, destination, rvalue) ;
437
- schedule_drop ( this) ;
438
409
block. unit ( )
439
410
}
440
411
ExprKind :: Index { .. } | ExprKind :: Deref { .. } | ExprKind :: Field { .. } => {
@@ -452,7 +423,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
452
423
let place = unpack ! ( block = this. as_place( block, expr) ) ;
453
424
let rvalue = Rvalue :: Use ( this. consume_by_copy_or_move ( place) ) ;
454
425
this. cfg . push_assign ( block, source_info, destination, rvalue) ;
455
- schedule_drop ( this) ;
456
426
block. unit ( )
457
427
}
458
428
@@ -467,7 +437,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
467
437
TerminatorKind :: Yield { value, resume, resume_arg : destination, drop : None } ,
468
438
) ;
469
439
this. generator_drop_cleanup ( block) ;
470
- schedule_drop ( this) ;
471
440
resume. unit ( )
472
441
}
473
442
@@ -499,7 +468,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
499
468
500
469
let rvalue = unpack ! ( block = this. as_local_rvalue( block, expr) ) ;
501
470
this. cfg . push_assign ( block, source_info, destination, rvalue) ;
502
- schedule_drop ( this) ;
503
471
block. unit ( )
504
472
}
505
473
} ;
0 commit comments