1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
use crate::mir;
use crate::ty::codec::{TyDecoder, TyEncoder};
use crate::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeFolder, TypeSuperFoldable};
use crate::ty::sty::{ClosureSubsts, GeneratorSubsts, InlineConstSubsts};
use crate::ty::visit::{TypeVisitable, TypeVisitor};
use crate::ty::{self, Lift, List, ParamConst, Ty, TyCtxt};
use rustc_data_structures::intern::{Interned, WithStableHash};
use rustc_hir::def_id::DefId;
use rustc_macros::HashStable;
use rustc_serialize::{self, Decodable, Encodable};
use smallvec::SmallVec;
use core::intrinsics;
use std::cmp::Ordering;
use std::fmt;
use std::marker::PhantomData;
use std::mem;
use std::num::NonZeroUsize;
use std::ops::ControlFlow;
use std::slice;
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
pub struct GenericArg<'tcx> {
ptr: NonZeroUsize,
marker: PhantomData<(Ty<'tcx>, ty::Region<'tcx>, ty::Const<'tcx>)>,
}
const TAG_MASK: usize = 0b11;
const TYPE_TAG: usize = 0b00;
const REGION_TAG: usize = 0b01;
const CONST_TAG: usize = 0b10;
#[derive(Debug, TyEncodable, TyDecodable, PartialEq, Eq, PartialOrd, Ord)]
pub enum GenericArgKind<'tcx> {
Lifetime(ty::Region<'tcx>),
Type(Ty<'tcx>),
Const(ty::Const<'tcx>),
}
pub fn ty_slice_as_generic_args<'a, 'tcx>(ts: &'a [Ty<'tcx>]) -> &'a [GenericArg<'tcx>] {
assert_eq!(TYPE_TAG, 0);
unsafe { slice::from_raw_parts(ts.as_ptr().cast(), ts.len()) }
}
impl<'tcx> List<Ty<'tcx>> {
#[inline]
pub fn as_substs(&'tcx self) -> SubstsRef<'tcx> {
assert_eq!(TYPE_TAG, 0);
unsafe { &*(self as *const List<Ty<'tcx>> as *const List<GenericArg<'tcx>>) }
}
}
impl<'tcx> GenericArgKind<'tcx> {
#[inline]
fn pack(self) -> GenericArg<'tcx> {
let (tag, ptr) = match self {
GenericArgKind::Lifetime(lt) => {
assert_eq!(mem::align_of_val(&*lt.0.0) & TAG_MASK, 0);
(REGION_TAG, lt.0.0 as *const ty::RegionKind<'tcx> as usize)
}
GenericArgKind::Type(ty) => {
assert_eq!(mem::align_of_val(&*ty.0.0) & TAG_MASK, 0);
(TYPE_TAG, ty.0.0 as *const WithStableHash<ty::TyS<'tcx>> as usize)
}
GenericArgKind::Const(ct) => {
assert_eq!(mem::align_of_val(&*ct.0.0) & TAG_MASK, 0);
(CONST_TAG, ct.0.0 as *const ty::ConstS<'tcx> as usize)
}
};
GenericArg { ptr: unsafe { NonZeroUsize::new_unchecked(ptr | tag) }, marker: PhantomData }
}
}
impl<'tcx> fmt::Debug for GenericArg<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.unpack() {
GenericArgKind::Lifetime(lt) => lt.fmt(f),
GenericArgKind::Type(ty) => ty.fmt(f),
GenericArgKind::Const(ct) => ct.fmt(f),
}
}
}
impl<'tcx> Ord for GenericArg<'tcx> {
fn cmp(&self, other: &GenericArg<'tcx>) -> Ordering {
self.unpack().cmp(&other.unpack())
}
}
impl<'tcx> PartialOrd for GenericArg<'tcx> {
fn partial_cmp(&self, other: &GenericArg<'tcx>) -> Option<Ordering> {
Some(self.cmp(&other))
}
}
impl<'tcx> From<ty::Region<'tcx>> for GenericArg<'tcx> {
#[inline]
fn from(r: ty::Region<'tcx>) -> GenericArg<'tcx> {
GenericArgKind::Lifetime(r).pack()
}
}
impl<'tcx> From<Ty<'tcx>> for GenericArg<'tcx> {
#[inline]
fn from(ty: Ty<'tcx>) -> GenericArg<'tcx> {
GenericArgKind::Type(ty).pack()
}
}
impl<'tcx> From<ty::Const<'tcx>> for GenericArg<'tcx> {
#[inline]
fn from(c: ty::Const<'tcx>) -> GenericArg<'tcx> {
GenericArgKind::Const(c).pack()
}
}
impl<'tcx> GenericArg<'tcx> {
#[inline]
pub fn unpack(self) -> GenericArgKind<'tcx> {
let ptr = self.ptr.get();
unsafe {
match ptr & TAG_MASK {
REGION_TAG => GenericArgKind::Lifetime(ty::Region(Interned::new_unchecked(
&*((ptr & !TAG_MASK) as *const ty::RegionKind<'tcx>),
))),
TYPE_TAG => GenericArgKind::Type(Ty(Interned::new_unchecked(
&*((ptr & !TAG_MASK) as *const WithStableHash<ty::TyS<'tcx>>),
))),
CONST_TAG => GenericArgKind::Const(ty::Const(Interned::new_unchecked(
&*((ptr & !TAG_MASK) as *const ty::ConstS<'tcx>),
))),
_ => intrinsics::unreachable(),
}
}
}
pub fn expect_region(self) -> ty::Region<'tcx> {
match self.unpack() {
GenericArgKind::Lifetime(lt) => lt,
_ => bug!("expected a region, but found another kind"),
}
}
pub fn expect_ty(self) -> Ty<'tcx> {
match self.unpack() {
GenericArgKind::Type(ty) => ty,
_ => bug!("expected a type, but found another kind"),
}
}
pub fn expect_const(self) -> ty::Const<'tcx> {
match self.unpack() {
GenericArgKind::Const(c) => c,
_ => bug!("expected a const, but found another kind"),
}
}
}
impl<'a, 'tcx> Lift<'tcx> for GenericArg<'a> {
type Lifted = GenericArg<'tcx>;
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
match self.unpack() {
GenericArgKind::Lifetime(lt) => tcx.lift(lt).map(|lt| lt.into()),
GenericArgKind::Type(ty) => tcx.lift(ty).map(|ty| ty.into()),
GenericArgKind::Const(ct) => tcx.lift(ct).map(|ct| ct.into()),
}
}
}
impl<'tcx> TypeFoldable<'tcx> for GenericArg<'tcx> {
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
match self.unpack() {
GenericArgKind::Lifetime(lt) => lt.try_fold_with(folder).map(Into::into),
GenericArgKind::Type(ty) => ty.try_fold_with(folder).map(Into::into),
GenericArgKind::Const(ct) => ct.try_fold_with(folder).map(Into::into),
}
}
}
impl<'tcx> TypeVisitable<'tcx> for GenericArg<'tcx> {
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
match self.unpack() {
GenericArgKind::Lifetime(lt) => lt.visit_with(visitor),
GenericArgKind::Type(ty) => ty.visit_with(visitor),
GenericArgKind::Const(ct) => ct.visit_with(visitor),
}
}
}
impl<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>> Encodable<E> for GenericArg<'tcx> {
fn encode(&self, e: &mut E) {
self.unpack().encode(e)
}
}
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for GenericArg<'tcx> {
fn decode(d: &mut D) -> GenericArg<'tcx> {
GenericArgKind::decode(d).pack()
}
}
pub type InternalSubsts<'tcx> = List<GenericArg<'tcx>>;
pub type SubstsRef<'tcx> = &'tcx InternalSubsts<'tcx>;
impl<'tcx> InternalSubsts<'tcx> {
pub fn try_as_type_list(&'tcx self) -> Option<&'tcx List<Ty<'tcx>>> {
if self.iter().all(|arg| matches!(arg.unpack(), GenericArgKind::Type(_))) {
assert_eq!(TYPE_TAG, 0);
Some(unsafe { &*(self as *const List<GenericArg<'tcx>> as *const List<Ty<'tcx>>) })
} else {
None
}
}
pub fn as_closure(&'tcx self) -> ClosureSubsts<'tcx> {
ClosureSubsts { substs: self }
}
pub fn as_generator(&'tcx self) -> GeneratorSubsts<'tcx> {
GeneratorSubsts { substs: self }
}
pub fn as_inline_const(&'tcx self) -> InlineConstSubsts<'tcx> {
InlineConstSubsts { substs: self }
}
pub fn identity_for_item(tcx: TyCtxt<'tcx>, def_id: DefId) -> SubstsRef<'tcx> {
Self::for_item(tcx, def_id, |param, _| tcx.mk_param_from_def(param))
}
pub fn for_item<F>(tcx: TyCtxt<'tcx>, def_id: DefId, mut mk_kind: F) -> SubstsRef<'tcx>
where
F: FnMut(&ty::GenericParamDef, &[GenericArg<'tcx>]) -> GenericArg<'tcx>,
{
let defs = tcx.generics_of(def_id);
let count = defs.count();
let mut substs = SmallVec::with_capacity(count);
Self::fill_item(&mut substs, tcx, defs, &mut mk_kind);
tcx.intern_substs(&substs)
}
pub fn extend_to<F>(&self, tcx: TyCtxt<'tcx>, def_id: DefId, mut mk_kind: F) -> SubstsRef<'tcx>
where
F: FnMut(&ty::GenericParamDef, &[GenericArg<'tcx>]) -> GenericArg<'tcx>,
{
Self::for_item(tcx, def_id, |param, substs| {
self.get(param.index as usize).cloned().unwrap_or_else(|| mk_kind(param, substs))
})
}
pub fn fill_item<F>(
substs: &mut SmallVec<[GenericArg<'tcx>; 8]>,
tcx: TyCtxt<'tcx>,
defs: &ty::Generics,
mk_kind: &mut F,
) where
F: FnMut(&ty::GenericParamDef, &[GenericArg<'tcx>]) -> GenericArg<'tcx>,
{
if let Some(def_id) = defs.parent {
let parent_defs = tcx.generics_of(def_id);
Self::fill_item(substs, tcx, parent_defs, mk_kind);
}
Self::fill_single(substs, defs, mk_kind)
}
pub fn fill_single<F>(
substs: &mut SmallVec<[GenericArg<'tcx>; 8]>,
defs: &ty::Generics,
mk_kind: &mut F,
) where
F: FnMut(&ty::GenericParamDef, &[GenericArg<'tcx>]) -> GenericArg<'tcx>,
{
substs.reserve(defs.params.len());
for param in &defs.params {
let kind = mk_kind(param, substs);
assert_eq!(param.index as usize, substs.len());
substs.push(kind);
}
}
#[inline]
pub fn types(&'tcx self) -> impl DoubleEndedIterator<Item = Ty<'tcx>> + 'tcx {
self.iter()
.filter_map(|k| if let GenericArgKind::Type(ty) = k.unpack() { Some(ty) } else { None })
}
#[inline]
pub fn regions(&'tcx self) -> impl DoubleEndedIterator<Item = ty::Region<'tcx>> + 'tcx {
self.iter().filter_map(|k| {
if let GenericArgKind::Lifetime(lt) = k.unpack() { Some(lt) } else { None }
})
}
#[inline]
pub fn consts(&'tcx self) -> impl DoubleEndedIterator<Item = ty::Const<'tcx>> + 'tcx {
self.iter().filter_map(|k| {
if let GenericArgKind::Const(ct) = k.unpack() { Some(ct) } else { None }
})
}
#[inline]
pub fn non_erasable_generics(
&'tcx self,
) -> impl DoubleEndedIterator<Item = GenericArgKind<'tcx>> + 'tcx {
self.iter().filter_map(|k| match k.unpack() {
GenericArgKind::Lifetime(_) => None,
generic => Some(generic),
})
}
#[inline]
pub fn type_at(&self, i: usize) -> Ty<'tcx> {
if let GenericArgKind::Type(ty) = self[i].unpack() {
ty
} else {
bug!("expected type for param #{} in {:?}", i, self);
}
}
#[inline]
pub fn region_at(&self, i: usize) -> ty::Region<'tcx> {
if let GenericArgKind::Lifetime(lt) = self[i].unpack() {
lt
} else {
bug!("expected region for param #{} in {:?}", i, self);
}
}
#[inline]
pub fn const_at(&self, i: usize) -> ty::Const<'tcx> {
if let GenericArgKind::Const(ct) = self[i].unpack() {
ct
} else {
bug!("expected const for param #{} in {:?}", i, self);
}
}
#[inline]
pub fn type_for_def(&self, def: &ty::GenericParamDef) -> GenericArg<'tcx> {
self.type_at(def.index as usize).into()
}
pub fn rebase_onto(
&self,
tcx: TyCtxt<'tcx>,
source_ancestor: DefId,
target_substs: SubstsRef<'tcx>,
) -> SubstsRef<'tcx> {
let defs = tcx.generics_of(source_ancestor);
tcx.mk_substs(target_substs.iter().chain(self.iter().skip(defs.params.len())))
}
pub fn truncate_to(&self, tcx: TyCtxt<'tcx>, generics: &ty::Generics) -> SubstsRef<'tcx> {
tcx.mk_substs(self.iter().take(generics.count()))
}
}
impl<'tcx> TypeFoldable<'tcx> for SubstsRef<'tcx> {
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
match self.len() {
1 => {
let param0 = self[0].try_fold_with(folder)?;
if param0 == self[0] { Ok(self) } else { Ok(folder.tcx().intern_substs(&[param0])) }
}
2 => {
let param0 = self[0].try_fold_with(folder)?;
let param1 = self[1].try_fold_with(folder)?;
if param0 == self[0] && param1 == self[1] {
Ok(self)
} else {
Ok(folder.tcx().intern_substs(&[param0, param1]))
}
}
0 => Ok(self),
_ => ty::util::fold_list(self, folder, |tcx, v| tcx.intern_substs(v)),
}
}
}
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<Ty<'tcx>> {
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
match self.len() {
2 => {
let param0 = self[0].try_fold_with(folder)?;
let param1 = self[1].try_fold_with(folder)?;
if param0 == self[0] && param1 == self[1] {
Ok(self)
} else {
Ok(folder.tcx().intern_type_list(&[param0, param1]))
}
}
_ => ty::util::fold_list(self, folder, |tcx, v| tcx.intern_type_list(v)),
}
}
}
impl<'tcx, T: TypeVisitable<'tcx>> TypeVisitable<'tcx> for &'tcx ty::List<T> {
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
self.iter().try_for_each(|t| t.visit_with(visitor))
}
}
#[rustc_on_unimplemented(message = "Calling `subst` must now be done through an `EarlyBinder`")]
pub trait Subst<'tcx>: Sized {
type Inner;
fn subst(self, tcx: TyCtxt<'tcx>, substs: &[GenericArg<'tcx>]) -> Self::Inner;
}
impl<'tcx, T: TypeFoldable<'tcx>> Subst<'tcx> for ty::EarlyBinder<T> {
type Inner = T;
fn subst(self, tcx: TyCtxt<'tcx>, substs: &[GenericArg<'tcx>]) -> Self::Inner {
let mut folder = SubstFolder { tcx, substs, binders_passed: 0 };
self.0.fold_with(&mut folder)
}
}
struct SubstFolder<'a, 'tcx> {
tcx: TyCtxt<'tcx>,
substs: &'a [GenericArg<'tcx>],
binders_passed: u32,
}
impl<'a, 'tcx> TypeFolder<'tcx> for SubstFolder<'a, 'tcx> {
#[inline]
fn tcx<'b>(&'b self) -> TyCtxt<'tcx> {
self.tcx
}
fn fold_binder<T: TypeFoldable<'tcx>>(
&mut self,
t: ty::Binder<'tcx, T>,
) -> ty::Binder<'tcx, T> {
self.binders_passed += 1;
let t = t.super_fold_with(self);
self.binders_passed -= 1;
t
}
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
#[cold]
#[inline(never)]
fn region_param_out_of_range(data: ty::EarlyBoundRegion) -> ! {
bug!(
"Region parameter out of range when substituting in region {} (index={})",
data.name,
data.index
)
}
match *r {
ty::ReEarlyBound(data) => {
let rk = self.substs.get(data.index as usize).map(|k| k.unpack());
match rk {
Some(GenericArgKind::Lifetime(lt)) => self.shift_region_through_binders(lt),
_ => region_param_out_of_range(data),
}
}
_ => r,
}
}
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
if !t.needs_subst() {
return t;
}
match *t.kind() {
ty::Param(p) => self.ty_for_param(p, t),
_ => t.super_fold_with(self),
}
}
fn fold_const(&mut self, c: ty::Const<'tcx>) -> ty::Const<'tcx> {
if let ty::ConstKind::Param(p) = c.kind() {
self.const_for_param(p, c)
} else {
c.super_fold_with(self)
}
}
#[inline]
fn fold_mir_const(&mut self, c: mir::ConstantKind<'tcx>) -> mir::ConstantKind<'tcx> {
c.super_fold_with(self)
}
}
impl<'a, 'tcx> SubstFolder<'a, 'tcx> {
fn ty_for_param(&self, p: ty::ParamTy, source_ty: Ty<'tcx>) -> Ty<'tcx> {
let opt_ty = self.substs.get(p.index as usize).map(|k| k.unpack());
let ty = match opt_ty {
Some(GenericArgKind::Type(ty)) => ty,
Some(kind) => self.type_param_expected(p, source_ty, kind),
None => self.type_param_out_of_range(p, source_ty),
};
self.shift_vars_through_binders(ty)
}
#[cold]
#[inline(never)]
fn type_param_expected(&self, p: ty::ParamTy, ty: Ty<'tcx>, kind: GenericArgKind<'tcx>) -> ! {
bug!(
"expected type for `{:?}` ({:?}/{}) but found {:?} when substituting, substs={:?}",
p,
ty,
p.index,
kind,
self.substs,
)
}
#[cold]
#[inline(never)]
fn type_param_out_of_range(&self, p: ty::ParamTy, ty: Ty<'tcx>) -> ! {
bug!(
"type parameter `{:?}` ({:?}/{}) out of range when substituting, substs={:?}",
p,
ty,
p.index,
self.substs,
)
}
fn const_for_param(&self, p: ParamConst, source_ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
let opt_ct = self.substs.get(p.index as usize).map(|k| k.unpack());
let ct = match opt_ct {
Some(GenericArgKind::Const(ct)) => ct,
Some(kind) => self.const_param_expected(p, source_ct, kind),
None => self.const_param_out_of_range(p, source_ct),
};
self.shift_vars_through_binders(ct)
}
#[cold]
#[inline(never)]
fn const_param_expected(
&self,
p: ty::ParamConst,
ct: ty::Const<'tcx>,
kind: GenericArgKind<'tcx>,
) -> ! {
bug!(
"expected const for `{:?}` ({:?}/{}) but found {:?} when substituting substs={:?}",
p,
ct,
p.index,
kind,
self.substs,
)
}
#[cold]
#[inline(never)]
fn const_param_out_of_range(&self, p: ty::ParamConst, ct: ty::Const<'tcx>) -> ! {
bug!(
"const parameter `{:?}` ({:?}/{}) out of range when substituting substs={:?}",
p,
ct,
p.index,
self.substs,
)
}
fn shift_vars_through_binders<T: TypeFoldable<'tcx>>(&self, val: T) -> T {
debug!(
"shift_vars(val={:?}, binders_passed={:?}, has_escaping_bound_vars={:?})",
val,
self.binders_passed,
val.has_escaping_bound_vars()
);
if self.binders_passed == 0 || !val.has_escaping_bound_vars() {
return val;
}
let result = ty::fold::shift_vars(TypeFolder::tcx(self), val, self.binders_passed);
debug!("shift_vars: shifted result = {:?}", result);
result
}
fn shift_region_through_binders(&self, region: ty::Region<'tcx>) -> ty::Region<'tcx> {
if self.binders_passed == 0 || !region.has_escaping_bound_vars() {
return region;
}
ty::fold::shift_region(self.tcx, region, self.binders_passed)
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, TyEncodable, TyDecodable)]
#[derive(HashStable, TypeFoldable, TypeVisitable, Lift)]
pub struct UserSubsts<'tcx> {
pub substs: SubstsRef<'tcx>,
pub user_self_ty: Option<UserSelfTy<'tcx>>,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, TyEncodable, TyDecodable)]
#[derive(HashStable, TypeFoldable, TypeVisitable, Lift)]
pub struct UserSelfTy<'tcx> {
pub impl_def_id: DefId,
pub self_ty: Ty<'tcx>,
}