1
Fork 0

Auto merge of #78027 - lcnr:lift-by-value, r=varkor

Lift: take self by value

seems small enough to not warrant an MCP 🤷
This commit is contained in:
bors 2020-10-21 23:09:38 +00:00
commit c4fe25d861
15 changed files with 139 additions and 167 deletions

View file

@ -157,7 +157,7 @@ impl<'tcx> FreeRegionRelations<'tcx> for FreeRegionMap<'tcx> {
impl<'a, 'tcx> Lift<'tcx> for FreeRegionMap<'a> { impl<'a, 'tcx> Lift<'tcx> for FreeRegionMap<'a> {
type Lifted = FreeRegionMap<'tcx>; type Lifted = FreeRegionMap<'tcx>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<FreeRegionMap<'tcx>> { fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<FreeRegionMap<'tcx>> {
self.relation.maybe_map(|&fr| tcx.lift(&fr)).map(|relation| FreeRegionMap { relation }) self.relation.maybe_map(|&fr| tcx.lift(fr)).map(|relation| FreeRegionMap { relation })
} }
} }

View file

@ -3,6 +3,7 @@ use syn::{self, parse_quote};
pub fn lift_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream { pub fn lift_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
s.add_bounds(synstructure::AddBounds::Generics); s.add_bounds(synstructure::AddBounds::Generics);
s.bind_with(|_| synstructure::BindStyle::Move);
let tcx: syn::Lifetime = parse_quote!('tcx); let tcx: syn::Lifetime = parse_quote!('tcx);
let newtcx: syn::GenericParam = parse_quote!('__lifted); let newtcx: syn::GenericParam = parse_quote!('__lifted);
@ -43,8 +44,8 @@ pub fn lift_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStre
quote! { quote! {
type Lifted = #lifted; type Lifted = #lifted;
fn lift_to_tcx(&self, __tcx: ::rustc_middle::ty::TyCtxt<'__lifted>) -> Option<#lifted> { fn lift_to_tcx(self, __tcx: ::rustc_middle::ty::TyCtxt<'__lifted>) -> Option<#lifted> {
Some(match *self { #body }) Some(match self { #body })
} }
}, },
) )

View file

