50
50
//! For generators with state 1 (returned) and state 2 (poisoned) it does nothing.
51
51
//! Otherwise it drops all the values in scope at the last suspension point.
52
52
53
+ use crate :: abort_unwinding_calls;
53
54
use crate :: deref_separator:: deref_finder;
54
55
use crate :: errors;
56
+ use crate :: pass_manager as pm;
55
57
use crate :: simplify;
56
58
use crate :: MirPass ;
57
59
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
@@ -64,6 +66,7 @@ use rustc_index::{Idx, IndexVec};
64
66
use rustc_middle:: mir:: dump_mir;
65
67
use rustc_middle:: mir:: visit:: { MutVisitor , PlaceContext , Visitor } ;
66
68
use rustc_middle:: mir:: * ;
69
+ use rustc_middle:: ty:: InstanceDef ;
67
70
use rustc_middle:: ty:: { self , AdtDef , Ty , TyCtxt } ;
68
71
use rustc_middle:: ty:: { GeneratorArgs , GenericArgsRef } ;
69
72
use rustc_mir_dataflow:: impls:: {
@@ -1147,6 +1150,17 @@ fn create_generator_drop_shim<'tcx>(
1147
1150
// unrelated code from the resume part of the function
1148
1151
simplify:: remove_dead_blocks ( tcx, & mut body) ;
1149
1152
1153
+ // Update the body's def to become the drop glue.
1154
+ let drop_in_place = tcx. require_lang_item ( LangItem :: DropInPlace , None ) ;
1155
+ body. source . instance = InstanceDef :: DropGlue ( drop_in_place, Some ( gen_ty) ) ;
1156
+
1157
+ pm:: run_passes_no_validate (
1158
+ tcx,
1159
+ & mut body,
1160
+ & [ & abort_unwinding_calls:: AbortUnwindingCalls ] ,
1161
+ None ,
1162
+ ) ;
1163
+
1150
1164
dump_mir ( tcx, false , "generator_drop" , & 0 , & body, |_, _| Ok ( ( ) ) ) ;
1151
1165
1152
1166
body
@@ -1317,6 +1331,8 @@ fn create_generator_resume_function<'tcx>(
1317
1331
// unrelated code from the drop part of the function
1318
1332
simplify:: remove_dead_blocks ( tcx, body) ;
1319
1333
1334
+ pm:: run_passes_no_validate ( tcx, body, & [ & abort_unwinding_calls:: AbortUnwindingCalls ] , None ) ;
1335
+
1320
1336
dump_mir ( tcx, false , "generator_resume" , & 0 , body, |_, _| Ok ( ( ) ) ) ;
1321
1337
}
1322
1338
0 commit comments