Skip to content

Commit 82ab668

Browse files
committed
Further foundational stuff on ProjectionKind before I add it to AscribeUserType.
1 parent 47e2d82 commit 82ab668

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/librustc/ty/context.rs

+18
Original file line numberDiff line numberDiff line change
@@ -1888,6 +1888,24 @@ impl<'a, 'tcx> Lift<'tcx> for &'a List<CanonicalVarInfo> {
18881888
}
18891889
}
18901890

1891+
impl<'a, 'tcx> Lift<'tcx> for &'a List<ProjectionKind<'a>> {
1892+
type Lifted = &'tcx List<ProjectionKind<'tcx>>;
1893+
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
1894+
if self.len() == 0 {
1895+
return Some(List::empty());
1896+
}
1897+
if tcx.interners.arena.in_arena(*self as *const _) {
1898+
return Some(unsafe { mem::transmute(*self) });
1899+
}
1900+
// Also try in the global tcx if we're not that.
1901+
if !tcx.is_global() {
1902+
self.lift_to_tcx(tcx.global_tcx())
1903+
} else {
1904+
None
1905+
}
1906+
}
1907+
}
1908+
18911909
pub mod tls {
18921910
use super::{GlobalCtxt, TyCtxt};
18931911

src/librustc/ty/structural_impls.rs

+12
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
//! hand, though we've recently added some macros (e.g.,
1414
//! `BraceStructLiftImpl!`) to help with the tedium.
1515
16+
use mir::ProjectionKind;
1617
use mir::interpret::ConstValue;
1718
use ty::{self, Lift, Ty, TyCtxt};
1819
use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
@@ -628,6 +629,17 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<Ty<'tcx>> {
628629
}
629630
}
630631

632+
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ProjectionKind<'tcx>> {
633+
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
634+
let v = self.iter().map(|t| t.fold_with(folder)).collect::<SmallVec<[_; 8]>>();
635+
folder.tcx().intern_projs(&v)
636+
}
637+
638+
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
639+
self.iter().any(|t| t.visit_with(visitor))
640+
}
641+
}
642+
631643
impl<'tcx> TypeFoldable<'tcx> for ty::instance::Instance<'tcx> {
632644
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
633645
use ty::InstanceDef::*;

0 commit comments

Comments
 (0)