@@ -242,9 +242,15 @@ pub struct ClosureArgs<'tcx> {
242
242
243
243
/// Struct returned by `split()`.
244
244
pub struct ClosureArgsParts < ' tcx > {
245
+ /// This is the args of the typeck root.
245
246
pub parent_args : & ' tcx [ GenericArg < ' tcx > ] ,
247
+ /// Represents the maximum calling capability of the closure.
246
248
pub closure_kind_ty : Ty < ' tcx > ,
249
+ /// Captures the closure's signature. This closure signature is "tupled", and
250
+ /// thus has a peculiar signature of `extern "rust-call" fn((Args, ...)) -> Ty`.
247
251
pub closure_sig_as_fn_ptr_ty : Ty < ' tcx > ,
252
+ /// The upvars captured by the closure. Remains an inference variable
253
+ /// until the upvar analysis, which happens late in HIR typeck.
248
254
pub tupled_upvars_ty : Ty < ' tcx > ,
249
255
}
250
256
@@ -277,15 +283,6 @@ impl<'tcx> ClosureArgs<'tcx> {
277
283
}
278
284
}
279
285
280
- /// Returns `true` only if enough of the synthetic types are known to
281
- /// allow using all of the methods on `ClosureArgs` without panicking.
282
- ///
283
- /// Used primarily by `ty::print::pretty` to be able to handle closure
284
- /// types that haven't had their synthetic types substituted in.
285
- pub fn is_valid ( self ) -> bool {
286
- self . args . len ( ) >= 3 && matches ! ( self . split( ) . tupled_upvars_ty. kind( ) , Tuple ( _) )
287
- }
288
-
289
286
/// Returns the substitutions of the closure's parent.
290
287
pub fn parent_args ( self ) -> & ' tcx [ GenericArg < ' tcx > ] {
291
288
self . split ( ) . parent_args
@@ -296,9 +293,9 @@ impl<'tcx> ClosureArgs<'tcx> {
296
293
/// empty iterator is returned.
297
294
#[ inline]
298
295
pub fn upvar_tys ( self ) -> & ' tcx List < Ty < ' tcx > > {
299
- match self . tupled_upvars_ty ( ) . kind ( ) {
296
+ match * self . tupled_upvars_ty ( ) . kind ( ) {
300
297
TyKind :: Error ( _) => ty:: List :: empty ( ) ,
301
- TyKind :: Tuple ( .. ) => self . tupled_upvars_ty ( ) . tuple_fields ( ) ,
298
+ TyKind :: Tuple ( tys ) => tys ,
302
299
TyKind :: Infer ( _) => bug ! ( "upvar_tys called before capture types are inferred" ) ,
303
300
ty => bug ! ( "Unexpected representation of upvar types tuple {:?}" , ty) ,
304
301
}
@@ -337,10 +334,9 @@ impl<'tcx> ClosureArgs<'tcx> {
337
334
338
335
/// Extracts the signature from the closure.
339
336
pub fn sig ( self ) -> ty:: PolyFnSig < ' tcx > {
340
- let ty = self . sig_as_fn_ptr_ty ( ) ;
341
- match ty. kind ( ) {
342
- ty:: FnPtr ( sig) => * sig,
343
- _ => bug ! ( "closure_sig_as_fn_ptr_ty is not a fn-ptr: {:?}" , ty. kind( ) ) ,
337
+ match * self . sig_as_fn_ptr_ty ( ) . kind ( ) {
338
+ ty:: FnPtr ( sig) => sig,
339
+ ty => bug ! ( "closure_sig_as_fn_ptr_ty is not a fn-ptr: {ty:?}" ) ,
344
340
}
345
341
}
346
342
@@ -356,11 +352,17 @@ pub struct CoroutineArgs<'tcx> {
356
352
}
357
353
358
354
pub struct CoroutineArgsParts < ' tcx > {
355
+ /// This is the args of the typeck root.
359
356
pub parent_args : & ' tcx [ GenericArg < ' tcx > ] ,
360
357
pub resume_ty : Ty < ' tcx > ,
361
358
pub yield_ty : Ty < ' tcx > ,
362
359
pub return_ty : Ty < ' tcx > ,
360
+ /// The interior type of the coroutine.
361
+ /// Represents all types that are stored in locals
362
+ /// in the coroutine's body.
363
363
pub witness : Ty < ' tcx > ,
364
+ /// The upvars captured by the closure. Remains an inference variable
365
+ /// until the upvar analysis, which happens late in HIR typeck.
364
366
pub tupled_upvars_ty : Ty < ' tcx > ,
365
367
}
366
368
@@ -397,15 +399,6 @@ impl<'tcx> CoroutineArgs<'tcx> {
397
399
}
398
400
}
399
401
400
- /// Returns `true` only if enough of the synthetic types are known to
401
- /// allow using all of the methods on `CoroutineArgs` without panicking.
402
- ///
403
- /// Used primarily by `ty::print::pretty` to be able to handle coroutine
404
- /// types that haven't had their synthetic types substituted in.
405
- pub fn is_valid ( self ) -> bool {
406
- self . args . len ( ) >= 5 && matches ! ( self . split( ) . tupled_upvars_ty. kind( ) , Tuple ( _) )
407
- }
408
-
409
402
/// Returns the substitutions of the coroutine's parent.
410
403
pub fn parent_args ( self ) -> & ' tcx [ GenericArg < ' tcx > ] {
411
404
self . split ( ) . parent_args
@@ -425,9 +418,9 @@ impl<'tcx> CoroutineArgs<'tcx> {
425
418
/// empty iterator is returned.
426
419
#[ inline]
427
420
pub fn upvar_tys ( self ) -> & ' tcx List < Ty < ' tcx > > {
428
- match self . tupled_upvars_ty ( ) . kind ( ) {
421
+ match * self . tupled_upvars_ty ( ) . kind ( ) {
429
422
TyKind :: Error ( _) => ty:: List :: empty ( ) ,
430
- TyKind :: Tuple ( .. ) => self . tupled_upvars_ty ( ) . tuple_fields ( ) ,
423
+ TyKind :: Tuple ( tys ) => tys ,
431
424
TyKind :: Infer ( _) => bug ! ( "upvar_tys called before capture types are inferred" ) ,
432
425
ty => bug ! ( "Unexpected representation of upvar types tuple {:?}" , ty) ,
433
426
}
0 commit comments