|
2 | 2 |
|
3 | 3 | use crate::ty::codec::{TyDecoder, TyEncoder};
|
4 | 4 | use crate::ty::fold::{FallibleTypeFolder, TypeFoldable};
|
5 |
| -use crate::ty::sty::{ClosureArgs, CoroutineArgs, CoroutineClosureArgs, InlineConstArgs}; |
6 | 5 | use crate::ty::visit::{TypeVisitable, TypeVisitor};
|
7 |
| -use crate::ty::{self, Lift, List, Ty, TyCtxt}; |
| 6 | +use crate::ty::{ |
| 7 | + self, ClosureArgs, CoroutineArgs, CoroutineClosureArgs, InlineConstArgs, Lift, List, Ty, TyCtxt, |
| 8 | +}; |
8 | 9 |
|
9 | 10 | use rustc_ast_ir::visit::VisitorResult;
|
10 | 11 | use rustc_ast_ir::walk_visitable_list;
|
@@ -56,6 +57,64 @@ impl<'tcx> rustc_type_ir::inherent::GenericArgs<TyCtxt<'tcx>> for ty::GenericArg
|
56 | 57 | ) -> ty::GenericArgsRef<'tcx> {
|
57 | 58 | ty::GenericArgs::extend_with_error(tcx, def_id, original_args)
|
58 | 59 | }
|
| 60 | + |
| 61 | + fn split_closure_args(self) -> ty::ClosureArgsParts<TyCtxt<'tcx>> { |
| 62 | + match self[..] { |
| 63 | + [ref parent_args @ .., closure_kind_ty, closure_sig_as_fn_ptr_ty, tupled_upvars_ty] => { |
| 64 | + ty::ClosureArgsParts { |
| 65 | + parent_args, |
| 66 | + closure_kind_ty: closure_kind_ty.expect_ty(), |
| 67 | + closure_sig_as_fn_ptr_ty: closure_sig_as_fn_ptr_ty.expect_ty(), |
| 68 | + tupled_upvars_ty: tupled_upvars_ty.expect_ty(), |
| 69 | + } |
| 70 | + } |
| 71 | + _ => bug!("closure args missing synthetics"), |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + fn split_coroutine_closure_args(self) -> ty::CoroutineClosureArgsParts<TyCtxt<'tcx>> { |
| 76 | + match self[..] { |
| 77 | + [ |
| 78 | + ref parent_args @ .., |
| 79 | + closure_kind_ty, |
| 80 | + signature_parts_ty, |
| 81 | + tupled_upvars_ty, |
| 82 | + coroutine_captures_by_ref_ty, |
| 83 | + coroutine_witness_ty, |
| 84 | + ] => ty::CoroutineClosureArgsParts { |
| 85 | + parent_args, |
| 86 | + closure_kind_ty: closure_kind_ty.expect_ty(), |
| 87 | + signature_parts_ty: signature_parts_ty.expect_ty(), |
| 88 | + tupled_upvars_ty: tupled_upvars_ty.expect_ty(), |
| 89 | + coroutine_captures_by_ref_ty: coroutine_captures_by_ref_ty.expect_ty(), |
| 90 | + coroutine_witness_ty: coroutine_witness_ty.expect_ty(), |
| 91 | + }, |
| 92 | + _ => bug!("closure args missing synthetics"), |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + fn split_coroutine_args(self) -> ty::CoroutineArgsParts<TyCtxt<'tcx>> { |
| 97 | + match self[..] { |
| 98 | + [ |
| 99 | + ref parent_args @ .., |
| 100 | + kind_ty, |
| 101 | + resume_ty, |
| 102 | + yield_ty, |
| 103 | + return_ty, |
| 104 | + witness, |
| 105 | + tupled_upvars_ty, |
| 106 | + ] => ty::CoroutineArgsParts { |
| 107 | + parent_args, |
| 108 | + kind_ty: kind_ty.expect_ty(), |
| 109 | + resume_ty: resume_ty.expect_ty(), |
| 110 | + yield_ty: yield_ty.expect_ty(), |
| 111 | + return_ty: return_ty.expect_ty(), |
| 112 | + witness: witness.expect_ty(), |
| 113 | + tupled_upvars_ty: tupled_upvars_ty.expect_ty(), |
| 114 | + }, |
| 115 | + _ => bug!("coroutine args missing synthetics"), |
| 116 | + } |
| 117 | + } |
59 | 118 | }
|
60 | 119 |
|
61 | 120 | impl<'tcx> rustc_type_ir::inherent::IntoKind for GenericArg<'tcx> {
|
@@ -295,23 +354,23 @@ impl<'tcx> GenericArgs<'tcx> {
|
295 | 354 | /// Closure args have a particular structure controlled by the
|
296 | 355 | /// compiler that encodes information like the signature and closure kind;
|
297 | 356 | /// see `ty::ClosureArgs` struct for more comments.
|
298 |
| - pub fn as_closure(&'tcx self) -> ClosureArgs<'tcx> { |
| 357 | + pub fn as_closure(&'tcx self) -> ClosureArgs<TyCtxt<'tcx>> { |
299 | 358 | ClosureArgs { args: self }
|
300 | 359 | }
|
301 | 360 |
|
302 | 361 | /// Interpret these generic args as the args of a coroutine-closure type.
|
303 | 362 | /// Coroutine-closure args have a particular structure controlled by the
|
304 | 363 | /// compiler that encodes information like the signature and closure kind;
|
305 | 364 | /// see `ty::CoroutineClosureArgs` struct for more comments.
|
306 |
| - pub fn as_coroutine_closure(&'tcx self) -> CoroutineClosureArgs<'tcx> { |
| 365 | + pub fn as_coroutine_closure(&'tcx self) -> CoroutineClosureArgs<TyCtxt<'tcx>> { |
307 | 366 | CoroutineClosureArgs { args: self }
|
308 | 367 | }
|
309 | 368 |
|
310 | 369 | /// Interpret these generic args as the args of a coroutine type.
|
311 | 370 | /// Coroutine args have a particular structure controlled by the
|
312 | 371 | /// compiler that encodes information like the signature and coroutine kind;
|
313 | 372 | /// see `ty::CoroutineArgs` struct for more comments.
|
314 |
| - pub fn as_coroutine(&'tcx self) -> CoroutineArgs<'tcx> { |
| 373 | + pub fn as_coroutine(&'tcx self) -> CoroutineArgs<TyCtxt<'tcx>> { |
315 | 374 | CoroutineArgs { args: self }
|
316 | 375 | }
|
317 | 376 |
|
|
0 commit comments