diff options
| author | Felix S. Klock II <pnkfelix@pnkfx.org> | 2018-10-26 13:32:45 +0200 |
|---|---|---|
| committer | Felix S. Klock II <pnkfelix@pnkfx.org> | 2018-10-26 23:47:53 +0200 |
| commit | 82ab668a556abc1843e10bb0da2a307d2442e1e2 (patch) | |
| tree | fa4abac9ebcb0cdbb8b64ed12790eb4cc275208e /src | |
| parent | 47e2d825e1615813d9b5b3b97e20cfe169f5097f (diff) | |
| download | rust-82ab668a556abc1843e10bb0da2a307d2442e1e2.tar.gz rust-82ab668a556abc1843e10bb0da2a307d2442e1e2.zip | |
Further foundational stuff on `ProjectionKind` before I add it to `AscribeUserType`.
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc/ty/context.rs | 18 | ||||
| -rw-r--r-- | src/librustc/ty/structural_impls.rs | 12 |
2 files changed, 30 insertions, 0 deletions
diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 1e3b372c029..d4b47db6081 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -1888,6 +1888,24 @@ impl<'a, 'tcx> Lift<'tcx> for &'a List<CanonicalVarInfo> { } } +impl<'a, 'tcx> Lift<'tcx> for &'a List<ProjectionKind<'a>> { + type Lifted = &'tcx List<ProjectionKind<'tcx>>; + fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> { + if self.len() == 0 { + return Some(List::empty()); + } + if tcx.interners.arena.in_arena(*self as *const _) { + return Some(unsafe { mem::transmute(*self) }); + } + // Also try in the global tcx if we're not that. + if !tcx.is_global() { + self.lift_to_tcx(tcx.global_tcx()) + } else { + None + } + } +} + pub mod tls { use super::{GlobalCtxt, TyCtxt}; diff --git a/src/librustc/ty/structural_impls.rs b/src/librustc/ty/structural_impls.rs index a93dca4af42..62827ea20c3 100644 --- a/src/librustc/ty/structural_impls.rs +++ b/src/librustc/ty/structural_impls.rs @@ -13,6 +13,7 @@ //! hand, though we've recently added some macros (e.g., //! `BraceStructLiftImpl!`) to help with the tedium. +use mir::ProjectionKind; use mir::interpret::ConstValue; use ty::{self, Lift, Ty, TyCtxt}; use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor}; @@ -628,6 +629,17 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<Ty<'tcx>> { } } +impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ProjectionKind<'tcx>> { + fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { + let v = self.iter().map(|t| t.fold_with(folder)).collect::<SmallVec<[_; 8]>>(); + folder.tcx().intern_projs(&v) + } + + fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool { + self.iter().any(|t| t.visit_with(visitor)) + } +} + impl<'tcx> TypeFoldable<'tcx> for ty::instance::Instance<'tcx> { fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { use ty::InstanceDef::*; |
