@@ -156,15 +156,6 @@ fn replace_base<'tcx>(place: &mut Place<'tcx>, new_base: Place<'tcx>, tcx: TyCtx
156
156
157
157
const SELF_ARG : Local = Local :: from_u32 ( 1 ) ;
158
158
159
- /// Coroutine has not been resumed yet.
160
- const UNRESUMED : usize = CoroutineArgs :: UNRESUMED ;
161
- /// Coroutine has returned / is completed.
162
- const RETURNED : usize = CoroutineArgs :: RETURNED ;
163
- /// Coroutine has panicked and is poisoned.
164
- const POISONED : usize = CoroutineArgs :: POISONED ;
165
- /// Number of reserved variants of coroutine state.
166
- const RESERVED_VARIANTS : usize = CoroutineArgs :: RESERVED_VARIANTS ;
167
-
168
159
/// A `yield` point in the coroutine.
169
160
struct SuspensionPoint < ' tcx > {
170
161
/// State discriminant used when suspending or resuming at this point.
@@ -475,7 +466,7 @@ impl<'tcx> MutVisitor<'tcx> for TransformVisitor<'tcx> {
475
466
self . make_state ( v, source_info, is_return, & mut data. statements ) ;
476
467
let state = if let Some ( ( resume, mut resume_arg) ) = resume {
477
468
// Yield
478
- let state = RESERVED_VARIANTS + self . suspension_points . len ( ) ;
469
+ let state = CoroutineArgs :: RESERVED_VARIANTS + self . suspension_points . len ( ) ;
479
470
480
471
// The resume arg target location might itself be remapped if its base local is
481
472
// live across a yield.
@@ -508,7 +499,7 @@ impl<'tcx> MutVisitor<'tcx> for TransformVisitor<'tcx> {
508
499
VariantIdx :: new ( state)
509
500
} else {
510
501
// Return
511
- VariantIdx :: new ( RETURNED ) // state for returned
502
+ VariantIdx :: new ( CoroutineArgs :: RETURNED ) // state for returned
512
503
} ;
513
504
data. statements . push ( self . set_discr ( state, source_info) ) ;
514
505
data. terminator_mut ( ) . kind = TerminatorKind :: Return ;
@@ -1044,10 +1035,11 @@ fn compute_layout<'tcx>(
1044
1035
// Build the coroutine variant field list.
1045
1036
// Create a map from local indices to coroutine struct indices.
1046
1037
let mut variant_fields: IndexVec < VariantIdx , IndexVec < FieldIdx , CoroutineSavedLocal > > =
1047
- iter:: repeat ( IndexVec :: new ( ) ) . take ( RESERVED_VARIANTS ) . collect ( ) ;
1038
+ iter:: repeat ( IndexVec :: new ( ) ) . take ( CoroutineArgs :: RESERVED_VARIANTS ) . collect ( ) ;
1048
1039
let mut remap = IndexVec :: from_elem_n ( None , saved_locals. domain_size ( ) ) ;
1049
1040
for ( suspension_point_idx, live_locals) in live_locals_at_suspension_points. iter ( ) . enumerate ( ) {
1050
- let variant_index = VariantIdx :: from ( RESERVED_VARIANTS + suspension_point_idx) ;
1041
+ let variant_index =
1042
+ VariantIdx :: from ( CoroutineArgs :: RESERVED_VARIANTS + suspension_point_idx) ;
1051
1043
let mut fields = IndexVec :: new ( ) ;
1052
1044
for ( idx, saved_local) in live_locals. iter ( ) . enumerate ( ) {
1053
1045
fields. push ( saved_local) ;
@@ -1194,7 +1186,7 @@ fn create_coroutine_drop_shim<'tcx>(
1194
1186
1195
1187
let mut cases = create_cases ( & mut body, transform, Operation :: Drop ) ;
1196
1188
1197
- cases. insert ( 0 , ( UNRESUMED , drop_clean) ) ;
1189
+ cases. insert ( 0 , ( CoroutineArgs :: UNRESUMED , drop_clean) ) ;
1198
1190
1199
1191
// The returned state and the poisoned state fall through to the default
1200
1192
// case which is just to return
@@ -1344,7 +1336,9 @@ fn create_coroutine_resume_function<'tcx>(
1344
1336
if can_unwind {
1345
1337
let source_info = SourceInfo :: outermost ( body. span ) ;
1346
1338
let poison_block = body. basic_blocks_mut ( ) . push ( BasicBlockData {
1347
- statements : vec ! [ transform. set_discr( VariantIdx :: new( POISONED ) , source_info) ] ,
1339
+ statements : vec ! [
1340
+ transform. set_discr( VariantIdx :: new( CoroutineArgs :: POISONED ) , source_info) ,
1341
+ ] ,
1348
1342
terminator : Some ( Terminator { source_info, kind : TerminatorKind :: UnwindResume } ) ,
1349
1343
is_cleanup : true ,
1350
1344
} ) ;
@@ -1376,13 +1370,16 @@ fn create_coroutine_resume_function<'tcx>(
1376
1370
use rustc_middle:: mir:: AssertKind :: { ResumedAfterPanic , ResumedAfterReturn } ;
1377
1371
1378
1372
// Jump to the entry point on the unresumed
1379
- cases. insert ( 0 , ( UNRESUMED , START_BLOCK ) ) ;
1373
+ cases. insert ( 0 , ( CoroutineArgs :: UNRESUMED , START_BLOCK ) ) ;
1380
1374
1381
1375
// Panic when resumed on the returned or poisoned state
1382
1376
if can_unwind {
1383
1377
cases. insert (
1384
1378
1 ,
1385
- ( POISONED , insert_panic_block ( tcx, body, ResumedAfterPanic ( transform. coroutine_kind ) ) ) ,
1379
+ (
1380
+ CoroutineArgs :: POISONED ,
1381
+ insert_panic_block ( tcx, body, ResumedAfterPanic ( transform. coroutine_kind ) ) ,
1382
+ ) ,
1386
1383
) ;
1387
1384
}
1388
1385
@@ -1397,7 +1394,7 @@ fn create_coroutine_resume_function<'tcx>(
1397
1394
transform. insert_none_ret_block ( body)
1398
1395
}
1399
1396
} ;
1400
- cases. insert ( 1 , ( RETURNED , block) ) ;
1397
+ cases. insert ( 1 , ( CoroutineArgs :: RETURNED , block) ) ;
1401
1398
}
1402
1399
1403
1400
insert_switch ( body, cases, & transform, TerminatorKind :: Unreachable ) ;
0 commit comments