@@ -547,7 +547,7 @@ fn transform_async_context<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
547
547
548
548
let get_context_def_id = tcx. require_lang_item ( LangItem :: GetContext , None ) ;
549
549
550
- for bb in START_BLOCK .. body. basic_blocks . next_index ( ) {
550
+ for bb in body. basic_blocks . indices ( ) {
551
551
let bb_data = & body[ bb] ;
552
552
if bb_data. is_cleanup {
553
553
continue ;
@@ -556,11 +556,11 @@ fn transform_async_context<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
556
556
match & bb_data. terminator ( ) . kind {
557
557
TerminatorKind :: Call { func, .. } => {
558
558
let func_ty = func. ty ( body, tcx) ;
559
- if let ty:: FnDef ( def_id, _) = * func_ty. kind ( ) {
560
- if def_id == get_context_def_id {
561
- let local = eliminate_get_context_call ( & mut body [ bb ] ) ;
562
- replace_resume_ty_local ( tcx , body, local , context_mut_ref ) ;
563
- }
559
+ if let ty:: FnDef ( def_id, _) = * func_ty. kind ( )
560
+ && def_id == get_context_def_id
561
+ {
562
+ let local = eliminate_get_context_call ( & mut body[ bb ] ) ;
563
+ replace_resume_ty_local ( tcx , body , local , context_mut_ref ) ;
564
564
}
565
565
}
566
566
TerminatorKind :: Yield { resume_arg, .. } => {
@@ -1057,7 +1057,7 @@ fn insert_switch<'tcx>(
1057
1057
let blocks = body. basic_blocks_mut ( ) . iter_mut ( ) ;
1058
1058
1059
1059
for target in blocks. flat_map ( |b| b. terminator_mut ( ) . successors_mut ( ) ) {
1060
- * target = BasicBlock :: new ( target . index ( ) + 1 ) ;
1060
+ * target += 1 ;
1061
1061
}
1062
1062
}
1063
1063
@@ -1209,14 +1209,8 @@ fn can_return<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, typing_env: ty::Typing
1209
1209
}
1210
1210
1211
1211
// If there's a return terminator the function may return.
1212
- for block in body. basic_blocks . iter ( ) {
1213
- if let TerminatorKind :: Return = block. terminator ( ) . kind {
1214
- return true ;
1215
- }
1216
- }
1217
-
1212
+ body. basic_blocks . iter ( ) . any ( |block| matches ! ( block. terminator( ) . kind, TerminatorKind :: Return ) )
1218
1213
// Otherwise the function can't return.
1219
- false
1220
1214
}
1221
1215
1222
1216
fn can_unwind < ' tcx > ( tcx : TyCtxt < ' tcx > , body : & Body < ' tcx > ) -> bool {
@@ -1293,12 +1287,12 @@ fn create_coroutine_resume_function<'tcx>(
1293
1287
kind : TerminatorKind :: Goto { target : poison_block } ,
1294
1288
} ;
1295
1289
}
1296
- } else if !block. is_cleanup {
1290
+ } else if !block. is_cleanup
1297
1291
// Any terminators that *can* unwind but don't have an unwind target set are also
1298
1292
// pointed at our poisoning block (unless they're part of the cleanup path).
1299
- if let Some ( unwind @ UnwindAction :: Continue ) = block. terminator_mut ( ) . unwind_mut ( ) {
1300
- * unwind = UnwindAction :: Cleanup ( poison_block ) ;
1301
- }
1293
+ && let Some ( unwind @ UnwindAction :: Continue ) = block. terminator_mut ( ) . unwind_mut ( )
1294
+ {
1295
+ * unwind = UnwindAction :: Cleanup ( poison_block ) ;
1302
1296
}
1303
1297
}
1304
1298
}
@@ -1340,12 +1334,14 @@ fn create_coroutine_resume_function<'tcx>(
1340
1334
make_coroutine_state_argument_indirect ( tcx, body) ;
1341
1335
1342
1336
match transform. coroutine_kind {
1337
+ CoroutineKind :: Coroutine ( _)
1338
+ | CoroutineKind :: Desugared ( CoroutineDesugaring :: Async | CoroutineDesugaring :: AsyncGen , _) =>
1339
+ {
1340
+ make_coroutine_state_argument_pinned ( tcx, body) ;
1341
+ }
1343
1342
// Iterator::next doesn't accept a pinned argument,
1344
1343
// unlike for all other coroutine kinds.
1345
1344
CoroutineKind :: Desugared ( CoroutineDesugaring :: Gen , _) => { }
1346
- _ => {
1347
- make_coroutine_state_argument_pinned ( tcx, body) ;
1348
- }
1349
1345
}
1350
1346
1351
1347
// Make sure we remove dead blocks to remove
@@ -1408,8 +1404,7 @@ fn create_cases<'tcx>(
1408
1404
let mut statements = Vec :: new ( ) ;
1409
1405
1410
1406
// Create StorageLive instructions for locals with live storage
1411
- for i in 0 ..( body. local_decls . len ( ) ) {
1412
- let l = Local :: new ( i) ;
1407
+ for l in body. local_decls . indices ( ) {
1413
1408
let needs_storage_live = point. storage_liveness . contains ( l)
1414
1409
&& !transform. remap . contains ( l)
1415
1410
&& !transform. always_live_locals . contains ( l) ;
@@ -1535,15 +1530,10 @@ impl<'tcx> crate::MirPass<'tcx> for StateTransform {
1535
1530
let coroutine_kind = body. coroutine_kind ( ) . unwrap ( ) ;
1536
1531
1537
1532
// Get the discriminant type and args which typeck computed
1538
- let ( discr_ty, movable) = match * coroutine_ty. kind ( ) {
1539
- ty:: Coroutine ( _, args) => {
1540
- let args = args. as_coroutine ( ) ;
1541
- ( args. discr_ty ( tcx) , coroutine_kind. movability ( ) == hir:: Movability :: Movable )
1542
- }
1543
- _ => {
1544
- tcx. dcx ( ) . span_bug ( body. span , format ! ( "unexpected coroutine type {coroutine_ty}" ) ) ;
1545
- }
1533
+ let ty:: Coroutine ( _, args) = coroutine_ty. kind ( ) else {
1534
+ tcx. dcx ( ) . span_bug ( body. span , format ! ( "unexpected coroutine type {coroutine_ty}" ) ) ;
1546
1535
} ;
1536
+ let discr_ty = args. as_coroutine ( ) . discr_ty ( tcx) ;
1547
1537
1548
1538
let new_ret_ty = match coroutine_kind {
1549
1539
CoroutineKind :: Desugared ( CoroutineDesugaring :: Async , _) => {
@@ -1610,6 +1600,7 @@ impl<'tcx> crate::MirPass<'tcx> for StateTransform {
1610
1600
1611
1601
let always_live_locals = always_storage_live_locals ( body) ;
1612
1602
1603
+ let movable = coroutine_kind. movability ( ) == hir:: Movability :: Movable ;
1613
1604
let liveness_info =
1614
1605
locals_live_across_suspend_points ( tcx, body, & always_live_locals, movable) ;
1615
1606
0 commit comments