From 82ab668a556abc1843e10bb0da2a307d2442e1e2 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Fri, 26 Oct 2018 13:32:45 +0200 Subject: [PATCH] Further foundational stuff on `ProjectionKind` before I add it to `AscribeUserType`. --- src/librustc/ty/context.rs | 18 ++++++++++++++++++ src/librustc/ty/structural_impls.rs | 12 ++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 1e3b372c0290..d4b47db60816 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 { } } +impl<'a, 'tcx> Lift<'tcx> for &'a List> { + type Lifted = &'tcx List>; + fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option { + 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 a93dca4af426..62827ea20c31 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> { } } +impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List> { + 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::>(); + folder.tcx().intern_projs(&v) + } + + fn super_visit_with>(&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::*;