@@ -242,9 +242,15 @@ pub struct ClosureArgs<'tcx> {
242242
243243/// Struct returned by `split()`.
244244pub struct ClosureArgsParts < ' tcx > {
245+ // This is the args of the typeck root.
245246 pub parent_args : & ' tcx [ GenericArg < ' tcx > ] ,
247+ // Represents the maximum calling capability of the closure.
246248 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`.
247251 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.
248254 pub tupled_upvars_ty : Ty < ' tcx > ,
249255}
250256
@@ -277,15 +283,6 @@ impl<'tcx> ClosureArgs<'tcx> {
277283 }
278284 }
279285
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-
289286 /// Returns the substitutions of the closure's parent.
290287 pub fn parent_args ( self ) -> & ' tcx [ GenericArg < ' tcx > ] {
291288 self . split ( ) . parent_args
@@ -296,9 +293,9 @@ impl<'tcx> ClosureArgs<'tcx> {
296293 /// empty iterator is returned.
297294 #[ inline]
298295 pub fn upvar_tys ( self ) -> & ' tcx List < Ty < ' tcx > > {
299- match self . tupled_upvars_ty ( ) . kind ( ) {
296+ match * self . tupled_upvars_ty ( ) . kind ( ) {
300297 TyKind :: Error ( _) => ty:: List :: empty ( ) ,
301- TyKind :: Tuple ( .. ) => self . tupled_upvars_ty ( ) . tuple_fields ( ) ,
298+ TyKind :: Tuple ( tys ) => tys ,
302299 TyKind :: Infer ( _) => bug ! ( "upvar_tys called before capture types are inferred" ) ,
303300 ty => bug ! ( "Unexpected representation of upvar types tuple {:?}" , ty) ,
304301 }
@@ -337,10 +334,9 @@ impl<'tcx> ClosureArgs<'tcx> {
337334
338335 /// Extracts the signature from the closure.
339336 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:?}" ) ,
344340 }
345341 }
346342
@@ -356,11 +352,17 @@ pub struct CoroutineArgs<'tcx> {
356352}
357353
358354pub struct CoroutineArgsParts < ' tcx > {
355+ // This is the args of the typeck root.
359356 pub parent_args : & ' tcx [ GenericArg < ' tcx > ] ,
360357 pub resume_ty : Ty < ' tcx > ,
361358 pub yield_ty : Ty < ' tcx > ,
362359 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.
363363 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.
364366 pub tupled_upvars_ty : Ty < ' tcx > ,
365367}
366368
@@ -397,15 +399,6 @@ impl<'tcx> CoroutineArgs<'tcx> {
397399 }
398400 }
399401
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-
409402 /// Returns the substitutions of the coroutine's parent.
410403 pub fn parent_args ( self ) -> & ' tcx [ GenericArg < ' tcx > ] {
411404 self . split ( ) . parent_args
@@ -425,9 +418,9 @@ impl<'tcx> CoroutineArgs<'tcx> {
425418 /// empty iterator is returned.
426419 #[ inline]
427420 pub fn upvar_tys ( self ) -> & ' tcx List < Ty < ' tcx > > {
428- match self . tupled_upvars_ty ( ) . kind ( ) {
421+ match * self . tupled_upvars_ty ( ) . kind ( ) {
429422 TyKind :: Error ( _) => ty:: List :: empty ( ) ,
430- TyKind :: Tuple ( .. ) => self . tupled_upvars_ty ( ) . tuple_fields ( ) ,
423+ TyKind :: Tuple ( tys ) => tys ,
431424 TyKind :: Infer ( _) => bug ! ( "upvar_tys called before capture types are inferred" ) ,
432425 ty => bug ! ( "Unexpected representation of upvar types tuple {:?}" , ty) ,
433426 }
0 commit comments