@@ -241,38 +241,36 @@ pub struct ClosureArgs<'tcx> {
241
241
}
242
242
243
243
/// Struct returned by `split()`.
244
- pub struct ClosureArgsParts < ' tcx , T > {
244
+ pub struct ClosureArgsParts < ' tcx > {
245
245
pub parent_args : & ' tcx [ GenericArg < ' tcx > ] ,
246
- pub closure_kind_ty : T ,
247
- pub closure_sig_as_fn_ptr_ty : T ,
248
- pub tupled_upvars_ty : T ,
246
+ pub closure_kind_ty : Ty < ' tcx > ,
247
+ pub closure_sig_as_fn_ptr_ty : Ty < ' tcx > ,
248
+ pub tupled_upvars_ty : Ty < ' tcx > ,
249
249
}
250
250
251
251
impl < ' tcx > ClosureArgs < ' tcx > {
252
252
/// Construct `ClosureArgs` from `ClosureArgsParts`, containing `Args`
253
253
/// for the closure parent, alongside additional closure-specific components.
254
- pub fn new ( tcx : TyCtxt < ' tcx > , parts : ClosureArgsParts < ' tcx , Ty < ' tcx > > ) -> ClosureArgs < ' tcx > {
254
+ pub fn new ( tcx : TyCtxt < ' tcx > , parts : ClosureArgsParts < ' tcx > ) -> ClosureArgs < ' tcx > {
255
255
ClosureArgs {
256
- args : tcx. mk_args_from_iter (
257
- parts. parent_args . iter ( ) . copied ( ) . chain (
258
- [ parts. closure_kind_ty , parts. closure_sig_as_fn_ptr_ty , parts. tupled_upvars_ty ]
259
- . iter ( )
260
- . map ( |& ty| ty. into ( ) ) ,
261
- ) ,
262
- ) ,
256
+ args : tcx. mk_args_from_iter ( parts. parent_args . iter ( ) . copied ( ) . chain ( [
257
+ parts. closure_kind_ty . into ( ) ,
258
+ parts. closure_sig_as_fn_ptr_ty . into ( ) ,
259
+ parts. tupled_upvars_ty . into ( ) ,
260
+ ] ) ) ,
263
261
}
264
262
}
265
263
266
264
/// Divides the closure args into their respective components.
267
265
/// The ordering assumed here must match that used by `ClosureArgs::new` above.
268
- fn split ( self ) -> ClosureArgsParts < ' tcx , GenericArg < ' tcx > > {
266
+ fn split ( self ) -> ClosureArgsParts < ' tcx > {
269
267
match self . args [ ..] {
270
268
[ ref parent_args @ .., closure_kind_ty, closure_sig_as_fn_ptr_ty, tupled_upvars_ty] => {
271
269
ClosureArgsParts {
272
270
parent_args,
273
- closure_kind_ty,
274
- closure_sig_as_fn_ptr_ty,
275
- tupled_upvars_ty,
271
+ closure_kind_ty : closure_kind_ty . expect_ty ( ) ,
272
+ closure_sig_as_fn_ptr_ty : closure_sig_as_fn_ptr_ty . expect_ty ( ) ,
273
+ tupled_upvars_ty : tupled_upvars_ty . expect_ty ( ) ,
276
274
}
277
275
}
278
276
_ => bug ! ( "closure args missing synthetics" ) ,
@@ -285,7 +283,7 @@ impl<'tcx> ClosureArgs<'tcx> {
285
283
/// Used primarily by `ty::print::pretty` to be able to handle closure
286
284
/// types that haven't had their synthetic types substituted in.
287
285
pub fn is_valid ( self ) -> bool {
288
- self . args . len ( ) >= 3 && matches ! ( self . split( ) . tupled_upvars_ty. expect_ty ( ) . kind( ) , Tuple ( _) )
286
+ self . args . len ( ) >= 3 && matches ! ( self . split( ) . tupled_upvars_ty. kind( ) , Tuple ( _) )
289
287
}
290
288
291
289
/// Returns the substitutions of the closure's parent.
@@ -309,14 +307,14 @@ impl<'tcx> ClosureArgs<'tcx> {
309
307
/// Returns the tuple type representing the upvars for this closure.
310
308
#[ inline]
311
309
pub fn tupled_upvars_ty ( self ) -> Ty < ' tcx > {
312
- self . split ( ) . tupled_upvars_ty . expect_ty ( )
310
+ self . split ( ) . tupled_upvars_ty
313
311
}
314
312
315
313
/// Returns the closure kind for this closure; may return a type
316
314
/// variable during inference. To get the closure kind during
317
315
/// inference, use `infcx.closure_kind(args)`.
318
316
pub fn kind_ty ( self ) -> Ty < ' tcx > {
319
- self . split ( ) . closure_kind_ty . expect_ty ( )
317
+ self . split ( ) . closure_kind_ty
320
318
}
321
319
322
320
/// Returns the `fn` pointer type representing the closure signature for this
@@ -325,7 +323,7 @@ impl<'tcx> ClosureArgs<'tcx> {
325
323
// type is known at the time of the creation of `ClosureArgs`,
326
324
// see `rustc_hir_analysis::check::closure`.
327
325
pub fn sig_as_fn_ptr_ty ( self ) -> Ty < ' tcx > {
328
- self . split ( ) . closure_sig_as_fn_ptr_ty . expect_ty ( )
326
+ self . split ( ) . closure_sig_as_fn_ptr_ty
329
327
}
330
328
331
329
/// Returns the closure kind for this closure; only usable outside
@@ -357,51 +355,42 @@ pub struct CoroutineArgs<'tcx> {
357
355
pub args : GenericArgsRef < ' tcx > ,
358
356
}
359
357
360
- pub struct CoroutineArgsParts < ' tcx , T > {
358
+ pub struct CoroutineArgsParts < ' tcx > {
361
359
pub parent_args : & ' tcx [ GenericArg < ' tcx > ] ,
362
- pub resume_ty : T ,
363
- pub yield_ty : T ,
364
- pub return_ty : T ,
365
- pub witness : T ,
366
- pub tupled_upvars_ty : T ,
360
+ pub resume_ty : Ty < ' tcx > ,
361
+ pub yield_ty : Ty < ' tcx > ,
362
+ pub return_ty : Ty < ' tcx > ,
363
+ pub witness : Ty < ' tcx > ,
364
+ pub tupled_upvars_ty : Ty < ' tcx > ,
367
365
}
368
366
369
367
impl < ' tcx > CoroutineArgs < ' tcx > {
370
368
/// Construct `CoroutineArgs` from `CoroutineArgsParts`, containing `Args`
371
369
/// for the coroutine parent, alongside additional coroutine-specific components.
372
- pub fn new (
373
- tcx : TyCtxt < ' tcx > ,
374
- parts : CoroutineArgsParts < ' tcx , Ty < ' tcx > > ,
375
- ) -> CoroutineArgs < ' tcx > {
370
+ pub fn new ( tcx : TyCtxt < ' tcx > , parts : CoroutineArgsParts < ' tcx > ) -> CoroutineArgs < ' tcx > {
376
371
CoroutineArgs {
377
- args : tcx. mk_args_from_iter (
378
- parts. parent_args . iter ( ) . copied ( ) . chain (
379
- [
380
- parts. resume_ty ,
381
- parts. yield_ty ,
382
- parts. return_ty ,
383
- parts. witness ,
384
- parts. tupled_upvars_ty ,
385
- ]
386
- . iter ( )
387
- . map ( |& ty| ty. into ( ) ) ,
388
- ) ,
389
- ) ,
372
+ args : tcx. mk_args_from_iter ( parts. parent_args . iter ( ) . copied ( ) . chain ( [
373
+ parts. resume_ty . into ( ) ,
374
+ parts. yield_ty . into ( ) ,
375
+ parts. return_ty . into ( ) ,
376
+ parts. witness . into ( ) ,
377
+ parts. tupled_upvars_ty . into ( ) ,
378
+ ] ) ) ,
390
379
}
391
380
}
392
381
393
382
/// Divides the coroutine args into their respective components.
394
383
/// The ordering assumed here must match that used by `CoroutineArgs::new` above.
395
- fn split ( self ) -> CoroutineArgsParts < ' tcx , GenericArg < ' tcx > > {
384
+ fn split ( self ) -> CoroutineArgsParts < ' tcx > {
396
385
match self . args [ ..] {
397
386
[ ref parent_args @ .., resume_ty, yield_ty, return_ty, witness, tupled_upvars_ty] => {
398
387
CoroutineArgsParts {
399
388
parent_args,
400
- resume_ty,
401
- yield_ty,
402
- return_ty,
403
- witness,
404
- tupled_upvars_ty,
389
+ resume_ty : resume_ty . expect_ty ( ) ,
390
+ yield_ty : yield_ty . expect_ty ( ) ,
391
+ return_ty : return_ty . expect_ty ( ) ,
392
+ witness : witness . expect_ty ( ) ,
393
+ tupled_upvars_ty : tupled_upvars_ty . expect_ty ( ) ,
405
394
}
406
395
}
407
396
_ => bug ! ( "coroutine args missing synthetics" ) ,
@@ -414,7 +403,7 @@ impl<'tcx> CoroutineArgs<'tcx> {
414
403
/// Used primarily by `ty::print::pretty` to be able to handle coroutine
415
404
/// types that haven't had their synthetic types substituted in.
416
405
pub fn is_valid ( self ) -> bool {
417
- self . args . len ( ) >= 5 && matches ! ( self . split( ) . tupled_upvars_ty. expect_ty ( ) . kind( ) , Tuple ( _) )
406
+ self . args . len ( ) >= 5 && matches ! ( self . split( ) . tupled_upvars_ty. kind( ) , Tuple ( _) )
418
407
}
419
408
420
409
/// Returns the substitutions of the coroutine's parent.
@@ -428,7 +417,7 @@ impl<'tcx> CoroutineArgs<'tcx> {
428
417
/// The state transformation MIR pass may only produce layouts which mention types
429
418
/// in this tuple. Upvars are not counted here.
430
419
pub fn witness ( self ) -> Ty < ' tcx > {
431
- self . split ( ) . witness . expect_ty ( )
420
+ self . split ( ) . witness
432
421
}
433
422
434
423
/// Returns an iterator over the list of types of captured paths by the coroutine.
@@ -447,31 +436,32 @@ impl<'tcx> CoroutineArgs<'tcx> {
447
436
/// Returns the tuple type representing the upvars for this coroutine.
448
437
#[ inline]
449
438
pub fn tupled_upvars_ty ( self ) -> Ty < ' tcx > {
450
- self . split ( ) . tupled_upvars_ty . expect_ty ( )
439
+ self . split ( ) . tupled_upvars_ty
451
440
}
452
441
453
442
/// Returns the type representing the resume type of the coroutine.
454
443
pub fn resume_ty ( self ) -> Ty < ' tcx > {
455
- self . split ( ) . resume_ty . expect_ty ( )
444
+ self . split ( ) . resume_ty
456
445
}
457
446
458
447
/// Returns the type representing the yield type of the coroutine.
459
448
pub fn yield_ty ( self ) -> Ty < ' tcx > {
460
- self . split ( ) . yield_ty . expect_ty ( )
449
+ self . split ( ) . yield_ty
461
450
}
462
451
463
452
/// Returns the type representing the return type of the coroutine.
464
453
pub fn return_ty ( self ) -> Ty < ' tcx > {
465
- self . split ( ) . return_ty . expect_ty ( )
454
+ self . split ( ) . return_ty
466
455
}
467
456
468
457
/// Returns the "coroutine signature", which consists of its resume, yield
469
458
/// and return types.
470
459
pub fn sig ( self ) -> GenSig < ' tcx > {
460
+ let parts = self . split ( ) ;
471
461
ty:: GenSig {
472
- resume_ty : self . resume_ty ( ) ,
473
- yield_ty : self . yield_ty ( ) ,
474
- return_ty : self . return_ty ( ) ,
462
+ resume_ty : parts . resume_ty ,
463
+ yield_ty : parts . yield_ty ,
464
+ return_ty : parts . return_ty ,
475
465
}
476
466
}
477
467
}
0 commit comments