@ -29,8 +29,8 @@ macro_rules! CloneLiftImpls {
$( $(
impl<$tcx> $crate::ty::Lift<$tcx> for $ty { impl<$tcx> $crate::ty::Lift<$tcx> for $ty {
type Lifted = Self; type Lifted = Self;
fn lift_to_tcx(&self, _: $crate::ty::TyCtxt<$tcx>) -> Option<Self> { fn lift_to_tcx(self, _: $crate::ty::TyCtxt<$tcx>) -> Option<Self> {
Some(Clone::clone(self)) Some(self)
} }
} }
)+ )+

View file

@ -2210,7 +2210,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
let name = ty::tls::with(|tcx| { let name = ty::tls::with(|tcx| {
let mut name = String::new(); let mut name = String::new();
let substs = tcx.lift(&substs).expect("could not lift for printing"); let substs = tcx.lift(substs).expect("could not lift for printing");
FmtPrinter::new(tcx, &mut name, Namespace::ValueNS) FmtPrinter::new(tcx, &mut name, Namespace::ValueNS)
.print_def_path(variant_def.def_id, substs)?; .print_def_path(variant_def.def_id, substs)?;
Ok(name) Ok(name)
@ -2233,7 +2233,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
if let Some(def_id) = def_id.as_local() { if let Some(def_id) = def_id.as_local() {
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id); let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
let name = if tcx.sess.opts.debugging_opts.span_free_formats { let name = if tcx.sess.opts.debugging_opts.span_free_formats {
let substs = tcx.lift(&substs).unwrap(); let substs = tcx.lift(substs).unwrap();
format!( format!(
"[closure@{}]", "[closure@{}]",
tcx.def_path_str_with_substs(def_id.to_def_id(), substs), tcx.def_path_str_with_substs(def_id.to_def_id(), substs),
@ -2527,7 +2527,7 @@ fn pretty_print_const(
) -> fmt::Result { ) -> fmt::Result {
use crate::ty::print::PrettyPrinter; use crate::ty::print::PrettyPrinter;
ty::tls::with(|tcx| { ty::tls::with(|tcx| {
let literal = tcx.lift(&c).unwrap(); let literal = tcx.lift(c).unwrap();
let mut cx = FmtPrinter::new(tcx, fmt, Namespace::ValueNS); let mut cx = FmtPrinter::new(tcx, fmt, Namespace::ValueNS);
cx.print_alloc_ids = true; cx.print_alloc_ids = true;
cx.pretty_print_const(literal, print_types)?; cx.pretty_print_const(literal, print_types)?;

View file

@ -535,7 +535,7 @@ impl<'tcx> TerminatorKind<'tcx> {
Goto { .. } => vec!["".into()], Goto { .. } => vec!["".into()],
SwitchInt { ref targets, switch_ty, .. } => ty::tls::with(|tcx| { SwitchInt { ref targets, switch_ty, .. } => ty::tls::with(|tcx| {
let param_env = ty::ParamEnv::empty(); let param_env = ty::ParamEnv::empty();
let switch_ty = tcx.lift(&switch_ty).unwrap(); let switch_ty = tcx.lift(switch_ty).unwrap();
let size = tcx.layout_of(param_env.and(switch_ty)).unwrap().size; let size = tcx.layout_of(param_env.and(switch_ty)).unwrap().size;
targets targets
.values .values

View file

@ -1060,7 +1060,7 @@ impl<'tcx> TyCtxt<'tcx> {
) )
} }
pub fn lift<T: ?Sized + Lift<'tcx>>(self, value: &T) -> Option<T::Lifted> { pub fn lift<T: Lift<'tcx>>(self, value: T) -> Option<T::Lifted> {
value.lift_to_tcx(self) value.lift_to_tcx(self)
} }
@ -1569,16 +1569,16 @@ impl<'tcx> TyCtxt<'tcx> {
/// e.g., `()` or `u8`, was interned in a different context. /// e.g., `()` or `u8`, was interned in a different context.
pub trait Lift<'tcx>: fmt::Debug { pub trait Lift<'tcx>: fmt::Debug {
type Lifted: fmt::Debug + 'tcx; type Lifted: fmt::Debug + 'tcx;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted>; fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted>;
} }
macro_rules! nop_lift { macro_rules! nop_lift {
($set:ident; $ty:ty => $lifted:ty) => { ($set:ident; $ty:ty => $lifted:ty) => {
impl<'a, 'tcx> Lift<'tcx> for $ty { impl<'a, 'tcx> Lift<'tcx> for $ty {
type Lifted = $lifted; type Lifted = $lifted;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> { fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
if tcx.interners.$set.contains_pointer_to(&Interned(*self)) { if tcx.interners.$set.contains_pointer_to(&Interned(self)) {
Some(unsafe { mem::transmute(*self) }) Some(unsafe { mem::transmute(self) })
} else { } else {
None None
} }
@ -1591,12 +1591,12 @@ macro_rules! nop_list_lift {
($set:ident; $ty:ty => $lifted:ty) => { ($set:ident; $ty:ty => $lifted:ty) => {
impl<'a, 'tcx> Lift<'tcx> for &'a List<$ty> { impl<'a, 'tcx> Lift<'tcx> for &'a List<$ty> {
type Lifted = &'tcx List<$lifted>; type Lifted = &'tcx List<$lifted>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> { fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
if self.is_empty() { if self.is_empty() {
return Some(List::empty()); return Some(List::empty());
} }
if tcx.interners.$set.contains_pointer_to(&Interned(*self)) { if tcx.interners.$set.contains_pointer_to(&Interned(self)) {
Some(unsafe { mem::transmute(*self) }) Some(unsafe { mem::transmute(self) })
} else { } else {
None None
} }

View file

@ -229,7 +229,7 @@ impl<'tcx> ty::TyS<'tcx> {
ty::Adt(def, _) => format!("{} `{}`", def.descr(), tcx.def_path_str(def.did)).into(), ty::Adt(def, _) => format!("{} `{}`", def.descr(), tcx.def_path_str(def.did)).into(),
ty::Foreign(def_id) => format!("extern type `{}`", tcx.def_path_str(def_id)).into(), ty::Foreign(def_id) => format!("extern type `{}`", tcx.def_path_str(def_id)).into(),
ty::Array(t, n) => { ty::Array(t, n) => {
let n = tcx.lift(&n).unwrap(); let n = tcx.lift(n).unwrap();
match n.try_eval_usize(tcx, ty::ParamEnv::empty()) { match n.try_eval_usize(tcx, ty::ParamEnv::empty()) {
_ if t.is_simple_ty() => format!("array `{}`", self).into(), _ if t.is_simple_ty() => format!("array `{}`", self).into(),
Some(n) => format!("array of {} element{}", n, pluralize!(n)).into(), Some(n) => format!("array of {} element{}", n, pluralize!(n)).into(),

View file

@ -258,7 +258,7 @@ impl<'tcx> InstanceDef<'tcx> {
impl<'tcx> fmt::Display for Instance<'tcx> { impl<'tcx> fmt::Display for Instance<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
ty::tls::with(|tcx| { ty::tls::with(|tcx| {
let substs = tcx.lift(&self.substs).expect("could not lift for printing"); let substs = tcx.lift(self.substs).expect("could not lift for printing");
FmtPrinter::new(tcx, &mut *f, Namespace::ValueNS) FmtPrinter::new(tcx, &mut *f, Namespace::ValueNS)
.print_def_path(self.def_id(), substs)?; .print_def_path(self.def_id(), substs)?;
Ok(()) Ok(())

View file

@ -1848,7 +1848,7 @@ macro_rules! forward_display_to_print {
$(impl fmt::Display for $ty { $(impl fmt::Display for $ty {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
ty::tls::with(|tcx| { ty::tls::with(|tcx| {
tcx.lift(self) tcx.lift(*self)
.expect("could not lift for printing") .expect("could not lift for printing")
.print(FmtPrinter::new(tcx, f, Namespace::TypeNS))?; .print(FmtPrinter::new(tcx, f, Namespace::TypeNS))?;
Ok(()) Ok(())

View file

@ -332,24 +332,23 @@ CloneTypeFoldableAndLiftImpls! {
// FIXME(eddyb) replace all the uses of `Option::map` with `?`. // FIXME(eddyb) replace all the uses of `Option::map` with `?`.
impl<'tcx, A: Lift<'tcx>, B: Lift<'tcx>> Lift<'tcx> for (A, B) { impl<'tcx, A: Lift<'tcx>, B: Lift<'tcx>> Lift<'tcx> for (A, B) {
type Lifted = (A::Lifted, B::Lifted); type Lifted = (A::Lifted, B::Lifted);
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> { fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
tcx.lift(&self.0).and_then(|a| tcx.lift(&self.1).map(|b| (a, b))) Some((tcx.lift(self.0)?, tcx.lift(self.1)?))
} }
} }
impl<'tcx, A: Lift<'tcx>, B: Lift<'tcx>, C: Lift<'tcx>> Lift<'tcx> for (A, B, C) { impl<'tcx, A: Lift<'tcx>, B: Lift<'tcx>, C: Lift<'tcx>> Lift<'tcx> for (A, B, C) {
type Lifted = (A::Lifted, B::Lifted, C::Lifted); type Lifted = (A::Lifted, B::Lifted, C::Lifted);
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> { fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
tcx.lift(&self.0) Some((tcx.lift(self.0)?, tcx.lift(self.1)?, tcx.lift(self.2)?))
.and_then(|a| tcx.lift(&self.1).and_then(|b| tcx.lift(&self.2).map(|c| (a, b, c))))
} }
} }
impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for Option<T> { impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for Option<T> {
type Lifted = Option<T::Lifted>; type Lifted = Option<T::Lifted>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> { fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
match *self { match self {
Some(ref x) => tcx.lift(x).map(Some), Some(x) => tcx.lift(x).map(Some),
None => Some(None), None => Some(None),
} }
} }
@ -357,89 +356,72 @@ impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for Option<T> {
impl<'tcx, T: Lift<'tcx>, E: Lift<'tcx>> Lift<'tcx> for Result<T, E> { impl<'tcx, T: Lift<'tcx>, E: Lift<'tcx>> Lift<'tcx> for Result<T, E> {
type Lifted = Result<T::Lifted, E::Lifted>; type Lifted = Result<T::Lifted, E::Lifted>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> { fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
match *self { match self {
Ok(ref x) => tcx.lift(x).map(Ok), Ok(x) => tcx.lift(x).map(Ok),
Err(ref e) => tcx.lift(e).map(Err), Err(e) => tcx.lift(e).map(Err),
} }
} }
} }
impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for Box<T> { impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for Box<T> {
type Lifted = Box<T::Lifted>; type Lifted = Box<T::Lifted>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> { fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
tcx.lift(&**self).map(Box::new) tcx.lift(*self).map(Box::new)
} }
} }
impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for Rc<T> { impl<'tcx, T: Lift<'tcx> + Clone> Lift<'tcx> for Rc<T> {
type Lifted = Rc<T::Lifted>; type Lifted = Rc<T::Lifted>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> { fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
tcx.lift(&**self).map(Rc::new) tcx.lift(self.as_ref().clone()).map(Rc::new)
} }
} }
impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for Arc<T> { impl<'tcx, T: Lift<'tcx> + Clone> Lift<'tcx> for Arc<T> {
type Lifted = Arc<T::Lifted>; type Lifted = Arc<T::Lifted>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> { fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
tcx.lift(&**self).map(Arc::new) tcx.lift(self.as_ref().clone()).map(Arc::new)
} }
} }
impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for [T] {
type Lifted = Vec<T::Lifted>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
// type annotation needed to inform `projection_must_outlive`
let mut result: Vec<<T as Lift<'tcx>>::Lifted> = Vec::with_capacity(self.len());
for x in self {
if let Some(value) = tcx.lift(x) {
result.push(value);
} else {
return None;
}
}
Some(result)
}
}
impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for Vec<T> { impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for Vec<T> {
type Lifted = Vec<T::Lifted>; type Lifted = Vec<T::Lifted>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> { fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
tcx.lift(&self[..]) self.into_iter().map(|v| tcx.lift(v)).collect()
} }
} }
impl<'tcx, I: Idx, T: Lift<'tcx>> Lift<'tcx> for IndexVec<I, T> { impl<'tcx, I: Idx, T: Lift<'tcx>> Lift<'tcx> for IndexVec<I, T> {
type Lifted = IndexVec<I, T::Lifted>; type Lifted = IndexVec<I, T::Lifted>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> { fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
self.iter().map(|e| tcx.lift(e)).collect() self.into_iter().map(|e| tcx.lift(e)).collect()
} }
} }
impl<'a, 'tcx> Lift<'tcx> for ty::TraitRef<'a> { impl<'a, 'tcx> Lift<'tcx> for ty::TraitRef<'a> {
type Lifted = ty::TraitRef<'tcx>; type Lifted = ty::TraitRef<'tcx>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> { fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
tcx.lift(&self.substs).map(|substs| ty::TraitRef { def_id: self.def_id, substs }) tcx.lift(self.substs).map(|substs| ty::TraitRef { def_id: self.def_id, substs })
} }
} }
impl<'a, 'tcx> Lift<'tcx> for ty::ExistentialTraitRef<'a> { impl<'a, 'tcx> Lift<'tcx> for ty::ExistentialTraitRef<'a> {
type Lifted = ty::ExistentialTraitRef<'tcx>; type Lifted = ty::ExistentialTraitRef<'tcx>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> { fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
tcx.lift(&self.substs).map(|substs| ty::ExistentialTraitRef { def_id: self.def_id, substs }) tcx.lift(self.substs).map(|substs| ty::ExistentialTraitRef { def_id: self.def_id, substs })
} }
} }
impl<'a, 'tcx> Lift<'tcx> for ty::ExistentialPredicate<'a> { impl<'a, 'tcx> Lift<'tcx> for ty::ExistentialPredicate<'a> {
type Lifted = ty::ExistentialPredicate<'tcx>; type Lifted = ty::ExistentialPredicate<'tcx>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> { fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
match self { match self {
ty::ExistentialPredicate::Trait(x) => tcx.lift(x).map(ty::ExistentialPredicate::Trait), ty::ExistentialPredicate::Trait(x) => tcx.lift(x).map(ty::ExistentialPredicate::Trait),
ty::ExistentialPredicate::Projection(x) => { ty::ExistentialPredicate::Projection(x) => {
tcx.lift(x).map(ty::ExistentialPredicate::Projection) tcx.lift(x).map(ty::ExistentialPredicate::Projection)
} }
ty::ExistentialPredicate::AutoTrait(def_id) => { ty::ExistentialPredicate::AutoTrait(def_id) => {
Some(ty::ExistentialPredicate::AutoTrait(*def_id)) Some(ty::ExistentialPredicate::AutoTrait(def_id))
} }
} }
} }
@ -447,15 +429,15 @@ impl<'a, 'tcx> Lift<'tcx> for ty::ExistentialPredicate<'a> {
impl<'a, 'tcx> Lift<'tcx> for ty::TraitPredicate<'a> { impl<'a, 'tcx> Lift<'tcx> for ty::TraitPredicate<'a> {
type Lifted = ty::TraitPredicate<'tcx>; type Lifted = ty::TraitPredicate<'tcx>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<ty::TraitPredicate<'tcx>> { fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<ty::TraitPredicate<'tcx>> {
tcx.lift(&self.trait_ref).map(|trait_ref| ty::TraitPredicate { trait_ref }) tcx.lift(self.trait_ref).map(|trait_ref| ty::TraitPredicate { trait_ref })
} }
} }
impl<'a, 'tcx> Lift<'tcx> for ty::SubtypePredicate<'a> { impl<'a, 'tcx> Lift<'tcx> for ty::SubtypePredicate<'a> {
type Lifted = ty::SubtypePredicate<'tcx>; type Lifted = ty::SubtypePredicate<'tcx>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<ty::SubtypePredicate<'tcx>> { fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<ty::SubtypePredicate<'tcx>> {
tcx.lift(&(self.a, self.b)).map(|(a, b)| ty::SubtypePredicate { tcx.lift((self.a, self.b)).map(|(a, b)| ty::SubtypePredicate {
a_is_expected: self.a_is_expected, a_is_expected: self.a_is_expected,
a, a,
b, b,
@ -465,33 +447,33 @@ impl<'a, 'tcx> Lift<'tcx> for ty::SubtypePredicate<'a> {
impl<'tcx, A: Copy + Lift<'tcx>, B: Copy + Lift<'tcx>> Lift<'tcx> for ty::OutlivesPredicate<A, B> { impl<'tcx, A: Copy + Lift<'tcx>, B: Copy + Lift<'tcx>> Lift<'tcx> for ty::OutlivesPredicate<A, B> {
type Lifted = ty::OutlivesPredicate<A::Lifted, B::Lifted>; type Lifted = ty::OutlivesPredicate<A::Lifted, B::Lifted>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> { fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
tcx.lift(&(self.0, self.1)).map(|(a, b)| ty::OutlivesPredicate(a, b)) tcx.lift((self.0, self.1)).map(|(a, b)| ty::OutlivesPredicate(a, b))
} }
} }
impl<'a, 'tcx> Lift<'tcx> for ty::ProjectionTy<'a> { impl<'a, 'tcx> Lift<'tcx> for ty::ProjectionTy<'a> {
type Lifted = ty::ProjectionTy<'tcx>; type Lifted = ty::ProjectionTy<'tcx>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<ty::ProjectionTy<'tcx>> { fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<ty::ProjectionTy<'tcx>> {
tcx.lift(&self.substs) tcx.lift(self.substs)
.map(|substs| ty::ProjectionTy { item_def_id: self.item_def_id, substs }) .map(|substs| ty::ProjectionTy { item_def_id: self.item_def_id, substs })
} }
} }
impl<'a, 'tcx> Lift<'tcx> for ty::ProjectionPredicate<'a> { impl<'a, 'tcx> Lift<'tcx> for ty::ProjectionPredicate<'a> {
type Lifted = ty::ProjectionPredicate<'tcx>; type Lifted = ty::ProjectionPredicate<'tcx>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<ty::ProjectionPredicate<'tcx>> { fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<ty::ProjectionPredicate<'tcx>> {
tcx.lift(&(self.projection_ty, self.ty)) tcx.lift((self.projection_ty, self.ty))
.map(|(projection_ty, ty)| ty::ProjectionPredicate { projection_ty, ty }) .map(|(projection_ty, ty)| ty::ProjectionPredicate { projection_ty, ty })
} }
} }
impl<'a, 'tcx> Lift<'tcx> for ty::ExistentialProjection<'a> { impl<'a, 'tcx> Lift<'tcx> for ty::ExistentialProjection<'a> {
type Lifted = ty::ExistentialProjection<'tcx>; type Lifted = ty::ExistentialProjection<'tcx>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> { fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
tcx.lift(&self.substs).map(|substs| ty::ExistentialProjection { tcx.lift(self.substs).map(|substs| ty::ExistentialProjection {
substs, substs,
ty: tcx.lift(&self.ty).expect("type must lift when substs do"), ty: tcx.lift(self.ty).expect("type must lift when substs do"),
item_def_id: self.item_def_id, item_def_id: self.item_def_id,
}) })
} }
@ -499,7 +481,7 @@ impl<'a, 'tcx> Lift<'tcx> for ty::ExistentialProjection<'a> {
impl<'a, 'tcx> Lift<'tcx> for ty::PredicateKind<'a> { impl<'a, 'tcx> Lift<'tcx> for ty::PredicateKind<'a> {
type Lifted = ty::PredicateKind<'tcx>; type Lifted = ty::PredicateKind<'tcx>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> { fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
match self { match self {
ty::PredicateKind::ForAll(binder) => tcx.lift(binder).map(ty::PredicateKind::ForAll), ty::PredicateKind::ForAll(binder) => tcx.lift(binder).map(ty::PredicateKind::ForAll),
ty::PredicateKind::Atom(atom) => tcx.lift(atom).map(ty::PredicateKind::Atom), ty::PredicateKind::Atom(atom) => tcx.lift(atom).map(ty::PredicateKind::Atom),
@ -509,24 +491,24 @@ impl<'a, 'tcx> Lift<'tcx> for ty::PredicateKind<'a> {
impl<'a, 'tcx> Lift<'tcx> for ty::PredicateAtom<'a> { impl<'a, 'tcx> Lift<'tcx> for ty::PredicateAtom<'a> {
type Lifted = ty::PredicateAtom<'tcx>; type Lifted = ty::PredicateAtom<'tcx>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> { fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
match *self { match self {
ty::PredicateAtom::Trait(ref data, constness) => { ty::PredicateAtom::Trait(data, constness) => {
tcx.lift(data).map(|data| ty::PredicateAtom::Trait(data, constness)) tcx.lift(data).map(|data| ty::PredicateAtom::Trait(data, constness))
} }
ty::PredicateAtom::Subtype(ref data) => tcx.lift(data).map(ty::PredicateAtom::Subtype), ty::PredicateAtom::Subtype(data) => tcx.lift(data).map(ty::PredicateAtom::Subtype),
ty::PredicateAtom::RegionOutlives(ref data) => { ty::PredicateAtom::RegionOutlives(data) => {
tcx.lift(data).map(ty::PredicateAtom::RegionOutlives) tcx.lift(data).map(ty::PredicateAtom::RegionOutlives)
} }
ty::PredicateAtom::TypeOutlives(ref data) => { ty::PredicateAtom::TypeOutlives(data) => {
tcx.lift(data).map(ty::PredicateAtom::TypeOutlives) tcx.lift(data).map(ty::PredicateAtom::TypeOutlives)
} }
ty::PredicateAtom::Projection(ref data) => { ty::PredicateAtom::Projection(data) => {
tcx.lift(data).map(ty::PredicateAtom::Projection) tcx.lift(data).map(ty::PredicateAtom::Projection)
} }
ty::PredicateAtom::WellFormed(ty) => tcx.lift(&ty).map(ty::PredicateAtom::WellFormed), ty::PredicateAtom::WellFormed(ty) => tcx.lift(ty).map(ty::PredicateAtom::WellFormed),
ty::PredicateAtom::ClosureKind(closure_def_id, closure_substs, kind) => { ty::PredicateAtom::ClosureKind(closure_def_id, closure_substs, kind) => {
tcx.lift(&closure_substs).map(|closure_substs| { tcx.lift(closure_substs).map(|closure_substs| {
ty::PredicateAtom::ClosureKind(closure_def_id, closure_substs, kind) ty::PredicateAtom::ClosureKind(closure_def_id, closure_substs, kind)
}) })
} }
@ -534,13 +516,13 @@ impl<'a, 'tcx> Lift<'tcx> for ty::PredicateAtom<'a> {
Some(ty::PredicateAtom::ObjectSafe(trait_def_id)) Some(ty::PredicateAtom::ObjectSafe(trait_def_id))
} }
ty::PredicateAtom::ConstEvaluatable(def_id, substs) => { ty::PredicateAtom::ConstEvaluatable(def_id, substs) => {
tcx.lift(&substs).map(|substs| ty::PredicateAtom::ConstEvaluatable(def_id, substs)) tcx.lift(substs).map(|substs| ty::PredicateAtom::ConstEvaluatable(def_id, substs))
} }
ty::PredicateAtom::ConstEquate(c1, c2) => { ty::PredicateAtom::ConstEquate(c1, c2) => {
tcx.lift(&(c1, c2)).map(|(c1, c2)| ty::PredicateAtom::ConstEquate(c1, c2)) tcx.lift((c1, c2)).map(|(c1, c2)| ty::PredicateAtom::ConstEquate(c1, c2))
} }
ty::PredicateAtom::TypeWellFormedFromEnv(ty) => { ty::PredicateAtom::TypeWellFormedFromEnv(ty) => {
tcx.lift(&ty).map(ty::PredicateAtom::TypeWellFormedFromEnv) tcx.lift(ty).map(ty::PredicateAtom::TypeWellFormedFromEnv)
} }
} }
} }
@ -548,61 +530,62 @@ impl<'a, 'tcx> Lift<'tcx> for ty::PredicateAtom<'a> {
impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for ty::Binder<T> { impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for ty::Binder<T> {
type Lifted = ty::Binder<T::Lifted>; type Lifted = ty::Binder<T::Lifted>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> { fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
tcx.lift(self.as_ref().skip_binder()).map(|v| self.rebind(v)) self.map_bound(|v| tcx.lift(v)).transpose()
} }
} }
impl<'a, 'tcx> Lift<'tcx> for ty::ParamEnv<'a> { impl<'a, 'tcx> Lift<'tcx> for ty::ParamEnv<'a> {
type Lifted = ty::ParamEnv<'tcx>; type Lifted = ty::ParamEnv<'tcx>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> { fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
tcx.lift(&self.caller_bounds()) tcx.lift(self.caller_bounds())
.map(|caller_bounds| ty::ParamEnv::new(caller_bounds, self.reveal())) .map(|caller_bounds| ty::ParamEnv::new(caller_bounds, self.reveal()))
} }
} }
impl<'a, 'tcx, T: Lift<'tcx>> Lift<'tcx> for ty::ParamEnvAnd<'a, T> { impl<'a, 'tcx, T: Lift<'tcx>> Lift<'tcx> for ty::ParamEnvAnd<'a, T> {
type Lifted = ty::ParamEnvAnd<'tcx, T::Lifted>; type Lifted = ty::ParamEnvAnd<'tcx, T::Lifted>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> { fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
tcx.lift(&self.param_env).and_then(|param_env| { tcx.lift(self.param_env).and_then(|param_env| {
tcx.lift(&self.value).map(|value| ty::ParamEnvAnd { param_env, value }) tcx.lift(self.value).map(|value| ty::ParamEnvAnd { param_env, value })
}) })
} }
} }
impl<'a, 'tcx> Lift<'tcx> for ty::ClosureSubsts<'a> { impl<'a, 'tcx> Lift<'tcx> for ty::ClosureSubsts<'a> {
type Lifted = ty::ClosureSubsts<'tcx>; type Lifted = ty::ClosureSubsts<'tcx>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> { fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
tcx.lift(&self.substs).map(|substs| ty::ClosureSubsts { substs }) tcx.lift(self.substs).map(|substs| ty::ClosureSubsts { substs })
} }
} }
impl<'a, 'tcx> Lift<'tcx> for ty::GeneratorSubsts<'a> { impl<'a, 'tcx> Lift<'tcx> for ty::GeneratorSubsts<'a> {
type Lifted = ty::GeneratorSubsts<'tcx>; type Lifted = ty::GeneratorSubsts<'tcx>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> { fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
tcx.lift(&self.substs).map(|substs| ty::GeneratorSubsts { substs }) tcx.lift(self.substs).map(|substs| ty::GeneratorSubsts { substs })
} }
} }
impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::Adjustment<'a> { impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::Adjustment<'a> {
type Lifted = ty::adjustment::Adjustment<'tcx>; type Lifted = ty::adjustment::Adjustment<'tcx>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> { fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
tcx.lift(&self.kind).and_then(|kind| { let ty::adjustment::Adjustment { kind, target } = self;
tcx.lift(&self.target).map(|target| ty::adjustment::Adjustment { kind, target }) tcx.lift(kind).and_then(|kind| {
tcx.lift(target).map(|target| ty::adjustment::Adjustment { kind, target })
}) })
} }
} }
impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::Adjust<'a> { impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::Adjust<'a> {
type Lifted = ty::adjustment::Adjust<'tcx>; type Lifted = ty::adjustment::Adjust<'tcx>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> { fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
match *self { match self {
ty::adjustment::Adjust::NeverToAny => Some(ty::adjustment::Adjust::NeverToAny), ty::adjustment::Adjust::NeverToAny => Some(ty::adjustment::Adjust::NeverToAny),
ty::adjustment::Adjust::Pointer(ptr) => Some(ty::adjustment::Adjust::Pointer(ptr)), ty::adjustment::Adjust::Pointer(ptr) => Some(ty::adjustment::Adjust::Pointer(ptr)),
ty::adjustment::Adjust::Deref(ref overloaded) => { ty::adjustment::Adjust::Deref(overloaded) => {
tcx.lift(overloaded).map(ty::adjustment::Adjust::Deref) tcx.lift(overloaded).map(ty::adjustment::Adjust::Deref)
} }
ty::adjustment::Adjust::Borrow(ref autoref) => { ty::adjustment::Adjust::Borrow(autoref) => {
tcx.lift(autoref).map(ty::adjustment::Adjust::Borrow) tcx.lift(autoref).map(ty::adjustment::Adjust::Borrow)
} }
} }
@ -611,8 +594,8 @@ impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::Adjust<'a> {
impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::OverloadedDeref<'a> { impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::OverloadedDeref<'a> {
type Lifted = ty::adjustment::OverloadedDeref<'tcx>; type Lifted = ty::adjustment::OverloadedDeref<'tcx>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> { fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
tcx.lift(&self.region).map(|region| ty::adjustment::OverloadedDeref { tcx.lift(self.region).map(|region| ty::adjustment::OverloadedDeref {
region, region,
mutbl: self.mutbl, mutbl: self.mutbl,
span: self.span, span: self.span,
@ -622,10 +605,10 @@ impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::OverloadedDeref<'a> {
impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::AutoBorrow<'a> { impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::AutoBorrow<'a> {
type Lifted = ty::adjustment::AutoBorrow<'tcx>; type Lifted = ty::adjustment::AutoBorrow<'tcx>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> { fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
match *self { match self {
ty::adjustment::AutoBorrow::Ref(r, m) => { ty::adjustment::AutoBorrow::Ref(r, m) => {
tcx.lift(&r).map(|r| ty::adjustment::AutoBorrow::Ref(r, m)) tcx.lift(r).map(|r| ty::adjustment::AutoBorrow::Ref(r, m))
} }
ty::adjustment::AutoBorrow::RawPtr(m) => Some(ty::adjustment::AutoBorrow::RawPtr(m)), ty::adjustment::AutoBorrow::RawPtr(m) => Some(ty::adjustment::AutoBorrow::RawPtr(m)),
} }
@ -634,16 +617,16 @@ impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::AutoBorrow<'a> {
impl<'a, 'tcx> Lift<'tcx> for ty::GenSig<'a> { impl<'a, 'tcx> Lift<'tcx> for ty::GenSig<'a> {
type Lifted = ty::GenSig<'tcx>; type Lifted = ty::GenSig<'tcx>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> { fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
tcx.lift(&(self.resume_ty, self.yield_ty, self.return_ty)) tcx.lift((self.resume_ty, self.yield_ty, self.return_ty))
.map(|(resume_ty, yield_ty, return_ty)| ty::GenSig { resume_ty, yield_ty, return_ty }) .map(|(resume_ty, yield_ty, return_ty)| ty::GenSig { resume_ty, yield_ty, return_ty })
} }
} }
impl<'a, 'tcx> Lift<'tcx> for ty::FnSig<'a> { impl<'a, 'tcx> Lift<'tcx> for ty::FnSig<'a> {
type Lifted = ty::FnSig<'tcx>; type Lifted = ty::FnSig<'tcx>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> { fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
tcx.lift(&self.inputs_and_output).map(|x| ty::FnSig { tcx.lift(self.inputs_and_output).map(|x| ty::FnSig {
inputs_and_output: x, inputs_and_output: x,
c_variadic: self.c_variadic, c_variadic: self.c_variadic,
unsafety: self.unsafety, unsafety: self.unsafety,
@ -654,19 +637,20 @@ impl<'a, 'tcx> Lift<'tcx> for ty::FnSig<'a> {
impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for ty::error::ExpectedFound<T> { impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for ty::error::ExpectedFound<T> {
type Lifted = ty::error::ExpectedFound<T::Lifted>; type Lifted = ty::error::ExpectedFound<T::Lifted>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> { fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
tcx.lift(&self.expected).and_then(|expected| { let ty::error::ExpectedFound { expected, found } = self;
tcx.lift(&self.found).map(|found| ty::error::ExpectedFound { expected, found }) tcx.lift(expected).and_then(|expected| {
tcx.lift(found).map(|found| ty::error::ExpectedFound { expected, found })
}) })
} }
} }
impl<'a, 'tcx> Lift<'tcx> for ty::error::TypeError<'a> { impl<'a, 'tcx> Lift<'tcx> for ty::error::TypeError<'a> {
type Lifted = ty::error::TypeError<'tcx>; type Lifted = ty::error::TypeError<'tcx>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> { fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
use crate::ty::error::TypeError::*; use crate::ty::error::TypeError::*;
Some(match *self { Some(match self {
Mismatch => Mismatch, Mismatch => Mismatch,
UnsafetyMismatch(x) => UnsafetyMismatch(x), UnsafetyMismatch(x) => UnsafetyMismatch(x),
AbiMismatch(x) => AbiMismatch(x), AbiMismatch(x) => AbiMismatch(x),
@ -675,51 +659,51 @@ impl<'a, 'tcx> Lift<'tcx> for ty::error::TypeError<'a> {
FixedArraySize(x) => FixedArraySize(x), FixedArraySize(x) => FixedArraySize(x),
ArgCount => ArgCount, ArgCount => ArgCount,
RegionsDoesNotOutlive(a, b) => { RegionsDoesNotOutlive(a, b) => {
return tcx.lift(&(a, b)).map(|(a, b)| RegionsDoesNotOutlive(a, b)); return tcx.lift((a, b)).map(|(a, b)| RegionsDoesNotOutlive(a, b));
} }
RegionsInsufficientlyPolymorphic(a, b) => { RegionsInsufficientlyPolymorphic(a, b) => {
return tcx.lift(&b).map(|b| RegionsInsufficientlyPolymorphic(a, b)); return tcx.lift(b).map(|b| RegionsInsufficientlyPolymorphic(a, b));
} }
RegionsOverlyPolymorphic(a, b) => { RegionsOverlyPolymorphic(a, b) => {
return tcx.lift(&b).map(|b| RegionsOverlyPolymorphic(a, b)); return tcx.lift(b).map(|b| RegionsOverlyPolymorphic(a, b));
} }
RegionsPlaceholderMismatch => RegionsPlaceholderMismatch, RegionsPlaceholderMismatch => RegionsPlaceholderMismatch,
IntMismatch(x) => IntMismatch(x), IntMismatch(x) => IntMismatch(x),
FloatMismatch(x) => FloatMismatch(x), FloatMismatch(x) => FloatMismatch(x),
Traits(x) => Traits(x), Traits(x) => Traits(x),
VariadicMismatch(x) => VariadicMismatch(x), VariadicMismatch(x) => VariadicMismatch(x),
CyclicTy(t) => return tcx.lift(&t).map(|t| CyclicTy(t)), CyclicTy(t) => return tcx.lift(t).map(|t| CyclicTy(t)),
CyclicConst(ct) => return tcx.lift(&ct).map(|ct| CyclicConst(ct)), CyclicConst(ct) => return tcx.lift(ct).map(|ct| CyclicConst(ct)),
ProjectionMismatched(x) => ProjectionMismatched(x), ProjectionMismatched(x) => ProjectionMismatched(x),
Sorts(ref x) => return tcx.lift(x).map(Sorts), Sorts(x) => return tcx.lift(x).map(Sorts),
ExistentialMismatch(ref x) => return tcx.lift(x).map(ExistentialMismatch), ExistentialMismatch(x) => return tcx.lift(x).map(ExistentialMismatch),
ConstMismatch(ref x) => return tcx.lift(x).map(ConstMismatch), ConstMismatch(x) => return tcx.lift(x).map(ConstMismatch),
IntrinsicCast => IntrinsicCast, IntrinsicCast => IntrinsicCast,
TargetFeatureCast(ref x) => TargetFeatureCast(*x), TargetFeatureCast(x) => TargetFeatureCast(x),
ObjectUnsafeCoercion(ref x) => return tcx.lift(x).map(ObjectUnsafeCoercion), ObjectUnsafeCoercion(x) => return tcx.lift(x).map(ObjectUnsafeCoercion),
}) })
} }
} }
impl<'a, 'tcx> Lift<'tcx> for ty::InstanceDef<'a> { impl<'a, 'tcx> Lift<'tcx> for ty::InstanceDef<'a> {
type Lifted = ty::InstanceDef<'tcx>; type Lifted = ty::InstanceDef<'tcx>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> { fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
match *self { match self {
ty::InstanceDef::Item(def_id) => Some(ty::InstanceDef::Item(def_id)), ty::InstanceDef::Item(def_id) => Some(ty::InstanceDef::Item(def_id)),
ty::InstanceDef::VtableShim(def_id) => Some(ty::InstanceDef::VtableShim(def_id)), ty::InstanceDef::VtableShim(def_id) => Some(ty::InstanceDef::VtableShim(def_id)),
ty::InstanceDef::ReifyShim(def_id) => Some(ty::InstanceDef::ReifyShim(def_id)), ty::InstanceDef::ReifyShim(def_id) => Some(ty::InstanceDef::ReifyShim(def_id)),
ty::InstanceDef::Intrinsic(def_id) => Some(ty::InstanceDef::Intrinsic(def_id)), ty::InstanceDef::Intrinsic(def_id) => Some(ty::InstanceDef::Intrinsic(def_id)),
ty::InstanceDef::FnPtrShim(def_id, ref ty) => { ty::InstanceDef::FnPtrShim(def_id, ty) => {
Some(ty::InstanceDef::FnPtrShim(def_id, tcx.lift(ty)?)) Some(ty::InstanceDef::FnPtrShim(def_id, tcx.lift(ty)?))
} }
ty::InstanceDef::Virtual(def_id, n) => Some(ty::InstanceDef::Virtual(def_id, n)), ty::InstanceDef::Virtual(def_id, n) => Some(ty::InstanceDef::Virtual(def_id, n)),
ty::InstanceDef::ClosureOnceShim { call_once } => { ty::InstanceDef::ClosureOnceShim { call_once } => {
Some(ty::InstanceDef::ClosureOnceShim { call_once }) Some(ty::InstanceDef::ClosureOnceShim { call_once })
} }
ty::InstanceDef::DropGlue(def_id, ref ty) => { ty::InstanceDef::DropGlue(def_id, ty) => {
Some(ty::InstanceDef::DropGlue(def_id, tcx.lift(ty)?)) Some(ty::InstanceDef::DropGlue(def_id, tcx.lift(ty)?))
} }
ty::InstanceDef::CloneShim(def_id, ref ty) => { ty::InstanceDef::CloneShim(def_id, ty) => {
Some(ty::InstanceDef::CloneShim(def_id, tcx.lift(ty)?)) Some(ty::InstanceDef::CloneShim(def_id, tcx.lift(ty)?))
} }
} }

View file

@ -141,11 +141,11 @@ impl<'tcx> GenericArg<'tcx> {
impl<'a, 'tcx> Lift<'tcx> for GenericArg<'a> { impl<'a, 'tcx> Lift<'tcx> for GenericArg<'a> {
type Lifted = GenericArg<'tcx>; type Lifted = GenericArg<'tcx>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> { fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
match self.unpack() { match self.unpack() {
GenericArgKind::Lifetime(lt) => tcx.lift(&lt).map(|lt| lt.into()), GenericArgKind::Lifetime(lt) => tcx.lift(lt).map(|lt| lt.into()),
GenericArgKind::Type(ty) => tcx.lift(&ty).map(|ty| ty.into()), GenericArgKind::Type(ty) => tcx.lift(ty).map(|ty| ty.into()),
GenericArgKind::Const(ct) => tcx.lift(&ct).map(|ct| ct.into()), GenericArgKind::Const(ct) => tcx.lift(ct).map(|ct| ct.into()),
} }
} }
} }

View file

@ -674,29 +674,16 @@ impl<'cx, 'tcx> dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tc
TerminatorKind::SwitchInt { ref discr, switch_ty: _, targets: _ } => { TerminatorKind::SwitchInt { ref discr, switch_ty: _, targets: _ } => {
self.consume_operand(loc, (discr, span), flow_state); self.consume_operand(loc, (discr, span), flow_state);
} }
TerminatorKind::Drop { place: ref drop_place, target: _, unwind: _ } => { TerminatorKind::Drop { place, target: _, unwind: _ } => {
let tcx = self.infcx.tcx;
// Compute the type with accurate region information.
let drop_place_ty = drop_place.ty(self.body, self.infcx.tcx);
// Erase the regions.
let drop_place_ty = self.infcx.tcx.erase_regions(&drop_place_ty).ty;
// "Lift" into the tcx -- once regions are erased, this type should be in the
// global arenas; this "lift" operation basically just asserts that is true, but
// that is useful later.
tcx.lift(&drop_place_ty).unwrap();
debug!( debug!(
"visit_terminator_drop \ "visit_terminator_drop \
loc: {:?} term: {:?} drop_place: {:?} drop_place_ty: {:?} span: {:?}", loc: {:?} term: {:?} place: {:?} span: {:?}",
loc, term, drop_place, drop_place_ty, span loc, term, place, span
); );
self.access_place( self.access_place(
loc, loc,
(*drop_place, span), (place, span),
(AccessDepth::Drop, Write(WriteKind::StorageDeadOrDrop)), (AccessDepth::Drop, Write(WriteKind::StorageDeadOrDrop)),
LocalMutationIsAllowed::Yes, LocalMutationIsAllowed::Yes,
flow_state, flow_state,

View file

@ -117,7 +117,7 @@ impl<Tag: Copy> std::fmt::Display for ImmTy<'tcx, Tag> {
ty::tls::with(|tcx| { ty::tls::with(|tcx| {
match self.imm { match self.imm {
Immediate::Scalar(s) => { Immediate::Scalar(s) => {
if let Some(ty) = tcx.lift(&self.layout.ty) { if let Some(ty) = tcx.lift(self.layout.ty) {
let cx = FmtPrinter::new(tcx, f, Namespace::ValueNS); let cx = FmtPrinter::new(tcx, f, Namespace::ValueNS);
p(cx, s, ty)?; p(cx, s, ty)?;
return Ok(()); return Ok(());

View file

@ -1563,7 +1563,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
ty::Str => Primitive(PrimitiveType::Str), ty::Str => Primitive(PrimitiveType::Str),
ty::Slice(ty) => Slice(box ty.clean(cx)), ty::Slice(ty) => Slice(box ty.clean(cx)),
ty::Array(ty, n) => { ty::Array(ty, n) => {
let mut n = cx.tcx.lift(&n).expect("array lift failed"); let mut n = cx.tcx.lift(n).expect("array lift failed");
n = n.eval(cx.tcx, ty::ParamEnv::reveal_all()); n = n.eval(cx.tcx, ty::ParamEnv::reveal_all());
let n = print_const(cx, n); let n = print_const(cx, n);
Array(box ty.clean(cx), n) Array(box ty.clean(cx), n)
@ -1573,7 +1573,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
BorrowedRef { lifetime: r.clean(cx), mutability: mutbl, type_: box ty.clean(cx) } BorrowedRef { lifetime: r.clean(cx), mutability: mutbl, type_: box ty.clean(cx) }
} }
ty::FnDef(..) | ty::FnPtr(_) => { ty::FnDef(..) | ty::FnPtr(_) => {
let ty = cx.tcx.lift(self).expect("FnPtr lift failed"); let ty = cx.tcx.lift(*self).expect("FnPtr lift failed");
let sig = ty.fn_sig(cx.tcx); let sig = ty.fn_sig(cx.tcx);
let def_id = DefId::local(CRATE_DEF_INDEX); let def_id = DefId::local(CRATE_DEF_INDEX);
BareFunction(box BareFunctionDecl { BareFunction(box BareFunctionDecl {
@ -1675,7 +1675,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
ty::Opaque(def_id, substs) => { ty::Opaque(def_id, substs) => {
// Grab the "TraitA + TraitB" from `impl TraitA + TraitB`, // Grab the "TraitA + TraitB" from `impl TraitA + TraitB`,
// by looking up the bounds associated with the def_id. // by looking up the bounds associated with the def_id.
let substs = cx.tcx.lift(&substs).expect("Opaque lift failed"); let substs = cx.tcx.lift(substs).expect("Opaque lift failed");
let bounds = cx let bounds = cx
.tcx .tcx
.explicit_item_bounds(def_id) .explicit_item_bounds(def_id)

View file

@ -503,7 +503,7 @@ fn print_const_with_custom_print_scalar(cx: &DocContext<'_>, ct: &'tcx ty::Const
format!("{}{}", format_integer_with_underscore_sep(&data.to_string()), ui.name_str()) format!("{}{}", format_integer_with_underscore_sep(&data.to_string()), ui.name_str())
} }
(ty::ConstKind::Value(ConstValue::Scalar(Scalar::Raw { data, .. })), ty::Int(i)) => { (ty::ConstKind::Value(ConstValue::Scalar(Scalar::Raw { data, .. })), ty::Int(i)) => {
let ty = cx.tcx.lift(&ct.ty).unwrap(); let ty = cx.tcx.lift(ct.ty).unwrap();
let size = cx.tcx.layout_of(ty::ParamEnv::empty().and(ty)).unwrap().size; let size = cx.tcx.layout_of(ty::ParamEnv::empty().and(ty)).unwrap().size;
let sign_extended_data = sign_extend(data, size) as i128; let sign_extended_data = sign_extend(data, size) as i128;