@@ -547,7 +547,7 @@ fn transform_async_context<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
547547
548548 let get_context_def_id = tcx. require_lang_item ( LangItem :: GetContext , None ) ;
549549
550- for bb in START_BLOCK .. body. basic_blocks . next_index ( ) {
550+ for bb in body. basic_blocks . indices ( ) {
551551 let bb_data = & body[ bb] ;
552552 if bb_data. is_cleanup {
553553 continue ;
@@ -556,11 +556,11 @@ fn transform_async_context<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
556556 match & bb_data. terminator ( ) . kind {
557557 TerminatorKind :: Call { func, .. } => {
558558 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 ) ;
564564 }
565565 }
566566 TerminatorKind :: Yield { resume_arg, .. } => {
@@ -1057,7 +1057,7 @@ fn insert_switch<'tcx>(
10571057 let blocks = body. basic_blocks_mut ( ) . iter_mut ( ) ;
10581058
10591059 for target in blocks. flat_map ( |b| b. terminator_mut ( ) . successors_mut ( ) ) {
1060- * target = BasicBlock :: new ( target . index ( ) + 1 ) ;
1060+ * target += 1 ;
10611061 }
10621062}
10631063
@@ -1209,14 +1209,8 @@ fn can_return<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, typing_env: ty::Typing
12091209 }
12101210
12111211 // 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 ) )
12181213 // Otherwise the function can't return.
1219- false
12201214}
12211215
12221216fn can_unwind < ' tcx > ( tcx : TyCtxt < ' tcx > , body : & Body < ' tcx > ) -> bool {
@@ -1293,12 +1287,12 @@ fn create_coroutine_resume_function<'tcx>(
12931287 kind : TerminatorKind :: Goto { target : poison_block } ,
12941288 } ;
12951289 }
1296- } else if !block. is_cleanup {
1290+ } else if !block. is_cleanup
12971291 // Any terminators that *can* unwind but don't have an unwind target set are also
12981292 // 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 ) ;
13021296 }
13031297 }
13041298 }
@@ -1340,12 +1334,14 @@ fn create_coroutine_resume_function<'tcx>(
13401334 make_coroutine_state_argument_indirect ( tcx, body) ;
13411335
13421336 match transform. coroutine_kind {
1337+ CoroutineKind :: Coroutine ( _)
1338+ | CoroutineKind :: Desugared ( CoroutineDesugaring :: Async | CoroutineDesugaring :: AsyncGen , _) =>
1339+ {
1340+ make_coroutine_state_argument_pinned ( tcx, body) ;
1341+ }
13431342 // Iterator::next doesn't accept a pinned argument,
13441343 // unlike for all other coroutine kinds.
13451344 CoroutineKind :: Desugared ( CoroutineDesugaring :: Gen , _) => { }
1346- _ => {
1347- make_coroutine_state_argument_pinned ( tcx, body) ;
1348- }
13491345 }
13501346
13511347 // Make sure we remove dead blocks to remove
@@ -1408,8 +1404,7 @@ fn create_cases<'tcx>(
14081404 let mut statements = Vec :: new ( ) ;
14091405
14101406 // 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 ( ) {
14131408 let needs_storage_live = point. storage_liveness . contains ( l)
14141409 && !transform. remap . contains ( l)
14151410 && !transform. always_live_locals . contains ( l) ;
@@ -1535,15 +1530,10 @@ impl<'tcx> crate::MirPass<'tcx> for StateTransform {
15351530 let coroutine_kind = body. coroutine_kind ( ) . unwrap ( ) ;
15361531
15371532 // 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}" ) ) ;
15461535 } ;
1536+ let discr_ty = args. as_coroutine ( ) . discr_ty ( tcx) ;
15471537
15481538 let new_ret_ty = match coroutine_kind {
15491539 CoroutineKind :: Desugared ( CoroutineDesugaring :: Async , _) => {
@@ -1610,6 +1600,7 @@ impl<'tcx> crate::MirPass<'tcx> for StateTransform {
16101600
16111601 let always_live_locals = always_storage_live_locals ( body) ;
16121602
1603+ let movable = coroutine_kind. movability ( ) == hir:: Movability :: Movable ;
16131604 let liveness_info =
16141605 locals_live_across_suspend_points ( tcx, body, & always_live_locals, movable) ;
16151606
0 commit comments