1use core::intrinsics;
4use std::marker::PhantomData;
5use std::num::NonZero;
6use std::ptr::NonNull;
7
8use rustc_data_structures::intern::Interned;
9use rustc_errors::{DiagArgValue, IntoDiagArg};
10use rustc_hir::def_id::DefId;
11use rustc_macros::{HashStable, TyDecodable, TyEncodable, extension};
12use rustc_serialize::{Decodable, Encodable};
13use rustc_type_ir::WithCachedTypeInfo;
14use rustc_type_ir::walk::TypeWalker;
15use smallvec::SmallVec;
16
17use crate::ty::codec::{TyDecoder, TyEncoder};
18use crate::ty::{
19 self, ClosureArgs, CoroutineArgs, CoroutineClosureArgs, FallibleTypeFolder, InlineConstArgs,
20 Lift, List, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeVisitable, TypeVisitor, VisitorResult,
21 walk_visitable_list,
22};
23
24pub type GenericArgKind<'tcx> = rustc_type_ir::GenericArgKind<TyCtxt<'tcx>>;
25pub type TermKind<'tcx> = rustc_type_ir::TermKind<TyCtxt<'tcx>>;
26
27#[derive(Copy, Clone, PartialEq, Eq, Hash)]
36pub struct GenericArg<'tcx> {
37 ptr: NonNull<()>,
38 marker: PhantomData<(Ty<'tcx>, ty::Region<'tcx>, ty::Const<'tcx>)>,
39}
40
41impl<'tcx> rustc_type_ir::inherent::GenericArg<TyCtxt<'tcx>> for GenericArg<'tcx> {}
42
43impl<'tcx> rustc_type_ir::inherent::GenericArgs<TyCtxt<'tcx>> for ty::GenericArgsRef<'tcx> {
44 fn rebase_onto(
45 self,
46 tcx: TyCtxt<'tcx>,
47 source_ancestor: DefId,
48 target_args: GenericArgsRef<'tcx>,
49 ) -> GenericArgsRef<'tcx> {
50 self.rebase_onto(tcx, source_ancestor, target_args)
51 }
52
53 fn type_at(self, i: usize) -> Ty<'tcx> {
54 self.type_at(i)
55 }
56
57 fn region_at(self, i: usize) -> ty::Region<'tcx> {
58 self.region_at(i)
59 }
60
61 fn const_at(self, i: usize) -> ty::Const<'tcx> {
62 self.const_at(i)
63 }
64
65 fn identity_for_item(tcx: TyCtxt<'tcx>, def_id: DefId) -> ty::GenericArgsRef<'tcx> {
66 GenericArgs::identity_for_item(tcx, def_id)
67 }
68
69 fn extend_with_error(
70 tcx: TyCtxt<'tcx>,
71 def_id: DefId,
72 original_args: &[ty::GenericArg<'tcx>],
73 ) -> ty::GenericArgsRef<'tcx> {
74 ty::GenericArgs::extend_with_error(tcx, def_id, original_args)
75 }
76
77 fn split_closure_args(self) -> ty::ClosureArgsParts<TyCtxt<'tcx>> {
78 match self[..] {
79 [ref parent_args @ .., closure_kind_ty, closure_sig_as_fn_ptr_ty, tupled_upvars_ty] => {
80 ty::ClosureArgsParts {
81 parent_args,
82 closure_kind_ty: closure_kind_ty.expect_ty(),
83 closure_sig_as_fn_ptr_ty: closure_sig_as_fn_ptr_ty.expect_ty(),
84 tupled_upvars_ty: tupled_upvars_ty.expect_ty(),
85 }
86 }
87 _ => bug!("closure args missing synthetics"),
88 }
89 }
90
91 fn split_coroutine_closure_args(self) -> ty::CoroutineClosureArgsParts<TyCtxt<'tcx>> {
92 match self[..] {
93 [
94 ref parent_args @ ..,
95 closure_kind_ty,
96 signature_parts_ty,
97 tupled_upvars_ty,
98 coroutine_captures_by_ref_ty,
99 coroutine_witness_ty,
100 ] => ty::CoroutineClosureArgsParts {
101 parent_args,
102 closure_kind_ty: closure_kind_ty.expect_ty(),
103 signature_parts_ty: signature_parts_ty.expect_ty(),
104 tupled_upvars_ty: tupled_upvars_ty.expect_ty(),
105 coroutine_captures_by_ref_ty: coroutine_captures_by_ref_ty.expect_ty(),
106 coroutine_witness_ty: coroutine_witness_ty.expect_ty(),
107 },
108 _ => bug!("closure args missing synthetics"),
109 }
110 }
111
112 fn split_coroutine_args(self) -> ty::CoroutineArgsParts<TyCtxt<'tcx>> {
113 match self[..] {
114 [
115 ref parent_args @ ..,
116 kind_ty,
117 resume_ty,
118 yield_ty,
119 return_ty,
120 witness,
121 tupled_upvars_ty,
122 ] => ty::CoroutineArgsParts {
123 parent_args,
124 kind_ty: kind_ty.expect_ty(),
125 resume_ty: resume_ty.expect_ty(),
126 yield_ty: yield_ty.expect_ty(),
127 return_ty: return_ty.expect_ty(),
128 witness: witness.expect_ty(),
129 tupled_upvars_ty: tupled_upvars_ty.expect_ty(),
130 },
131 _ => bug!("coroutine args missing synthetics"),
132 }
133 }
134}
135
136impl<'tcx> rustc_type_ir::inherent::IntoKind for GenericArg<'tcx> {
137 type Kind = GenericArgKind<'tcx>;
138
139 fn kind(self) -> Self::Kind {
140 self.kind()
141 }
142}
143
144unsafe impl<'tcx> rustc_data_structures::sync::DynSend for GenericArg<'tcx> where
145 &'tcx (Ty<'tcx>, ty::Region<'tcx>, ty::Const<'tcx>): rustc_data_structures::sync::DynSend
146{
147}
148unsafe impl<'tcx> rustc_data_structures::sync::DynSync for GenericArg<'tcx> where
149 &'tcx (Ty<'tcx>, ty::Region<'tcx>, ty::Const<'tcx>): rustc_data_structures::sync::DynSync
150{
151}
152unsafe impl<'tcx> Send for GenericArg<'tcx> where
153 &'tcx (Ty<'tcx>, ty::Region<'tcx>, ty::Const<'tcx>): Send
154{
155}
156unsafe impl<'tcx> Sync for GenericArg<'tcx> where
157 &'tcx (Ty<'tcx>, ty::Region<'tcx>, ty::Const<'tcx>): Sync
158{
159}
160
161impl<'tcx> IntoDiagArg for GenericArg<'tcx> {
162 fn into_diag_arg(self, _: &mut Option<std::path::PathBuf>) -> DiagArgValue {
163 self.to_string().into_diag_arg(&mut None)
164 }
165}
166
167const TAG_MASK: usize = 0b11;
168const TYPE_TAG: usize = 0b00;
169const REGION_TAG: usize = 0b01;
170const CONST_TAG: usize = 0b10;
171
172#[extension(trait GenericArgPackExt<'tcx>)]
173impl<'tcx> GenericArgKind<'tcx> {
174 #[inline]
175 fn pack(self) -> GenericArg<'tcx> {
176 let (tag, ptr) = match self {
177 GenericArgKind::Lifetime(lt) => {
178 assert_eq!(align_of_val(&*lt.0.0) & TAG_MASK, 0);
180 (REGION_TAG, NonNull::from(lt.0.0).cast())
181 }
182 GenericArgKind::Type(ty) => {
183 assert_eq!(align_of_val(&*ty.0.0) & TAG_MASK, 0);
185 (TYPE_TAG, NonNull::from(ty.0.0).cast())
186 }
187 GenericArgKind::Const(ct) => {
188 assert_eq!(align_of_val(&*ct.0.0) & TAG_MASK, 0);
190 (CONST_TAG, NonNull::from(ct.0.0).cast())
191 }
192 };
193
194 GenericArg { ptr: ptr.map_addr(|addr| addr | tag), marker: PhantomData }
195 }
196}
197
198impl<'tcx> From<ty::Region<'tcx>> for GenericArg<'tcx> {
199 #[inline]
200 fn from(r: ty::Region<'tcx>) -> GenericArg<'tcx> {
201 GenericArgKind::Lifetime(r).pack()
202 }
203}
204
205impl<'tcx> From<Ty<'tcx>> for GenericArg<'tcx> {
206 #[inline]
207 fn from(ty: Ty<'tcx>) -> GenericArg<'tcx> {
208 GenericArgKind::Type(ty).pack()
209 }
210}
211
212impl<'tcx> From<ty::Const<'tcx>> for GenericArg<'tcx> {
213 #[inline]
214 fn from(c: ty::Const<'tcx>) -> GenericArg<'tcx> {
215 GenericArgKind::Const(c).pack()
216 }
217}
218
219impl<'tcx> From<ty::Term<'tcx>> for GenericArg<'tcx> {
220 fn from(value: ty::Term<'tcx>) -> Self {
221 match value.kind() {
222 ty::TermKind::Ty(t) => t.into(),
223 ty::TermKind::Const(c) => c.into(),
224 }
225 }
226}
227
228impl<'tcx> GenericArg<'tcx> {
229 #[inline]
230 pub fn kind(self) -> GenericArgKind<'tcx> {
231 let ptr =
232 unsafe { self.ptr.map_addr(|addr| NonZero::new_unchecked(addr.get() & !TAG_MASK)) };
233 unsafe {
237 match self.ptr.addr().get() & TAG_MASK {
238 REGION_TAG => GenericArgKind::Lifetime(ty::Region(Interned::new_unchecked(
239 ptr.cast::<ty::RegionKind<'tcx>>().as_ref(),
240 ))),
241 TYPE_TAG => GenericArgKind::Type(Ty(Interned::new_unchecked(
242 ptr.cast::<WithCachedTypeInfo<ty::TyKind<'tcx>>>().as_ref(),
243 ))),
244 CONST_TAG => GenericArgKind::Const(ty::Const(Interned::new_unchecked(
245 ptr.cast::<WithCachedTypeInfo<ty::ConstKind<'tcx>>>().as_ref(),
246 ))),
247 _ => intrinsics::unreachable(),
248 }
249 }
250 }
251
252 #[inline]
253 pub fn as_region(self) -> Option<ty::Region<'tcx>> {
254 match self.kind() {
255 GenericArgKind::Lifetime(re) => Some(re),
256 _ => None,
257 }
258 }
259
260 #[inline]
261 pub fn as_type(self) -> Option<Ty<'tcx>> {
262 match self.kind() {
263 GenericArgKind::Type(ty) => Some(ty),
264 _ => None,
265 }
266 }
267
268 #[inline]
269 pub fn as_const(self) -> Option<ty::Const<'tcx>> {
270 match self.kind() {
271 GenericArgKind::Const(ct) => Some(ct),
272 _ => None,
273 }
274 }
275
276 #[inline]
277 pub fn as_term(self) -> Option<ty::Term<'tcx>> {
278 match self.kind() {
279 GenericArgKind::Lifetime(_) => None,
280 GenericArgKind::Type(ty) => Some(ty.into()),
281 GenericArgKind::Const(ct) => Some(ct.into()),
282 }
283 }
284
285 pub fn expect_region(self) -> ty::Region<'tcx> {
287 self.as_region().unwrap_or_else(|| bug!("expected a region, but found another kind"))
288 }
289
290 pub fn expect_ty(self) -> Ty<'tcx> {
294 self.as_type().unwrap_or_else(|| bug!("expected a type, but found another kind"))
295 }
296
297 pub fn expect_const(self) -> ty::Const<'tcx> {
299 self.as_const().unwrap_or_else(|| bug!("expected a const, but found another kind"))
300 }
301
302 pub fn is_non_region_infer(self) -> bool {
303 match self.kind() {
304 GenericArgKind::Lifetime(_) => false,
305 GenericArgKind::Type(ty) => ty.is_ty_or_numeric_infer(),
307 GenericArgKind::Const(ct) => ct.is_ct_infer(),
308 }
309 }
310
311 pub fn walk(self) -> TypeWalker<TyCtxt<'tcx>> {
322 TypeWalker::new(self)
323 }
324}
325
326impl<'a, 'tcx> Lift<TyCtxt<'tcx>> for GenericArg<'a> {
327 type Lifted = GenericArg<'tcx>;
328
329 fn lift_to_interner(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
330 match self.kind() {
331 GenericArgKind::Lifetime(lt) => tcx.lift(lt).map(|lt| lt.into()),
332 GenericArgKind::Type(ty) => tcx.lift(ty).map(|ty| ty.into()),
333 GenericArgKind::Const(ct) => tcx.lift(ct).map(|ct| ct.into()),
334 }
335 }
336}
337
338impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for GenericArg<'tcx> {
339 fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>(
340 self,
341 folder: &mut F,
342 ) -> Result<Self, F::Error> {
343 match self.kind() {
344 GenericArgKind::Lifetime(lt) => lt.try_fold_with(folder).map(Into::into),
345 GenericArgKind::Type(ty) => ty.try_fold_with(folder).map(Into::into),
346 GenericArgKind::Const(ct) => ct.try_fold_with(folder).map(Into::into),
347 }
348 }
349
350 fn fold_with<F: TypeFolder<TyCtxt<'tcx>>>(self, folder: &mut F) -> Self {
351 match self.kind() {
352 GenericArgKind::Lifetime(lt) => lt.fold_with(folder).into(),
353 GenericArgKind::Type(ty) => ty.fold_with(folder).into(),
354 GenericArgKind::Const(ct) => ct.fold_with(folder).into(),
355 }
356 }
357}
358
359impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for GenericArg<'tcx> {
360 fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> V::Result {
361 match self.kind() {
362 GenericArgKind::Lifetime(lt) => lt.visit_with(visitor),
363 GenericArgKind::Type(ty) => ty.visit_with(visitor),
364 GenericArgKind::Const(ct) => ct.visit_with(visitor),
365 }
366 }
367}
368
369impl<'tcx, E: TyEncoder<'tcx>> Encodable<E> for GenericArg<'tcx> {
370 fn encode(&self, e: &mut E) {
371 self.kind().encode(e)
372 }
373}
374
375impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for GenericArg<'tcx> {
376 fn decode(d: &mut D) -> GenericArg<'tcx> {
377 GenericArgKind::decode(d).pack()
378 }
379}
380
381pub type GenericArgs<'tcx> = List<GenericArg<'tcx>>;
383
384pub type GenericArgsRef<'tcx> = &'tcx GenericArgs<'tcx>;
385
386impl<'tcx> GenericArgs<'tcx> {
387 pub fn into_type_list(&self, tcx: TyCtxt<'tcx>) -> &'tcx List<Ty<'tcx>> {
393 tcx.mk_type_list_from_iter(self.iter().map(|arg| match arg.kind() {
394 GenericArgKind::Type(ty) => ty,
395 _ => bug!("`into_type_list` called on generic arg with non-types"),
396 }))
397 }
398
399 pub fn as_closure(&'tcx self) -> ClosureArgs<TyCtxt<'tcx>> {
404 ClosureArgs { args: self }
405 }
406
407 pub fn as_coroutine_closure(&'tcx self) -> CoroutineClosureArgs<TyCtxt<'tcx>> {
412 CoroutineClosureArgs { args: self }
413 }
414
415 pub fn as_coroutine(&'tcx self) -> CoroutineArgs<TyCtxt<'tcx>> {
420 CoroutineArgs { args: self }
421 }
422
423 pub fn as_inline_const(&'tcx self) -> InlineConstArgs<'tcx> {
428 InlineConstArgs { args: self }
429 }
430
431 pub fn identity_for_item(tcx: TyCtxt<'tcx>, def_id: impl Into<DefId>) -> GenericArgsRef<'tcx> {
433 Self::for_item(tcx, def_id.into(), |param, _| tcx.mk_param_from_def(param))
434 }
435
436 pub fn for_item<F>(tcx: TyCtxt<'tcx>, def_id: DefId, mut mk_kind: F) -> GenericArgsRef<'tcx>
442 where
443 F: FnMut(&ty::GenericParamDef, &[GenericArg<'tcx>]) -> GenericArg<'tcx>,
444 {
445 let defs = tcx.generics_of(def_id);
446 let count = defs.count();
447 let mut args = SmallVec::with_capacity(count);
448 Self::fill_item(&mut args, tcx, defs, &mut mk_kind);
449 tcx.mk_args(&args)
450 }
451
452 pub fn extend_to<F>(
453 &self,
454 tcx: TyCtxt<'tcx>,
455 def_id: DefId,
456 mut mk_kind: F,
457 ) -> GenericArgsRef<'tcx>
458 where
459 F: FnMut(&ty::GenericParamDef, &[GenericArg<'tcx>]) -> GenericArg<'tcx>,
460 {
461 Self::for_item(tcx, def_id, |param, args| {
462 self.get(param.index as usize).cloned().unwrap_or_else(|| mk_kind(param, args))
463 })
464 }
465
466 pub fn fill_item<F>(
467 args: &mut SmallVec<[GenericArg<'tcx>; 8]>,
468 tcx: TyCtxt<'tcx>,
469 defs: &ty::Generics,
470 mk_kind: &mut F,
471 ) where
472 F: FnMut(&ty::GenericParamDef, &[GenericArg<'tcx>]) -> GenericArg<'tcx>,
473 {
474 if let Some(def_id) = defs.parent {
475 let parent_defs = tcx.generics_of(def_id);
476 Self::fill_item(args, tcx, parent_defs, mk_kind);
477 }
478 Self::fill_single(args, defs, mk_kind)
479 }
480
481 pub fn fill_single<F>(
482 args: &mut SmallVec<[GenericArg<'tcx>; 8]>,
483 defs: &ty::Generics,
484 mk_kind: &mut F,
485 ) where
486 F: FnMut(&ty::GenericParamDef, &[GenericArg<'tcx>]) -> GenericArg<'tcx>,
487 {
488 args.reserve(defs.own_params.len());
489 for param in &defs.own_params {
490 let kind = mk_kind(param, args);
491 assert_eq!(param.index as usize, args.len(), "{args:#?}, {defs:#?}");
492 args.push(kind);
493 }
494 }
495
496 pub fn extend_with_error(
499 tcx: TyCtxt<'tcx>,
500 def_id: DefId,
501 original_args: &[GenericArg<'tcx>],
502 ) -> GenericArgsRef<'tcx> {
503 ty::GenericArgs::for_item(tcx, def_id, |def, _| {
504 if let Some(arg) = original_args.get(def.index as usize) {
505 *arg
506 } else {
507 def.to_error(tcx)
508 }
509 })
510 }
511
512 #[inline]
513 pub fn types(&self) -> impl DoubleEndedIterator<Item = Ty<'tcx>> {
514 self.iter().filter_map(|k| k.as_type())
515 }
516
517 #[inline]
518 pub fn regions(&self) -> impl DoubleEndedIterator<Item = ty::Region<'tcx>> {
519 self.iter().filter_map(|k| k.as_region())
520 }
521
522 #[inline]
523 pub fn consts(&self) -> impl DoubleEndedIterator<Item = ty::Const<'tcx>> {
524 self.iter().filter_map(|k| k.as_const())
525 }
526
527 #[inline]
529 pub fn non_erasable_generics(&self) -> impl DoubleEndedIterator<Item = GenericArgKind<'tcx>> {
530 self.iter().filter_map(|arg| match arg.kind() {
531 ty::GenericArgKind::Lifetime(_) => None,
532 generic => Some(generic),
533 })
534 }
535
536 #[inline]
537 #[track_caller]
538 pub fn type_at(&self, i: usize) -> Ty<'tcx> {
539 self[i].as_type().unwrap_or_else(|| bug!("expected type for param #{} in {:?}", i, self))
540 }
541
542 #[inline]
543 #[track_caller]
544 pub fn region_at(&self, i: usize) -> ty::Region<'tcx> {
545 self[i]
546 .as_region()
547 .unwrap_or_else(|| bug!("expected region for param #{} in {:?}", i, self))
548 }
549
550 #[inline]
551 #[track_caller]
552 pub fn const_at(&self, i: usize) -> ty::Const<'tcx> {
553 self[i].as_const().unwrap_or_else(|| bug!("expected const for param #{} in {:?}", i, self))
554 }
555
556 #[inline]
557 #[track_caller]
558 pub fn type_for_def(&self, def: &ty::GenericParamDef) -> GenericArg<'tcx> {
559 self.type_at(def.index as usize).into()
560 }
561
562 pub fn rebase_onto(
581 &self,
582 tcx: TyCtxt<'tcx>,
583 source_ancestor: DefId,
584 target_args: GenericArgsRef<'tcx>,
585 ) -> GenericArgsRef<'tcx> {
586 let defs = tcx.generics_of(source_ancestor);
587 tcx.mk_args_from_iter(target_args.iter().chain(self.iter().skip(defs.count())))
588 }
589
590 pub fn truncate_to(&self, tcx: TyCtxt<'tcx>, generics: &ty::Generics) -> GenericArgsRef<'tcx> {
591 tcx.mk_args_from_iter(self.iter().take(generics.count()))
592 }
593
594 pub fn print_as_list(&self) -> String {
595 let v = self.iter().map(|arg| arg.to_string()).collect::<Vec<_>>();
596 format!("[{}]", v.join(", "))
597 }
598}
599
600impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for GenericArgsRef<'tcx> {
601 fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>(
602 self,
603 folder: &mut F,
604 ) -> Result<Self, F::Error> {
605 match self.len() {
612 1 => {
613 let param0 = self[0].try_fold_with(folder)?;
614 if param0 == self[0] { Ok(self) } else { Ok(folder.cx().mk_args(&[param0])) }
615 }
616 2 => {
617 let param0 = self[0].try_fold_with(folder)?;
618 let param1 = self[1].try_fold_with(folder)?;
619 if param0 == self[0] && param1 == self[1] {
620 Ok(self)
621 } else {
622 Ok(folder.cx().mk_args(&[param0, param1]))
623 }
624 }
625 0 => Ok(self),
626 _ => ty::util::try_fold_list(self, folder, |tcx, v| tcx.mk_args(v)),
627 }
628 }
629
630 fn fold_with<F: TypeFolder<TyCtxt<'tcx>>>(self, folder: &mut F) -> Self {
631 match self.len() {
633 1 => {
634 let param0 = self[0].fold_with(folder);
635 if param0 == self[0] { self } else { folder.cx().mk_args(&[param0]) }
636 }
637 2 => {
638 let param0 = self[0].fold_with(folder);
639 let param1 = self[1].fold_with(folder);
640 if param0 == self[0] && param1 == self[1] {
641 self
642 } else {
643 folder.cx().mk_args(&[param0, param1])
644 }
645 }
646 0 => self,
647 _ => ty::util::fold_list(self, folder, |tcx, v| tcx.mk_args(v)),
648 }
649 }
650}
651
652impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for &'tcx ty::List<Ty<'tcx>> {
653 fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>(
654 self,
655 folder: &mut F,
656 ) -> Result<Self, F::Error> {
657 match self.len() {
673 2 => {
674 let param0 = self[0].try_fold_with(folder)?;
675 let param1 = self[1].try_fold_with(folder)?;
676 if param0 == self[0] && param1 == self[1] {
677 Ok(self)
678 } else {
679 Ok(folder.cx().mk_type_list(&[param0, param1]))
680 }
681 }
682 _ => ty::util::try_fold_list(self, folder, |tcx, v| tcx.mk_type_list(v)),
683 }
684 }
685
686 fn fold_with<F: TypeFolder<TyCtxt<'tcx>>>(self, folder: &mut F) -> Self {
687 match self.len() {
689 2 => {
690 let param0 = self[0].fold_with(folder);
691 let param1 = self[1].fold_with(folder);
692 if param0 == self[0] && param1 == self[1] {
693 self
694 } else {
695 folder.cx().mk_type_list(&[param0, param1])
696 }
697 }
698 _ => ty::util::fold_list(self, folder, |tcx, v| tcx.mk_type_list(v)),
699 }
700 }
701}
702
703impl<'tcx, T: TypeVisitable<TyCtxt<'tcx>>> TypeVisitable<TyCtxt<'tcx>> for &'tcx ty::List<T> {
704 #[inline]
705 fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> V::Result {
706 walk_visitable_list!(visitor, self.iter());
707 V::Result::output()
708 }
709}
710
711#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, TyEncodable, TyDecodable)]
714#[derive(HashStable, TypeFoldable, TypeVisitable)]
715pub struct UserArgs<'tcx> {
716 pub args: GenericArgsRef<'tcx>,
718
719 pub user_self_ty: Option<UserSelfTy<'tcx>>,
722}
723
724#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, TyEncodable, TyDecodable)]
741#[derive(HashStable, TypeFoldable, TypeVisitable)]
742pub struct UserSelfTy<'tcx> {
743 pub impl_def_id: DefId,
744 pub self_ty: Ty<'tcx>,
745}