@@ -241,38 +241,36 @@ pub struct ClosureArgs<'tcx> {
241241}
242242
243243/// Struct returned by `split()`.
244- pub struct ClosureArgsParts < ' tcx , T > {
244+ pub struct ClosureArgsParts < ' tcx > {
245245 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 > ,
249249}
250250
251251impl < ' tcx > ClosureArgs < ' tcx > {
252252 /// Construct `ClosureArgs` from `ClosureArgsParts`, containing `Args`
253253 /// 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 > {
255255 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+ ] ) ) ,
263261 }
264262 }
265263
266264 /// Divides the closure args into their respective components.
267265 /// 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 > {
269267 match self . args [ ..] {
270268 [ ref parent_args @ .., closure_kind_ty, closure_sig_as_fn_ptr_ty, tupled_upvars_ty] => {
271269 ClosureArgsParts {
272270 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 ( ) ,
276274 }
277275 }
278276 _ => bug ! ( "closure args missing synthetics" ) ,
@@ -285,7 +283,7 @@ impl<'tcx> ClosureArgs<'tcx> {
285283 /// Used primarily by `ty::print::pretty` to be able to handle closure
286284 /// types that haven't had their synthetic types substituted in.
287285 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 ( _) )
289287 }
290288
291289 /// Returns the substitutions of the closure's parent.
@@ -309,14 +307,14 @@ impl<'tcx> ClosureArgs<'tcx> {
309307 /// Returns the tuple type representing the upvars for this closure.
310308 #[ inline]
311309 pub fn tupled_upvars_ty ( self ) -> Ty < ' tcx > {
312- self . split ( ) . tupled_upvars_ty . expect_ty ( )
310+ self . split ( ) . tupled_upvars_ty
313311 }
314312
315313 /// Returns the closure kind for this closure; may return a type
316314 /// variable during inference. To get the closure kind during
317315 /// inference, use `infcx.closure_kind(args)`.
318316 pub fn kind_ty ( self ) -> Ty < ' tcx > {
319- self . split ( ) . closure_kind_ty . expect_ty ( )
317+ self . split ( ) . closure_kind_ty
320318 }
321319
322320 /// Returns the `fn` pointer type representing the closure signature for this
@@ -325,7 +323,7 @@ impl<'tcx> ClosureArgs<'tcx> {
325323 // type is known at the time of the creation of `ClosureArgs`,
326324 // see `rustc_hir_analysis::check::closure`.
327325 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
329327 }
330328
331329 /// Returns the closure kind for this closure; only usable outside
@@ -357,51 +355,42 @@ pub struct CoroutineArgs<'tcx> {
357355 pub args : GenericArgsRef < ' tcx > ,
358356}
359357
360- pub struct CoroutineArgsParts < ' tcx , T > {
358+ pub struct CoroutineArgsParts < ' tcx > {
361359 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 > ,
367365}
368366
369367impl < ' tcx > CoroutineArgs < ' tcx > {
370368 /// Construct `CoroutineArgs` from `CoroutineArgsParts`, containing `Args`
371369 /// 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 > {
376371 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+ ] ) ) ,
390379 }
391380 }
392381
393382 /// Divides the coroutine args into their respective components.
394383 /// 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 > {
396385 match self . args [ ..] {
397386 [ ref parent_args @ .., resume_ty, yield_ty, return_ty, witness, tupled_upvars_ty] => {
398387 CoroutineArgsParts {
399388 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 ( ) ,
405394 }
406395 }
407396 _ => bug ! ( "coroutine args missing synthetics" ) ,
@@ -414,7 +403,7 @@ impl<'tcx> CoroutineArgs<'tcx> {
414403 /// Used primarily by `ty::print::pretty` to be able to handle coroutine
415404 /// types that haven't had their synthetic types substituted in.
416405 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 ( _) )
418407 }
419408
420409 /// Returns the substitutions of the coroutine's parent.
@@ -428,7 +417,7 @@ impl<'tcx> CoroutineArgs<'tcx> {
428417 /// The state transformation MIR pass may only produce layouts which mention types
429418 /// in this tuple. Upvars are not counted here.
430419 pub fn witness ( self ) -> Ty < ' tcx > {
431- self . split ( ) . witness . expect_ty ( )
420+ self . split ( ) . witness
432421 }
433422
434423 /// Returns an iterator over the list of types of captured paths by the coroutine.
@@ -447,31 +436,32 @@ impl<'tcx> CoroutineArgs<'tcx> {
447436 /// Returns the tuple type representing the upvars for this coroutine.
448437 #[ inline]
449438 pub fn tupled_upvars_ty ( self ) -> Ty < ' tcx > {
450- self . split ( ) . tupled_upvars_ty . expect_ty ( )
439+ self . split ( ) . tupled_upvars_ty
451440 }
452441
453442 /// Returns the type representing the resume type of the coroutine.
454443 pub fn resume_ty ( self ) -> Ty < ' tcx > {
455- self . split ( ) . resume_ty . expect_ty ( )
444+ self . split ( ) . resume_ty
456445 }
457446
458447 /// Returns the type representing the yield type of the coroutine.
459448 pub fn yield_ty ( self ) -> Ty < ' tcx > {
460- self . split ( ) . yield_ty . expect_ty ( )
449+ self . split ( ) . yield_ty
461450 }
462451
463452 /// Returns the type representing the return type of the coroutine.
464453 pub fn return_ty ( self ) -> Ty < ' tcx > {
465- self . split ( ) . return_ty . expect_ty ( )
454+ self . split ( ) . return_ty
466455 }
467456
468457 /// Returns the "coroutine signature", which consists of its resume, yield
469458 /// and return types.
470459 pub fn sig ( self ) -> GenSig < ' tcx > {
460+ let parts = self . split ( ) ;
471461 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 ,
475465 }
476466 }
477467}
0 commit comments