2015-09-06 21:51:58 +03:00
|
|
|
// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2017-11-11 13:04:36 -05:00
|
|
|
//! This module contains implements of the `Lift` and `TypeFoldable`
|
|
|
|
//! traits for various types in the Rust compiler. Most are written by
|
|
|
|
//! hand, though we've recently added some macros (e.g.,
|
|
|
|
//! `BraceStructLiftImpl!`) to help with the tedium.
|
|
|
|
|
2018-01-16 09:28:27 +01:00
|
|
|
use middle::const_val::{self, ConstVal, ConstEvalErr};
|
2016-08-04 15:52:57 +03:00
|
|
|
use ty::{self, Lift, Ty, TyCtxt};
|
2016-03-22 17:30:57 +02:00
|
|
|
use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
|
2016-10-24 18:23:29 -06:00
|
|
|
use rustc_data_structures::accumulate_vec::AccumulateVec;
|
2017-02-08 22:19:22 +13:00
|
|
|
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
|
2018-01-16 09:13:50 +01:00
|
|
|
use mir::interpret;
|
2015-09-06 21:51:58 +03:00
|
|
|
|
|
|
|
use std::rc::Rc;
|
|
|
|
|
2017-11-11 13:04:36 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// Atomic structs
|
|
|
|
//
|
|
|
|
// For things that don't carry any arena-allocated data (and are
|
|
|
|
// copy...), just add them to this list.
|
|
|
|
|
|
|
|
macro_rules! CopyImpls {
|
|
|
|
($($ty:ty,)+) => {
|
|
|
|
$(
|
|
|
|
impl<'tcx> Lift<'tcx> for $ty {
|
|
|
|
type Lifted = Self;
|
|
|
|
fn lift_to_tcx<'a, 'gcx>(&self, _: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self> {
|
|
|
|
Some(*self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx> TypeFoldable<'tcx> for $ty {
|
|
|
|
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, _: &mut F) -> $ty {
|
|
|
|
*self
|
|
|
|
}
|
|
|
|
|
|
|
|
fn super_visit_with<F: TypeVisitor<'tcx>>(&self, _: &mut F) -> bool {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)+
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CopyImpls! {
|
|
|
|
(),
|
|
|
|
::hir::Unsafety,
|
|
|
|
::syntax::abi::Abi,
|
|
|
|
::hir::def_id::DefId,
|
|
|
|
::mir::Local,
|
2018-01-02 23:22:09 +00:00
|
|
|
::mir::Promoted,
|
2017-11-11 13:04:36 -05:00
|
|
|
::traits::Reveal,
|
|
|
|
::syntax_pos::Span,
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// Macros
|
|
|
|
//
|
|
|
|
// When possible, use one of these (relatively) convenient macros to write
|
|
|
|
// the impls for you.
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! BraceStructLiftImpl {
|
|
|
|
(impl<$($p:tt),*> Lift<$tcx:tt> for $s:path {
|
|
|
|
type Lifted = $lifted:ty;
|
|
|
|
$($field:ident),* $(,)*
|
|
|
|
} $(where $($wc:tt)*)*) => {
|
|
|
|
impl<$($p),*> $crate::ty::Lift<$tcx> for $s
|
|
|
|
$(where $($wc)*)*
|
|
|
|
{
|
|
|
|
type Lifted = $lifted;
|
|
|
|
|
|
|
|
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<$lifted> {
|
|
|
|
$(let $field = tcx.lift(&self.$field)?;)*
|
|
|
|
Some(Self::Lifted { $($field),* })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! EnumLiftImpl {
|
|
|
|
(impl<$($p:tt),*> Lift<$tcx:tt> for $s:path {
|
|
|
|
type Lifted = $lifted:ty;
|
|
|
|
$(
|
|
|
|
($variant:path) ( $( $variant_arg:ident),* )
|
|
|
|
),*
|
|
|
|
$(,)*
|
|
|
|
} $(where $($wc:tt)*)*) => {
|
|
|
|
impl<$($p),*> $crate::ty::Lift<$tcx> for $s
|
|
|
|
$(where $($wc)*)*
|
|
|
|
{
|
|
|
|
type Lifted = $lifted;
|
|
|
|
|
|
|
|
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<$lifted> {
|
|
|
|
match self {
|
|
|
|
$($variant ( $($variant_arg),* ) => {
|
|
|
|
Some($variant ( $(tcx.lift($variant_arg)?),* ))
|
|
|
|
})*
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! BraceStructTypeFoldableImpl {
|
|
|
|
(impl<$($p:tt),*> TypeFoldable<$tcx:tt> for $s:path {
|
|
|
|
$($field:ident),* $(,)*
|
|
|
|
} $(where $($wc:tt)*)*) => {
|
|
|
|
impl<$($p),*> $crate::ty::fold::TypeFoldable<$tcx> for $s
|
|
|
|
$(where $($wc)*)*
|
|
|
|
{
|
|
|
|
fn super_fold_with<'gcx: $tcx, V: $crate::ty::fold::TypeFolder<'gcx, $tcx>>(
|
|
|
|
&self,
|
|
|
|
folder: &mut V,
|
|
|
|
) -> Self {
|
|
|
|
let $s { $($field,)* } = self;
|
|
|
|
$s { $($field: $field.fold_with(folder),)* }
|
|
|
|
}
|
|
|
|
|
|
|
|
fn super_visit_with<V: $crate::ty::fold::TypeVisitor<$tcx>>(
|
|
|
|
&self,
|
|
|
|
visitor: &mut V,
|
|
|
|
) -> bool {
|
|
|
|
let $s { $($field,)* } = self;
|
|
|
|
false $(|| $field.visit_with(visitor))*
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! EnumTypeFoldableImpl {
|
|
|
|
(impl<$($p:tt),*> TypeFoldable<$tcx:tt> for $s:path {
|
|
|
|
$(
|
|
|
|
($variant:path) ( $( $variant_arg:ident),* )
|
|
|
|
),*
|
|
|
|
$(,)*
|
|
|
|
} $(where $($wc:tt)*)*) => {
|
|
|
|
impl<$($p),*> $crate::ty::fold::TypeFoldable<$tcx> for $s
|
|
|
|
$(where $($wc)*)*
|
|
|
|
{
|
|
|
|
fn super_fold_with<'gcx: $tcx, V: $crate::ty::fold::TypeFolder<'gcx, $tcx>>(
|
|
|
|
&self,
|
|
|
|
folder: &mut V,
|
|
|
|
) -> Self {
|
|
|
|
match self {
|
|
|
|
$($variant ( $($variant_arg),* ) => {
|
|
|
|
$variant ( $($variant_arg.fold_with(folder)),* )
|
|
|
|
})*
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn super_visit_with<V: $crate::ty::fold::TypeVisitor<$tcx>>(
|
|
|
|
&self,
|
|
|
|
visitor: &mut V,
|
|
|
|
) -> bool {
|
|
|
|
match self {
|
|
|
|
$($variant ( $($variant_arg),* ) => {
|
|
|
|
false $(|| $variant_arg.visit_with(visitor))*
|
|
|
|
})*
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2015-09-06 21:51:58 +03:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// Lift implementations
|
|
|
|
|
|
|
|
impl<'tcx, A: Lift<'tcx>, B: Lift<'tcx>> Lift<'tcx> for (A, B) {
|
|
|
|
type Lifted = (A::Lifted, B::Lifted);
|
2016-04-29 06:00:23 +03:00
|
|
|
fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
2015-09-06 21:51:58 +03:00
|
|
|
tcx.lift(&self.0).and_then(|a| tcx.lift(&self.1).map(|b| (a, b)))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-26 14:34:03 +01:00
|
|
|
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);
|
|
|
|
fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
|
|
|
tcx.lift(&self.0).and_then(|a| {
|
|
|
|
tcx.lift(&self.1).and_then(|b| tcx.lift(&self.2).map(|c| (a, b, c)))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-29 06:00:23 +03:00
|
|
|
impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for Option<T> {
|
|
|
|
type Lifted = Option<T::Lifted>;
|
|
|
|
fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
2016-05-02 18:07:47 +03:00
|
|
|
match *self {
|
|
|
|
Some(ref x) => tcx.lift(x).map(Some),
|
|
|
|
None => Some(None)
|
|
|
|
}
|
2016-04-29 06:00:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx, T: Lift<'tcx>, E: Lift<'tcx>> Lift<'tcx> for Result<T, E> {
|
|
|
|
type Lifted = Result<T::Lifted, E::Lifted>;
|
|
|
|
fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
|
|
|
match *self {
|
|
|
|
Ok(ref x) => tcx.lift(x).map(Ok),
|
|
|
|
Err(ref e) => tcx.lift(e).map(Err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-07 08:08:53 +03:00
|
|
|
impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for Box<T> {
|
|
|
|
type Lifted = Box<T::Lifted>;
|
|
|
|
fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
|
|
|
tcx.lift(&**self).map(Box::new)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-06 21:51:58 +03:00
|
|
|
impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for [T] {
|
|
|
|
type Lifted = Vec<T::Lifted>;
|
2016-04-29 06:00:23 +03:00
|
|
|
fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
2015-09-26 02:52:46 +03:00
|
|
|
// type annotation needed to inform `projection_must_outlive`
|
|
|
|
let mut result : Vec<<T as Lift<'tcx>>::Lifted>
|
|
|
|
= Vec::with_capacity(self.len());
|
2015-09-06 21:51:58 +03:00
|
|
|
for x in self {
|
|
|
|
if let Some(value) = tcx.lift(x) {
|
|
|
|
result.push(value);
|
|
|
|
} else {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Some(result)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-02 18:07:47 +03:00
|
|
|
impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for Vec<T> {
|
|
|
|
type Lifted = Vec<T::Lifted>;
|
|
|
|
fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
|
|
|
tcx.lift(&self[..])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-11 13:04:36 -05:00
|
|
|
impl<'tcx, I: Idx, T: Lift<'tcx>> Lift<'tcx> for IndexVec<I, T> {
|
|
|
|
type Lifted = IndexVec<I, T::Lifted>;
|
|
|
|
fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
|
|
|
self.iter()
|
|
|
|
.map(|e| tcx.lift(e))
|
|
|
|
.collect()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-04 15:52:57 +03:00
|
|
|
impl<'a, 'tcx> Lift<'tcx> for ty::TraitRef<'a> {
|
|
|
|
type Lifted = ty::TraitRef<'tcx>;
|
|
|
|
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
|
|
|
tcx.lift(&self.substs).map(|substs| ty::TraitRef {
|
|
|
|
def_id: self.def_id,
|
2017-07-03 11:19:51 -07:00
|
|
|
substs,
|
2016-08-04 15:52:57 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, 'tcx> Lift<'tcx> for ty::ExistentialTraitRef<'a> {
|
|
|
|
type Lifted = ty::ExistentialTraitRef<'tcx>;
|
|
|
|
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
|
|
|
tcx.lift(&self.substs).map(|substs| ty::ExistentialTraitRef {
|
2015-09-06 21:51:58 +03:00
|
|
|
def_id: self.def_id,
|
2017-07-03 11:19:51 -07:00
|
|
|
substs,
|
2015-09-06 21:51:58 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, 'tcx> Lift<'tcx> for ty::TraitPredicate<'a> {
|
|
|
|
type Lifted = ty::TraitPredicate<'tcx>;
|
2016-04-29 06:00:23 +03:00
|
|
|
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>)
|
|
|
|
-> Option<ty::TraitPredicate<'tcx>> {
|
2015-09-06 21:51:58 +03:00
|
|
|
tcx.lift(&self.trait_ref).map(|trait_ref| ty::TraitPredicate {
|
2017-07-03 11:19:51 -07:00
|
|
|
trait_ref,
|
2015-09-06 21:51:58 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-09 21:47:09 -05:00
|
|
|
impl<'a, 'tcx> Lift<'tcx> for ty::SubtypePredicate<'a> {
|
|
|
|
type Lifted = ty::SubtypePredicate<'tcx>;
|
|
|
|
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>)
|
|
|
|
-> Option<ty::SubtypePredicate<'tcx>> {
|
|
|
|
tcx.lift(&(self.a, self.b)).map(|(a, b)| ty::SubtypePredicate {
|
|
|
|
a_is_expected: self.a_is_expected,
|
2017-07-03 11:19:51 -07:00
|
|
|
a,
|
|
|
|
b,
|
2017-03-09 21:47:09 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-06 21:51:58 +03:00
|
|
|
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>;
|
2016-04-29 06:00:23 +03:00
|
|
|
fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
2015-09-06 21:51:58 +03:00
|
|
|
tcx.lift(&(self.0, self.1)).map(|(a, b)| ty::OutlivesPredicate(a, b))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-28 18:27:11 +03:00
|
|
|
impl<'a, 'tcx> Lift<'tcx> for ty::ProjectionTy<'a> {
|
|
|
|
type Lifted = ty::ProjectionTy<'tcx>;
|
|
|
|
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>)
|
|
|
|
-> Option<ty::ProjectionTy<'tcx>> {
|
2017-07-11 10:33:09 -04:00
|
|
|
tcx.lift(&self.substs).map(|substs| {
|
|
|
|
ty::ProjectionTy {
|
|
|
|
item_def_id: self.item_def_id,
|
2017-08-06 22:54:09 -07:00
|
|
|
substs,
|
2017-07-11 10:33:09 -04:00
|
|
|
}
|
2016-07-28 18:27:11 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-06 21:51:58 +03:00
|
|
|
impl<'a, 'tcx> Lift<'tcx> for ty::ProjectionPredicate<'a> {
|
|
|
|
type Lifted = ty::ProjectionPredicate<'tcx>;
|
2016-04-29 06:00:23 +03:00
|
|
|
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>)
|
|
|
|
-> Option<ty::ProjectionPredicate<'tcx>> {
|
2016-07-28 18:27:11 +03:00
|
|
|
tcx.lift(&(self.projection_ty, self.ty)).map(|(projection_ty, ty)| {
|
2015-09-06 21:51:58 +03:00
|
|
|
ty::ProjectionPredicate {
|
2017-07-03 11:19:51 -07:00
|
|
|
projection_ty,
|
|
|
|
ty,
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-04 15:52:57 +03:00
|
|
|
impl<'a, 'tcx> Lift<'tcx> for ty::ExistentialProjection<'a> {
|
|
|
|
type Lifted = ty::ExistentialProjection<'tcx>;
|
|
|
|
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
2017-07-11 10:33:09 -04:00
|
|
|
tcx.lift(&self.substs).map(|substs| {
|
2016-08-04 15:52:57 +03:00
|
|
|
ty::ExistentialProjection {
|
2017-07-11 10:33:09 -04:00
|
|
|
substs,
|
|
|
|
ty: tcx.lift(&self.ty).expect("type must lift when substs do"),
|
|
|
|
item_def_id: self.item_def_id,
|
2016-08-04 15:52:57 +03:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-11 04:14:41 +03:00
|
|
|
impl<'a, 'tcx> Lift<'tcx> for ty::Predicate<'a> {
|
|
|
|
type Lifted = ty::Predicate<'tcx>;
|
|
|
|
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
|
|
|
match *self {
|
|
|
|
ty::Predicate::Trait(ref binder) => {
|
|
|
|
tcx.lift(binder).map(ty::Predicate::Trait)
|
|
|
|
}
|
2017-03-09 21:47:09 -05:00
|
|
|
ty::Predicate::Subtype(ref binder) => {
|
|
|
|
tcx.lift(binder).map(ty::Predicate::Subtype)
|
|
|
|
}
|
2016-05-11 04:14:41 +03:00
|
|
|
ty::Predicate::RegionOutlives(ref binder) => {
|
|
|
|
tcx.lift(binder).map(ty::Predicate::RegionOutlives)
|
|
|
|
}
|
|
|
|
ty::Predicate::TypeOutlives(ref binder) => {
|
|
|
|
tcx.lift(binder).map(ty::Predicate::TypeOutlives)
|
|
|
|
}
|
|
|
|
ty::Predicate::Projection(ref binder) => {
|
|
|
|
tcx.lift(binder).map(ty::Predicate::Projection)
|
|
|
|
}
|
|
|
|
ty::Predicate::WellFormed(ty) => {
|
|
|
|
tcx.lift(&ty).map(ty::Predicate::WellFormed)
|
|
|
|
}
|
2017-11-08 08:50:59 -05:00
|
|
|
ty::Predicate::ClosureKind(closure_def_id, closure_substs, kind) => {
|
|
|
|
tcx.lift(&closure_substs)
|
|
|
|
.map(|closure_substs| ty::Predicate::ClosureKind(closure_def_id,
|
|
|
|
closure_substs,
|
|
|
|
kind))
|
2016-05-11 04:14:41 +03:00
|
|
|
}
|
|
|
|
ty::Predicate::ObjectSafe(trait_def_id) => {
|
|
|
|
Some(ty::Predicate::ObjectSafe(trait_def_id))
|
|
|
|
}
|
2017-08-07 08:08:53 +03:00
|
|
|
ty::Predicate::ConstEvaluatable(def_id, substs) => {
|
|
|
|
tcx.lift(&substs).map(|substs| {
|
|
|
|
ty::Predicate::ConstEvaluatable(def_id, substs)
|
|
|
|
})
|
|
|
|
}
|
2016-05-11 04:14:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-06 21:51:58 +03:00
|
|
|
impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for ty::Binder<T> {
|
|
|
|
type Lifted = ty::Binder<T::Lifted>;
|
2016-04-29 06:00:23 +03:00
|
|
|
fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
2015-09-06 21:51:58 +03:00
|
|
|
tcx.lift(&self.0).map(|x| ty::Binder(x))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-07 08:08:53 +03:00
|
|
|
impl<'a, 'tcx> Lift<'tcx> for ty::ParamEnv<'a> {
|
|
|
|
type Lifted = ty::ParamEnv<'tcx>;
|
|
|
|
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
|
|
|
tcx.lift(&self.caller_bounds).map(|caller_bounds| {
|
|
|
|
ty::ParamEnv {
|
|
|
|
reveal: self.reveal,
|
2017-07-15 07:23:28 -04:00
|
|
|
universe: self.universe,
|
2017-08-07 08:08:53 +03:00
|
|
|
caller_bounds,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, 'tcx, T: Lift<'tcx>> Lift<'tcx> for ty::ParamEnvAnd<'a, T> {
|
|
|
|
type Lifted = ty::ParamEnvAnd<'tcx, T::Lifted>;
|
|
|
|
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
|
|
|
tcx.lift(&self.param_env).and_then(|param_env| {
|
|
|
|
tcx.lift(&self.value).map(|value| {
|
|
|
|
ty::ParamEnvAnd {
|
|
|
|
param_env,
|
|
|
|
value,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-29 08:30:54 +03:00
|
|
|
impl<'a, 'tcx> Lift<'tcx> for ty::ClosureSubsts<'a> {
|
|
|
|
type Lifted = ty::ClosureSubsts<'tcx>;
|
|
|
|
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
2016-11-03 22:19:33 +02:00
|
|
|
tcx.lift(&self.substs).map(|substs| {
|
|
|
|
ty::ClosureSubsts { substs: substs }
|
2016-04-29 08:30:54 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-26 14:34:03 +01:00
|
|
|
impl<'a, 'tcx> Lift<'tcx> for ty::GeneratorInterior<'a> {
|
|
|
|
type Lifted = ty::GeneratorInterior<'tcx>;
|
|
|
|
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
2017-08-09 13:56:19 -07:00
|
|
|
tcx.lift(&self.witness).map(|witness| {
|
2017-10-07 16:36:28 +02:00
|
|
|
ty::GeneratorInterior { witness, movable: self.movable }
|
2016-12-26 14:34:03 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-20 20:03:04 +03:00
|
|
|
impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::Adjustment<'a> {
|
|
|
|
type Lifted = ty::adjustment::Adjustment<'tcx>;
|
2016-05-02 18:07:47 +03:00
|
|
|
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
2017-05-20 20:03:04 +03:00
|
|
|
tcx.lift(&self.kind).and_then(|kind| {
|
2017-05-27 10:29:24 +03:00
|
|
|
tcx.lift(&self.target).map(|target| {
|
|
|
|
ty::adjustment::Adjustment { kind, target }
|
2017-05-20 20:03:04 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::Adjust<'a> {
|
|
|
|
type Lifted = ty::adjustment::Adjust<'tcx>;
|
|
|
|
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
|
|
|
match *self {
|
|
|
|
ty::adjustment::Adjust::NeverToAny =>
|
|
|
|
Some(ty::adjustment::Adjust::NeverToAny),
|
|
|
|
ty::adjustment::Adjust::ReifyFnPointer =>
|
|
|
|
Some(ty::adjustment::Adjust::ReifyFnPointer),
|
|
|
|
ty::adjustment::Adjust::UnsafeFnPointer =>
|
|
|
|
Some(ty::adjustment::Adjust::UnsafeFnPointer),
|
|
|
|
ty::adjustment::Adjust::ClosureFnPointer =>
|
|
|
|
Some(ty::adjustment::Adjust::ClosureFnPointer),
|
|
|
|
ty::adjustment::Adjust::MutToConstPointer =>
|
|
|
|
Some(ty::adjustment::Adjust::MutToConstPointer),
|
2017-05-27 10:29:24 +03:00
|
|
|
ty::adjustment::Adjust::Unsize =>
|
|
|
|
Some(ty::adjustment::Adjust::Unsize),
|
|
|
|
ty::adjustment::Adjust::Deref(ref overloaded) => {
|
|
|
|
tcx.lift(overloaded).map(ty::adjustment::Adjust::Deref)
|
|
|
|
}
|
|
|
|
ty::adjustment::Adjust::Borrow(ref autoref) => {
|
|
|
|
tcx.lift(autoref).map(ty::adjustment::Adjust::Borrow)
|
2017-05-20 20:03:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::OverloadedDeref<'a> {
|
|
|
|
type Lifted = ty::adjustment::OverloadedDeref<'tcx>;
|
|
|
|
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
2017-05-27 10:29:24 +03:00
|
|
|
tcx.lift(&self.region).map(|region| {
|
2017-05-20 20:03:04 +03:00
|
|
|
ty::adjustment::OverloadedDeref {
|
|
|
|
region,
|
|
|
|
mutbl: self.mutbl,
|
2016-05-02 18:07:47 +03:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-20 06:33:20 +03:00
|
|
|
impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::AutoBorrow<'a> {
|
|
|
|
type Lifted = ty::adjustment::AutoBorrow<'tcx>;
|
2016-05-02 18:07:47 +03:00
|
|
|
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
|
|
|
match *self {
|
2016-10-20 06:33:20 +03:00
|
|
|
ty::adjustment::AutoBorrow::Ref(r, m) => {
|
|
|
|
tcx.lift(&r).map(|r| ty::adjustment::AutoBorrow::Ref(r, m))
|
2016-05-02 18:07:47 +03:00
|
|
|
}
|
2016-10-20 06:33:20 +03:00
|
|
|
ty::adjustment::AutoBorrow::RawPtr(m) => {
|
|
|
|
Some(ty::adjustment::AutoBorrow::RawPtr(m))
|
2016-05-02 18:07:47 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-26 14:34:03 +01:00
|
|
|
impl<'a, 'tcx> Lift<'tcx> for ty::GenSig<'a> {
|
|
|
|
type Lifted = ty::GenSig<'tcx>;
|
|
|
|
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
2017-07-11 12:57:05 -07:00
|
|
|
tcx.lift(&(self.yield_ty, self.return_ty))
|
|
|
|
.map(|(yield_ty, return_ty)| {
|
2017-07-05 14:57:26 -07:00
|
|
|
ty::GenSig {
|
2017-07-10 21:11:31 +02:00
|
|
|
yield_ty,
|
2017-07-05 14:57:26 -07:00
|
|
|
return_ty,
|
|
|
|
}
|
|
|
|
})
|
2016-12-26 14:34:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-02 18:07:47 +03:00
|
|
|
impl<'a, 'tcx> Lift<'tcx> for ty::FnSig<'a> {
|
|
|
|
type Lifted = ty::FnSig<'tcx>;
|
|
|
|
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
2016-11-28 20:25:33 -07:00
|
|
|
tcx.lift(&self.inputs_and_output).map(|x| {
|
|
|
|
ty::FnSig {
|
|
|
|
inputs_and_output: x,
|
2017-02-13 10:51:06 +02:00
|
|
|
variadic: self.variadic,
|
2016-05-02 18:07:47 +03:00
|
|
|
unsafety: self.unsafety,
|
2017-02-13 10:51:06 +02:00
|
|
|
abi: self.abi,
|
2016-05-02 18:07:47 +03:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-29 06:00:23 +03:00
|
|
|
impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for ty::error::ExpectedFound<T> {
|
|
|
|
type Lifted = ty::error::ExpectedFound<T::Lifted>;
|
|
|
|
fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
|
|
|
tcx.lift(&self.expected).and_then(|expected| {
|
|
|
|
tcx.lift(&self.found).map(|found| {
|
|
|
|
ty::error::ExpectedFound {
|
2017-07-03 11:19:51 -07:00
|
|
|
expected,
|
|
|
|
found,
|
2016-04-29 06:00:23 +03:00
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, 'tcx> Lift<'tcx> for ty::error::TypeError<'a> {
|
|
|
|
type Lifted = ty::error::TypeError<'tcx>;
|
|
|
|
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
|
|
|
use ty::error::TypeError::*;
|
|
|
|
|
|
|
|
Some(match *self {
|
|
|
|
Mismatch => Mismatch,
|
|
|
|
UnsafetyMismatch(x) => UnsafetyMismatch(x),
|
|
|
|
AbiMismatch(x) => AbiMismatch(x),
|
|
|
|
Mutability => Mutability,
|
|
|
|
TupleSize(x) => TupleSize(x),
|
|
|
|
FixedArraySize(x) => FixedArraySize(x),
|
|
|
|
ArgCount => ArgCount,
|
2016-08-25 23:58:52 +03:00
|
|
|
RegionsDoesNotOutlive(a, b) => {
|
|
|
|
return tcx.lift(&(a, b)).map(|(a, b)| RegionsDoesNotOutlive(a, b))
|
|
|
|
}
|
2017-07-29 17:19:57 +03:00
|
|
|
RegionsInsufficientlyPolymorphic(a, b) => {
|
|
|
|
return tcx.lift(&b).map(|b| RegionsInsufficientlyPolymorphic(a, b))
|
2016-08-25 23:58:52 +03:00
|
|
|
}
|
2017-07-29 17:19:57 +03:00
|
|
|
RegionsOverlyPolymorphic(a, b) => {
|
|
|
|
return tcx.lift(&b).map(|b| RegionsOverlyPolymorphic(a, b))
|
2016-04-29 06:00:23 +03:00
|
|
|
}
|
|
|
|
IntMismatch(x) => IntMismatch(x),
|
|
|
|
FloatMismatch(x) => FloatMismatch(x),
|
|
|
|
Traits(x) => Traits(x),
|
|
|
|
VariadicMismatch(x) => VariadicMismatch(x),
|
2017-11-17 11:13:13 -05:00
|
|
|
CyclicTy(t) => return tcx.lift(&t).map(|t| CyclicTy(t)),
|
2017-07-11 10:33:09 -04:00
|
|
|
ProjectionMismatched(x) => ProjectionMismatched(x),
|
2016-04-29 06:00:23 +03:00
|
|
|
ProjectionBoundsLength(x) => ProjectionBoundsLength(x),
|
|
|
|
|
|
|
|
Sorts(ref x) => return tcx.lift(x).map(Sorts),
|
2017-08-30 16:06:05 -04:00
|
|
|
OldStyleLUB(ref x) => return tcx.lift(x).map(OldStyleLUB),
|
2017-07-16 04:55:48 -04:00
|
|
|
ExistentialMismatch(ref x) => return tcx.lift(x).map(ExistentialMismatch)
|
2016-04-29 06:00:23 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-07 08:08:53 +03:00
|
|
|
impl<'a, 'tcx> Lift<'tcx> for ConstEvalErr<'a> {
|
|
|
|
type Lifted = ConstEvalErr<'tcx>;
|
|
|
|
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
2018-01-31 10:39:30 +01:00
|
|
|
tcx.lift(&*self.kind).map(|kind| {
|
2017-08-07 08:08:53 +03:00
|
|
|
ConstEvalErr {
|
|
|
|
span: self.span,
|
2018-01-31 10:39:30 +01:00
|
|
|
kind: Rc::new(kind),
|
2017-08-07 08:08:53 +03:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-16 09:13:50 +01:00
|
|
|
impl<'a, 'tcx> Lift<'tcx> for interpret::EvalError<'a> {
|
|
|
|
type Lifted = interpret::EvalError<'tcx>;
|
|
|
|
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
2018-01-02 23:22:09 +00:00
|
|
|
use ::mir::interpret::EvalErrorKind::*;
|
2018-01-31 10:39:30 +01:00
|
|
|
let kind = match self.kind {
|
2018-01-16 09:13:50 +01:00
|
|
|
MachineError(ref err) => MachineError(err.clone()),
|
|
|
|
FunctionPointerTyMismatch(a, b) => FunctionPointerTyMismatch(
|
|
|
|
tcx.lift(&a)?,
|
|
|
|
tcx.lift(&b)?,
|
|
|
|
),
|
|
|
|
NoMirFor(ref s) => NoMirFor(s.clone()),
|
|
|
|
UnterminatedCString(ptr) => UnterminatedCString(ptr),
|
|
|
|
DanglingPointerDeref => DanglingPointerDeref,
|
|
|
|
DoubleFree => DoubleFree,
|
|
|
|
InvalidMemoryAccess => InvalidMemoryAccess,
|
|
|
|
InvalidFunctionPointer => InvalidFunctionPointer,
|
|
|
|
InvalidBool => InvalidBool,
|
|
|
|
InvalidDiscriminant => InvalidDiscriminant,
|
|
|
|
PointerOutOfBounds {
|
|
|
|
ptr,
|
|
|
|
access,
|
|
|
|
allocation_size,
|
|
|
|
} => PointerOutOfBounds { ptr, access, allocation_size },
|
|
|
|
InvalidNullPointerUsage => InvalidNullPointerUsage,
|
|
|
|
ReadPointerAsBytes => ReadPointerAsBytes,
|
|
|
|
ReadBytesAsPointer => ReadBytesAsPointer,
|
|
|
|
InvalidPointerMath => InvalidPointerMath,
|
|
|
|
ReadUndefBytes => ReadUndefBytes,
|
|
|
|
DeadLocal => DeadLocal,
|
|
|
|
InvalidBoolOp(bop) => InvalidBoolOp(bop),
|
|
|
|
Unimplemented(ref s) => Unimplemented(s.clone()),
|
|
|
|
DerefFunctionPointer => DerefFunctionPointer,
|
|
|
|
ExecuteMemory => ExecuteMemory,
|
|
|
|
ArrayIndexOutOfBounds(sp, a, b) => ArrayIndexOutOfBounds(sp, a, b),
|
|
|
|
Math(sp, ref err) => Math(sp, err.clone()),
|
|
|
|
Intrinsic(ref s) => Intrinsic(s.clone()),
|
|
|
|
OverflowingMath => OverflowingMath,
|
|
|
|
InvalidChar(c) => InvalidChar(c),
|
|
|
|
OutOfMemory {
|
|
|
|
allocation_size,
|
|
|
|
memory_size,
|
|
|
|
memory_usage,
|
|
|
|
} => OutOfMemory { allocation_size, memory_size, memory_usage },
|
|
|
|
ExecutionTimeLimitReached => ExecutionTimeLimitReached,
|
|
|
|
StackFrameLimitReached => StackFrameLimitReached,
|
|
|
|
OutOfTls => OutOfTls,
|
|
|
|
TlsOutOfBounds => TlsOutOfBounds,
|
|
|
|
AbiViolation(ref s) => AbiViolation(s.clone()),
|
|
|
|
AlignmentCheckFailed {
|
|
|
|
required,
|
|
|
|
has,
|
|
|
|
} => AlignmentCheckFailed { required, has },
|
|
|
|
MemoryLockViolation {
|
|
|
|
ptr,
|
|
|
|
len,
|
|
|
|
frame,
|
|
|
|
access,
|
|
|
|
ref lock,
|
|
|
|
} => MemoryLockViolation { ptr, len, frame, access, lock: lock.clone() },
|
|
|
|
MemoryAcquireConflict {
|
|
|
|
ptr,
|
|
|
|
len,
|
|
|
|
kind,
|
|
|
|
ref lock,
|
|
|
|
} => MemoryAcquireConflict { ptr, len, kind, lock: lock.clone() },
|
|
|
|
InvalidMemoryLockRelease {
|
|
|
|
ptr,
|
|
|
|
len,
|
|
|
|
frame,
|
|
|
|
ref lock,
|
|
|
|
} => InvalidMemoryLockRelease { ptr, len, frame, lock: lock.clone() },
|
|
|
|
DeallocatedLockedMemory {
|
|
|
|
ptr,
|
|
|
|
ref lock,
|
|
|
|
} => DeallocatedLockedMemory { ptr, lock: lock.clone() },
|
|
|
|
ValidationFailure(ref s) => ValidationFailure(s.clone()),
|
|
|
|
CalledClosureAsFunction => CalledClosureAsFunction,
|
|
|
|
VtableForArgumentlessMethod => VtableForArgumentlessMethod,
|
|
|
|
ModifiedConstantMemory => ModifiedConstantMemory,
|
|
|
|
AssumptionNotHeld => AssumptionNotHeld,
|
|
|
|
InlineAsm => InlineAsm,
|
|
|
|
TypeNotPrimitive(ty) => TypeNotPrimitive(tcx.lift(&ty)?),
|
|
|
|
ReallocatedWrongMemoryKind(ref a, ref b) => {
|
|
|
|
ReallocatedWrongMemoryKind(a.clone(), b.clone())
|
|
|
|
},
|
|
|
|
DeallocatedWrongMemoryKind(ref a, ref b) => {
|
|
|
|
DeallocatedWrongMemoryKind(a.clone(), b.clone())
|
|
|
|
},
|
|
|
|
ReallocateNonBasePtr => ReallocateNonBasePtr,
|
|
|
|
DeallocateNonBasePtr => DeallocateNonBasePtr,
|
|
|
|
IncorrectAllocationInformation(a, b, c, d) => {
|
|
|
|
IncorrectAllocationInformation(a, b, c, d)
|
|
|
|
},
|
|
|
|
Layout(lay) => Layout(tcx.lift(&lay)?),
|
|
|
|
HeapAllocZeroBytes => HeapAllocZeroBytes,
|
|
|
|
HeapAllocNonPowerOfTwoAlignment(n) => HeapAllocNonPowerOfTwoAlignment(n),
|
|
|
|
Unreachable => Unreachable,
|
|
|
|
Panic => Panic,
|
|
|
|
ReadFromReturnPointer => ReadFromReturnPointer,
|
|
|
|
PathNotFound(ref v) => PathNotFound(v.clone()),
|
|
|
|
UnimplementedTraitSelection => UnimplementedTraitSelection,
|
|
|
|
TypeckError => TypeckError,
|
|
|
|
};
|
|
|
|
Some(interpret::EvalError {
|
2018-01-31 10:39:30 +01:00
|
|
|
kind: kind,
|
2018-01-16 09:13:50 +01:00
|
|
|
backtrace: self.backtrace.clone(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-07 08:08:53 +03:00
|
|
|
impl<'a, 'tcx> Lift<'tcx> for const_val::ErrKind<'a> {
|
|
|
|
type Lifted = const_val::ErrKind<'tcx>;
|
|
|
|
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
|
|
|
use middle::const_val::ErrKind::*;
|
|
|
|
|
|
|
|
Some(match *self {
|
|
|
|
NonConstPath => NonConstPath,
|
|
|
|
UnimplementedConstVal(s) => UnimplementedConstVal(s),
|
|
|
|
IndexOutOfBounds { len, index } => IndexOutOfBounds { len, index },
|
|
|
|
Math(ref e) => Math(e.clone()),
|
|
|
|
|
|
|
|
LayoutError(ref e) => {
|
|
|
|
return tcx.lift(e).map(LayoutError)
|
|
|
|
}
|
|
|
|
|
|
|
|
TypeckError => TypeckError,
|
2017-11-24 18:50:17 +09:00
|
|
|
CheckMatchError => CheckMatchError,
|
2018-01-31 10:39:30 +01:00
|
|
|
Miri(ref e, ref frames) => return tcx.lift(e).map(|e| Miri(e, frames.clone())),
|
2017-08-07 08:08:53 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, 'tcx> Lift<'tcx> for ty::layout::LayoutError<'a> {
|
|
|
|
type Lifted = ty::layout::LayoutError<'tcx>;
|
|
|
|
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
|
|
|
match *self {
|
|
|
|
ty::layout::LayoutError::Unknown(ref ty) => {
|
|
|
|
tcx.lift(ty).map(ty::layout::LayoutError::Unknown)
|
|
|
|
}
|
|
|
|
ty::layout::LayoutError::SizeOverflow(ref ty) => {
|
|
|
|
tcx.lift(ty).map(ty::layout::LayoutError::SizeOverflow)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-02 23:22:09 +00:00
|
|
|
impl<'a, 'tcx> Lift<'tcx> for ty::InstanceDef<'a> {
|
|
|
|
type Lifted = ty::InstanceDef<'tcx>;
|
|
|
|
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
|
|
|
match *self {
|
|
|
|
ty::InstanceDef::Item(def_id) =>
|
|
|
|
Some(ty::InstanceDef::Item(def_id)),
|
|
|
|
ty::InstanceDef::Intrinsic(def_id) =>
|
|
|
|
Some(ty::InstanceDef::Intrinsic(def_id)),
|
|
|
|
ty::InstanceDef::FnPtrShim(def_id, ref 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::ClosureOnceShim { call_once } =>
|
|
|
|
Some(ty::InstanceDef::ClosureOnceShim { call_once }),
|
|
|
|
ty::InstanceDef::DropGlue(def_id, ref ty) =>
|
|
|
|
Some(ty::InstanceDef::DropGlue(def_id, tcx.lift(ty)?)),
|
|
|
|
ty::InstanceDef::CloneShim(def_id, ref ty) =>
|
|
|
|
Some(ty::InstanceDef::CloneShim(def_id, tcx.lift(ty)?)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BraceStructLiftImpl! {
|
|
|
|
impl<'a, 'tcx> Lift<'tcx> for ty::Instance<'a> {
|
|
|
|
type Lifted = ty::Instance<'tcx>;
|
|
|
|
def, substs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BraceStructLiftImpl! {
|
|
|
|
impl<'a, 'tcx> Lift<'tcx> for interpret::GlobalId<'a> {
|
|
|
|
type Lifted = interpret::GlobalId<'tcx>;
|
|
|
|
instance, promoted
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-06 21:51:58 +03:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// TypeFoldable implementations.
|
|
|
|
//
|
|
|
|
// Ideally, each type should invoke `folder.fold_foo(self)` and
|
|
|
|
// nothing else. In some cases, though, we haven't gotten around to
|
|
|
|
// adding methods on the `folder` yet, and thus the folding is
|
|
|
|
// hard-coded here. This is less-flexible, because folders cannot
|
|
|
|
// override the behavior, but there are a lot of random types and one
|
|
|
|
// can easily refactor the folding into the TypeFolder trait as
|
|
|
|
// needed.
|
|
|
|
|
|
|
|
impl<'tcx, T:TypeFoldable<'tcx>, U:TypeFoldable<'tcx>> TypeFoldable<'tcx> for (T, U) {
|
2016-04-29 06:00:23 +03:00
|
|
|
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> (T, U) {
|
2015-09-06 21:51:58 +03:00
|
|
|
(self.0.fold_with(folder), self.1.fold_with(folder))
|
|
|
|
}
|
2015-11-18 09:38:57 +00:00
|
|
|
|
2016-01-06 02:01:28 +00:00
|
|
|
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
2015-11-18 09:38:57 +00:00
|
|
|
self.0.visit_with(visitor) || self.1.visit_with(visitor)
|
|
|
|
}
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Option<T> {
|
2016-04-29 06:00:23 +03:00
|
|
|
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
2015-09-06 21:51:58 +03:00
|
|
|
self.as_ref().map(|t| t.fold_with(folder))
|
|
|
|
}
|
2015-11-18 09:38:57 +00:00
|
|
|
|
2016-01-06 02:01:28 +00:00
|
|
|
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
2015-11-18 09:38:57 +00:00
|
|
|
self.iter().any(|t| t.visit_with(visitor))
|
|
|
|
}
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Rc<T> {
|
2016-04-29 06:00:23 +03:00
|
|
|
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
2015-09-06 21:51:58 +03:00
|
|
|
Rc::new((**self).fold_with(folder))
|
|
|
|
}
|
2015-11-18 09:38:57 +00:00
|
|
|
|
2016-01-06 02:01:28 +00:00
|
|
|
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
2015-11-18 09:38:57 +00:00
|
|
|
(**self).visit_with(visitor)
|
|
|
|
}
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Box<T> {
|
2016-04-29 06:00:23 +03:00
|
|
|
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
2015-09-06 21:51:58 +03:00
|
|
|
let content: T = (**self).fold_with(folder);
|
|
|
|
box content
|
|
|
|
}
|
2015-11-18 09:38:57 +00:00
|
|
|
|
2016-01-06 02:01:28 +00:00
|
|
|
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
2015-11-18 09:38:57 +00:00
|
|
|
(**self).visit_with(visitor)
|
|
|
|
}
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Vec<T> {
|
2016-04-29 06:00:23 +03:00
|
|
|
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
2015-09-06 21:51:58 +03:00
|
|
|
self.iter().map(|t| t.fold_with(folder)).collect()
|
|
|
|
}
|
2015-11-18 09:38:57 +00:00
|
|
|
|
2016-01-06 02:01:28 +00:00
|
|
|
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
2015-11-18 09:38:57 +00:00
|
|
|
self.iter().any(|t| t.visit_with(visitor))
|
|
|
|
}
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx, T:TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::Binder<T> {
|
2016-04-29 06:00:23 +03:00
|
|
|
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
2016-01-08 23:34:05 +00:00
|
|
|
ty::Binder(self.0.fold_with(folder))
|
2015-11-18 09:38:57 +00:00
|
|
|
}
|
|
|
|
|
2016-04-29 06:00:23 +03:00
|
|
|
fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
2016-01-06 02:01:28 +00:00
|
|
|
folder.fold_binder(self)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
2016-01-08 23:34:05 +00:00
|
|
|
self.0.visit_with(visitor)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
|
|
|
visitor.visit_binder(self)
|
2015-11-18 09:38:57 +00:00
|
|
|
}
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2017-07-15 07:23:28 -04:00
|
|
|
impl<'tcx> TypeFoldable<'tcx> for ty::ParamEnv<'tcx> {
|
|
|
|
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
|
|
|
ty::ParamEnv {
|
|
|
|
reveal: self.reveal,
|
|
|
|
caller_bounds: self.caller_bounds.fold_with(folder),
|
|
|
|
universe: self.universe.fold_with(folder),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
|
|
|
let &ty::ParamEnv { reveal: _, ref universe, ref caller_bounds } = self;
|
|
|
|
universe.super_visit_with(visitor) || caller_bounds.super_visit_with(visitor)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx> TypeFoldable<'tcx> for ty::UniverseIndex {
|
|
|
|
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, _folder: &mut F) -> Self {
|
|
|
|
*self
|
|
|
|
}
|
|
|
|
|
|
|
|
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _visitor: &mut V) -> bool {
|
|
|
|
false
|
|
|
|
}
|
2017-05-23 04:19:47 -04:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:21:49 -07:00
|
|
|
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::Slice<ty::ExistentialPredicate<'tcx>> {
|
2016-04-29 06:00:23 +03:00
|
|
|
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
2016-11-16 09:21:49 -07:00
|
|
|
let v = self.iter().map(|p| p.fold_with(folder)).collect::<AccumulateVec<[_; 8]>>();
|
|
|
|
folder.tcx().intern_existential_predicates(&v)
|
2015-11-18 09:38:57 +00:00
|
|
|
}
|
|
|
|
|
2016-01-06 02:01:28 +00:00
|
|
|
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
2016-11-16 09:21:49 -07:00
|
|
|
self.iter().any(|p| p.visit_with(visitor))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx> TypeFoldable<'tcx> for ty::ExistentialPredicate<'tcx> {
|
|
|
|
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
|
|
|
use ty::ExistentialPredicate::*;
|
|
|
|
match *self {
|
|
|
|
Trait(ref tr) => Trait(tr.fold_with(folder)),
|
|
|
|
Projection(ref p) => Projection(p.fold_with(folder)),
|
|
|
|
AutoTrait(did) => AutoTrait(did),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
|
|
|
match *self {
|
|
|
|
ty::ExistentialPredicate::Trait(ref tr) => tr.visit_with(visitor),
|
|
|
|
ty::ExistentialPredicate::Projection(ref p) => p.visit_with(visitor),
|
|
|
|
ty::ExistentialPredicate::AutoTrait(_) => false,
|
|
|
|
}
|
2015-11-18 09:38:57 +00:00
|
|
|
}
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2016-09-02 11:08:16 +03:00
|
|
|
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::Slice<Ty<'tcx>> {
|
2016-04-29 08:30:54 +03:00
|
|
|
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
2016-10-24 18:23:29 -06:00
|
|
|
let v = self.iter().map(|t| t.fold_with(folder)).collect::<AccumulateVec<[_; 8]>>();
|
|
|
|
folder.tcx().intern_type_list(&v)
|
2016-04-29 08:30:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
|
|
|
self.iter().any(|t| t.visit_with(visitor))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-16 09:24:38 +01:00
|
|
|
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::*;
|
|
|
|
Self {
|
|
|
|
substs: self.substs.fold_with(folder),
|
|
|
|
def: match self.def {
|
|
|
|
Item(did) => Item(did.fold_with(folder)),
|
|
|
|
Intrinsic(did) => Intrinsic(did.fold_with(folder)),
|
|
|
|
FnPtrShim(did, ty) => FnPtrShim(
|
|
|
|
did.fold_with(folder),
|
|
|
|
ty.fold_with(folder),
|
|
|
|
),
|
|
|
|
Virtual(did, i) => Virtual(
|
|
|
|
did.fold_with(folder),
|
|
|
|
i,
|
|
|
|
),
|
|
|
|
ClosureOnceShim { call_once } => ClosureOnceShim {
|
|
|
|
call_once: call_once.fold_with(folder),
|
|
|
|
},
|
|
|
|
DropGlue(did, ty) => DropGlue(
|
|
|
|
did.fold_with(folder),
|
|
|
|
ty.fold_with(folder),
|
|
|
|
),
|
|
|
|
CloneShim(did, ty) => CloneShim(
|
|
|
|
did.fold_with(folder),
|
|
|
|
ty.fold_with(folder),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
|
|
|
use ty::InstanceDef::*;
|
|
|
|
self.substs.visit_with(visitor) ||
|
|
|
|
match self.def {
|
|
|
|
Item(did) => did.visit_with(visitor),
|
|
|
|
Intrinsic(did) => did.visit_with(visitor),
|
|
|
|
FnPtrShim(did, ty) => {
|
|
|
|
did.visit_with(visitor) ||
|
|
|
|
ty.visit_with(visitor)
|
|
|
|
},
|
|
|
|
Virtual(did, _) => did.visit_with(visitor),
|
|
|
|
ClosureOnceShim { call_once } => call_once.visit_with(visitor),
|
|
|
|
DropGlue(did, ty) => {
|
|
|
|
did.visit_with(visitor) ||
|
|
|
|
ty.visit_with(visitor)
|
|
|
|
},
|
|
|
|
CloneShim(did, ty) => {
|
|
|
|
did.visit_with(visitor) ||
|
|
|
|
ty.visit_with(visitor)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-02 23:22:09 +00:00
|
|
|
impl<'tcx> TypeFoldable<'tcx> for interpret::GlobalId<'tcx> {
|
|
|
|
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
|
|
|
Self {
|
|
|
|
instance: self.instance.fold_with(folder),
|
|
|
|
promoted: self.promoted
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
|
|
|
self.instance.visit_with(visitor)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-06 21:51:58 +03:00
|
|
|
impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
|
2016-04-29 06:00:23 +03:00
|
|
|
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
2015-11-18 09:38:57 +00:00
|
|
|
let sty = match self.sty {
|
2016-04-29 08:30:54 +03:00
|
|
|
ty::TyRawPtr(tm) => ty::TyRawPtr(tm.fold_with(folder)),
|
2017-08-05 16:11:24 +03:00
|
|
|
ty::TyArray(typ, sz) => ty::TyArray(typ.fold_with(folder), sz.fold_with(folder)),
|
2015-11-18 09:38:57 +00:00
|
|
|
ty::TySlice(typ) => ty::TySlice(typ.fold_with(folder)),
|
2016-09-06 01:26:02 +03:00
|
|
|
ty::TyAdt(tid, substs) => ty::TyAdt(tid, substs.fold_with(folder)),
|
2016-11-16 09:21:49 -07:00
|
|
|
ty::TyDynamic(ref trait_ty, ref region) =>
|
|
|
|
ty::TyDynamic(trait_ty.fold_with(folder), region.fold_with(folder)),
|
2017-01-11 15:58:37 +08:00
|
|
|
ty::TyTuple(ts, defaulted) => ty::TyTuple(ts.fold_with(folder), defaulted),
|
2017-05-13 17:11:52 +03:00
|
|
|
ty::TyFnDef(def_id, substs) => {
|
|
|
|
ty::TyFnDef(def_id, substs.fold_with(folder))
|
2015-06-13 13:15:03 -07:00
|
|
|
}
|
2016-04-29 08:30:54 +03:00
|
|
|
ty::TyFnPtr(f) => ty::TyFnPtr(f.fold_with(folder)),
|
|
|
|
ty::TyRef(ref r, tm) => {
|
|
|
|
ty::TyRef(r.fold_with(folder), tm.fold_with(folder))
|
2015-11-18 09:38:57 +00:00
|
|
|
}
|
2017-07-05 14:57:26 -07:00
|
|
|
ty::TyGenerator(did, substs, interior) => {
|
|
|
|
ty::TyGenerator(did, substs.fold_with(folder), interior.fold_with(folder))
|
|
|
|
}
|
2017-10-07 16:36:28 +02:00
|
|
|
ty::TyGeneratorWitness(types) => ty::TyGeneratorWitness(types.fold_with(folder)),
|
2016-04-29 08:30:54 +03:00
|
|
|
ty::TyClosure(did, substs) => ty::TyClosure(did, substs.fold_with(folder)),
|
2015-11-18 09:38:57 +00:00
|
|
|
ty::TyProjection(ref data) => ty::TyProjection(data.fold_with(folder)),
|
2016-07-22 18:56:22 +03:00
|
|
|
ty::TyAnon(did, substs) => ty::TyAnon(did, substs.fold_with(folder)),
|
2015-11-18 09:38:57 +00:00
|
|
|
ty::TyBool | ty::TyChar | ty::TyStr | ty::TyInt(_) |
|
|
|
|
ty::TyUint(_) | ty::TyFloat(_) | ty::TyError | ty::TyInfer(_) |
|
2017-09-03 19:53:58 +01:00
|
|
|
ty::TyParam(..) | ty::TyNever | ty::TyForeign(..) => return self
|
2015-11-18 09:38:57 +00:00
|
|
|
};
|
2016-11-24 21:10:08 +11:00
|
|
|
|
|
|
|
if self.sty == sty {
|
|
|
|
self
|
|
|
|
} else {
|
|
|
|
folder.tcx().mk_ty(sty)
|
|
|
|
}
|
2015-11-18 09:38:57 +00:00
|
|
|
}
|
|
|
|
|
2016-04-29 06:00:23 +03:00
|
|
|
fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
2016-01-06 02:01:28 +00:00
|
|
|
folder.fold_ty(*self)
|
2015-11-18 09:38:57 +00:00
|
|
|
}
|
|
|
|
|
2016-01-06 02:01:28 +00:00
|
|
|
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
2015-11-18 09:38:57 +00:00
|
|
|
match self.sty {
|
|
|
|
ty::TyRawPtr(ref tm) => tm.visit_with(visitor),
|
2017-08-05 16:11:24 +03:00
|
|
|
ty::TyArray(typ, sz) => typ.visit_with(visitor) || sz.visit_with(visitor),
|
2015-11-18 09:38:57 +00:00
|
|
|
ty::TySlice(typ) => typ.visit_with(visitor),
|
2016-09-06 01:26:02 +03:00
|
|
|
ty::TyAdt(_, substs) => substs.visit_with(visitor),
|
2016-11-16 09:21:49 -07:00
|
|
|
ty::TyDynamic(ref trait_ty, ref reg) =>
|
|
|
|
trait_ty.visit_with(visitor) || reg.visit_with(visitor),
|
2017-01-11 15:58:37 +08:00
|
|
|
ty::TyTuple(ts, _) => ts.visit_with(visitor),
|
2017-05-13 17:11:52 +03:00
|
|
|
ty::TyFnDef(_, substs) => substs.visit_with(visitor),
|
2016-02-16 18:36:41 +02:00
|
|
|
ty::TyFnPtr(ref f) => f.visit_with(visitor),
|
2015-11-18 09:38:57 +00:00
|
|
|
ty::TyRef(r, ref tm) => r.visit_with(visitor) || tm.visit_with(visitor),
|
2017-07-05 14:57:26 -07:00
|
|
|
ty::TyGenerator(_did, ref substs, ref interior) => {
|
|
|
|
substs.visit_with(visitor) || interior.visit_with(visitor)
|
|
|
|
}
|
2017-10-07 16:36:28 +02:00
|
|
|
ty::TyGeneratorWitness(ref types) => types.visit_with(visitor),
|
2015-11-18 09:38:57 +00:00
|
|
|
ty::TyClosure(_did, ref substs) => substs.visit_with(visitor),
|
|
|
|
ty::TyProjection(ref data) => data.visit_with(visitor),
|
2016-07-22 18:56:22 +03:00
|
|
|
ty::TyAnon(_, ref substs) => substs.visit_with(visitor),
|
2015-11-18 09:38:57 +00:00
|
|
|
ty::TyBool | ty::TyChar | ty::TyStr | ty::TyInt(_) |
|
|
|
|
ty::TyUint(_) | ty::TyFloat(_) | ty::TyError | ty::TyInfer(_) |
|
2017-09-03 19:53:58 +01:00
|
|
|
ty::TyParam(..) | ty::TyNever | ty::TyForeign(..) => false,
|
2015-11-18 09:38:57 +00:00
|
|
|
}
|
|
|
|
}
|
2015-09-06 21:51:58 +03:00
|
|
|
|
2016-01-06 02:01:28 +00:00
|
|
|
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
|
|
|
visitor.visit_ty(self)
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
2016-01-06 02:01:28 +00:00
|
|
|
}
|
2015-11-18 09:38:57 +00:00
|
|
|
|
2015-09-06 21:51:58 +03:00
|
|
|
impl<'tcx> TypeFoldable<'tcx> for ty::TypeAndMut<'tcx> {
|
2016-04-29 06:00:23 +03:00
|
|
|
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
2016-01-06 02:01:28 +00:00
|
|
|
ty::TypeAndMut { ty: self.ty.fold_with(folder), mutbl: self.mutbl }
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
2015-11-18 09:38:57 +00:00
|
|
|
|
2016-01-06 02:01:28 +00:00
|
|
|
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
2015-11-18 09:38:57 +00:00
|
|
|
self.ty.visit_with(visitor)
|
|
|
|
}
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2017-11-11 13:04:36 -05:00
|
|
|
BraceStructTypeFoldableImpl! {
|
|
|
|
impl<'tcx> TypeFoldable<'tcx> for ty::GenSig<'tcx> {
|
|
|
|
yield_ty, return_ty
|
2016-12-26 14:34:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-06 21:51:58 +03:00
|
|
|
impl<'tcx> TypeFoldable<'tcx> for ty::FnSig<'tcx> {
|
2016-04-29 06:00:23 +03:00
|
|
|
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
2016-11-28 20:25:33 -07:00
|
|
|
let inputs_and_output = self.inputs_and_output.fold_with(folder);
|
|
|
|
ty::FnSig {
|
|
|
|
inputs_and_output: folder.tcx().intern_type_list(&inputs_and_output),
|
|
|
|
variadic: self.variadic,
|
2017-02-13 10:51:06 +02:00
|
|
|
unsafety: self.unsafety,
|
|
|
|
abi: self.abi,
|
2016-11-28 20:25:33 -07:00
|
|
|
}
|
2015-11-18 09:38:57 +00:00
|
|
|
}
|
|
|
|
|
2016-01-06 02:01:28 +00:00
|
|
|
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
2016-11-28 20:25:33 -07:00
|
|
|
self.inputs().iter().any(|i| i.visit_with(visitor)) ||
|
|
|
|
self.output().visit_with(visitor)
|
2015-11-18 09:38:57 +00:00
|
|
|
}
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2017-11-11 13:04:36 -05:00
|
|
|
BraceStructTypeFoldableImpl! {
|
|
|
|
impl<'tcx> TypeFoldable<'tcx> for ty::TraitRef<'tcx> { def_id, substs }
|
2016-08-04 15:52:57 +03:00
|
|
|
}
|
|
|
|
|
2017-11-11 13:04:36 -05:00
|
|
|
BraceStructTypeFoldableImpl! {
|
|
|
|
impl<'tcx> TypeFoldable<'tcx> for ty::ExistentialTraitRef<'tcx> { def_id, substs }
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2017-11-11 13:04:36 -05:00
|
|
|
BraceStructTypeFoldableImpl! {
|
|
|
|
impl<'tcx> TypeFoldable<'tcx> for ty::ImplHeader<'tcx> {
|
|
|
|
impl_def_id,
|
|
|
|
self_ty,
|
|
|
|
trait_ref,
|
|
|
|
predicates,
|
2016-02-26 10:51:10 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-20 04:45:53 -04:00
|
|
|
impl<'tcx> TypeFoldable<'tcx> for ty::Region<'tcx> {
|
2016-04-29 06:00:23 +03:00
|
|
|
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, _folder: &mut F) -> Self {
|
2016-01-06 02:01:28 +00:00
|
|
|
*self
|
|
|
|
}
|
|
|
|
|
2016-04-29 06:00:23 +03:00
|
|
|
fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
2015-09-06 21:51:58 +03:00
|
|
|
folder.fold_region(*self)
|
|
|
|
}
|
2015-11-18 09:38:57 +00:00
|
|
|
|
2016-01-06 02:01:28 +00:00
|
|
|
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _visitor: &mut V) -> bool {
|
|
|
|
false
|
2015-11-18 09:38:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
|
|
|
visitor.visit_region(*self)
|
|
|
|
}
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx> TypeFoldable<'tcx> for ty::ClosureSubsts<'tcx> {
|
2016-04-29 06:00:23 +03:00
|
|
|
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
2015-09-06 21:51:58 +03:00
|
|
|
ty::ClosureSubsts {
|
2016-11-03 22:19:33 +02:00
|
|
|
substs: self.substs.fold_with(folder),
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
}
|
2015-11-18 09:38:57 +00:00
|
|
|
|
2016-01-06 02:01:28 +00:00
|
|
|
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
2016-11-03 22:19:33 +02:00
|
|
|
self.substs.visit_with(visitor)
|
2015-11-18 09:38:57 +00:00
|
|
|
}
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2016-12-26 14:34:03 +01:00
|
|
|
impl<'tcx> TypeFoldable<'tcx> for ty::GeneratorInterior<'tcx> {
|
|
|
|
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
2017-10-07 16:36:28 +02:00
|
|
|
ty::GeneratorInterior {
|
|
|
|
witness: self.witness.fold_with(folder),
|
|
|
|
movable: self.movable,
|
|
|
|
}
|
2016-12-26 14:34:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
2017-08-09 13:56:19 -07:00
|
|
|
self.witness.visit_with(visitor)
|
2016-12-26 14:34:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-11 13:04:36 -05:00
|
|
|
BraceStructTypeFoldableImpl! {
|
|
|
|
impl<'tcx> TypeFoldable<'tcx> for ty::adjustment::Adjustment<'tcx> {
|
|
|
|
kind,
|
|
|
|
target,
|
2017-05-20 20:03:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx> TypeFoldable<'tcx> for ty::adjustment::Adjust<'tcx> {
|
|
|
|
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
|
|
|
match *self {
|
|
|
|
ty::adjustment::Adjust::NeverToAny |
|
|
|
|
ty::adjustment::Adjust::ReifyFnPointer |
|
|
|
|
ty::adjustment::Adjust::UnsafeFnPointer |
|
|
|
|
ty::adjustment::Adjust::ClosureFnPointer |
|
2017-05-27 10:29:24 +03:00
|
|
|
ty::adjustment::Adjust::MutToConstPointer |
|
|
|
|
ty::adjustment::Adjust::Unsize => self.clone(),
|
|
|
|
ty::adjustment::Adjust::Deref(ref overloaded) => {
|
|
|
|
ty::adjustment::Adjust::Deref(overloaded.fold_with(folder))
|
|
|
|
}
|
|
|
|
ty::adjustment::Adjust::Borrow(ref autoref) => {
|
|
|
|
ty::adjustment::Adjust::Borrow(autoref.fold_with(folder))
|
2017-05-20 20:03:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
|
|
|
match *self {
|
|
|
|
ty::adjustment::Adjust::NeverToAny |
|
|
|
|
ty::adjustment::Adjust::ReifyFnPointer |
|
|
|
|
ty::adjustment::Adjust::UnsafeFnPointer |
|
|
|
|
ty::adjustment::Adjust::ClosureFnPointer |
|
2017-05-27 10:29:24 +03:00
|
|
|
ty::adjustment::Adjust::MutToConstPointer |
|
|
|
|
ty::adjustment::Adjust::Unsize => false,
|
|
|
|
ty::adjustment::Adjust::Deref(ref overloaded) => {
|
|
|
|
overloaded.visit_with(visitor)
|
|
|
|
}
|
|
|
|
ty::adjustment::Adjust::Borrow(ref autoref) => {
|
|
|
|
autoref.visit_with(visitor)
|
2017-05-20 20:03:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx> TypeFoldable<'tcx> for ty::adjustment::OverloadedDeref<'tcx> {
|
|
|
|
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
|
|
|
ty::adjustment::OverloadedDeref {
|
|
|
|
region: self.region.fold_with(folder),
|
|
|
|
mutbl: self.mutbl,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
2017-05-27 10:29:24 +03:00
|
|
|
self.region.visit_with(visitor)
|
2015-11-18 09:38:57 +00:00
|
|
|
}
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2016-10-20 06:33:20 +03:00
|
|
|
impl<'tcx> TypeFoldable<'tcx> for ty::adjustment::AutoBorrow<'tcx> {
|
2016-04-29 06:00:23 +03:00
|
|
|
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
2015-11-18 09:38:57 +00:00
|
|
|
match *self {
|
2016-10-20 06:33:20 +03:00
|
|
|
ty::adjustment::AutoBorrow::Ref(ref r, m) => {
|
|
|
|
ty::adjustment::AutoBorrow::Ref(r.fold_with(folder), m)
|
2015-11-18 09:38:57 +00:00
|
|
|
}
|
2016-10-20 06:33:20 +03:00
|
|
|
ty::adjustment::AutoBorrow::RawPtr(m) => ty::adjustment::AutoBorrow::RawPtr(m)
|
2015-11-18 09:38:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-06 02:01:28 +00:00
|
|
|
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
2015-11-18 09:38:57 +00:00
|
|
|
match *self {
|
2016-10-20 06:33:20 +03:00
|
|
|
ty::adjustment::AutoBorrow::Ref(r, _m) => r.visit_with(visitor),
|
|
|
|
ty::adjustment::AutoBorrow::RawPtr(_m) => false,
|
2015-11-18 09:38:57 +00:00
|
|
|
}
|
|
|
|
}
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2016-11-28 05:09:28 +02:00
|
|
|
|
2017-11-11 13:04:36 -05:00
|
|
|
BraceStructTypeFoldableImpl! {
|
|
|
|
impl<'tcx> TypeFoldable<'tcx> for ty::GenericPredicates<'tcx> {
|
|
|
|
parent, predicates
|
2016-11-28 05:09:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-23 04:19:47 -04:00
|
|
|
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::Slice<ty::Predicate<'tcx>> {
|
|
|
|
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
|
|
|
let v = self.iter().map(|p| p.fold_with(folder)).collect::<AccumulateVec<[_; 8]>>();
|
|
|
|
folder.tcx().intern_predicates(&v)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
|
|
|
self.iter().any(|p| p.visit_with(visitor))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-06 21:51:58 +03:00
|
|
|
impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> {
|
2016-04-29 06:00:23 +03:00
|
|
|
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
2015-09-06 21:51:58 +03:00
|
|
|
match *self {
|
|
|
|
ty::Predicate::Trait(ref a) =>
|
|
|
|
ty::Predicate::Trait(a.fold_with(folder)),
|
2017-03-09 21:47:09 -05:00
|
|
|
ty::Predicate::Subtype(ref binder) =>
|
|
|
|
ty::Predicate::Subtype(binder.fold_with(folder)),
|
2015-09-06 21:51:58 +03:00
|
|
|
ty::Predicate::RegionOutlives(ref binder) =>
|
|
|
|
ty::Predicate::RegionOutlives(binder.fold_with(folder)),
|
|
|
|
ty::Predicate::TypeOutlives(ref binder) =>
|
|
|
|
ty::Predicate::TypeOutlives(binder.fold_with(folder)),
|
|
|
|
ty::Predicate::Projection(ref binder) =>
|
|
|
|
ty::Predicate::Projection(binder.fold_with(folder)),
|
|
|
|
ty::Predicate::WellFormed(data) =>
|
|
|
|
ty::Predicate::WellFormed(data.fold_with(folder)),
|
2017-11-08 08:50:59 -05:00
|
|
|
ty::Predicate::ClosureKind(closure_def_id, closure_substs, kind) =>
|
|
|
|
ty::Predicate::ClosureKind(closure_def_id, closure_substs.fold_with(folder), kind),
|
2015-09-06 21:51:58 +03:00
|
|
|
ty::Predicate::ObjectSafe(trait_def_id) =>
|
|
|
|
ty::Predicate::ObjectSafe(trait_def_id),
|
2017-08-07 08:08:53 +03:00
|
|
|
ty::Predicate::ConstEvaluatable(def_id, substs) =>
|
|
|
|
ty::Predicate::ConstEvaluatable(def_id, substs.fold_with(folder)),
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
}
|
2015-11-18 09:38:57 +00:00
|
|
|
|
2016-01-06 02:01:28 +00:00
|
|
|
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
2015-11-18 09:38:57 +00:00
|
|
|
match *self {
|
|
|
|
ty::Predicate::Trait(ref a) => a.visit_with(visitor),
|
2017-03-09 21:47:09 -05:00
|
|
|
ty::Predicate::Subtype(ref binder) => binder.visit_with(visitor),
|
2015-11-18 09:38:57 +00:00
|
|
|
ty::Predicate::RegionOutlives(ref binder) => binder.visit_with(visitor),
|
|
|
|
ty::Predicate::TypeOutlives(ref binder) => binder.visit_with(visitor),
|
|
|
|
ty::Predicate::Projection(ref binder) => binder.visit_with(visitor),
|
|
|
|
ty::Predicate::WellFormed(data) => data.visit_with(visitor),
|
2017-11-08 08:50:59 -05:00
|
|
|
ty::Predicate::ClosureKind(_closure_def_id, closure_substs, _kind) =>
|
|
|
|
closure_substs.visit_with(visitor),
|
2015-11-18 09:38:57 +00:00
|
|
|
ty::Predicate::ObjectSafe(_trait_def_id) => false,
|
2017-08-07 08:08:53 +03:00
|
|
|
ty::Predicate::ConstEvaluatable(_def_id, substs) => substs.visit_with(visitor),
|
2015-11-18 09:38:57 +00:00
|
|
|
}
|
|
|
|
}
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2017-11-11 13:04:36 -05:00
|
|
|
BraceStructTypeFoldableImpl! {
|
|
|
|
impl<'tcx> TypeFoldable<'tcx> for ty::ProjectionPredicate<'tcx> {
|
|
|
|
projection_ty, ty
|
2015-11-18 09:38:57 +00:00
|
|
|
}
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2017-11-11 13:04:36 -05:00
|
|
|
BraceStructTypeFoldableImpl! {
|
|
|
|
impl<'tcx> TypeFoldable<'tcx> for ty::ExistentialProjection<'tcx> {
|
|
|
|
ty, substs, item_def_id
|
2016-08-04 15:52:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-11 13:04:36 -05:00
|
|
|
BraceStructTypeFoldableImpl! {
|
|
|
|
impl<'tcx> TypeFoldable<'tcx> for ty::ProjectionTy<'tcx> {
|
|
|
|
substs, item_def_id
|
2015-11-18 09:38:57 +00:00
|
|
|
}
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2017-11-11 13:04:36 -05:00
|
|
|
BraceStructTypeFoldableImpl! {
|
|
|
|
impl<'tcx> TypeFoldable<'tcx> for ty::InstantiatedPredicates<'tcx> {
|
|
|
|
predicates
|
2015-11-18 09:38:57 +00:00
|
|
|
}
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2017-03-09 21:47:09 -05:00
|
|
|
impl<'tcx> TypeFoldable<'tcx> for ty::SubtypePredicate<'tcx> {
|
|
|
|
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
|
|
|
ty::SubtypePredicate {
|
|
|
|
a_is_expected: self.a_is_expected,
|
|
|
|
a: self.a.fold_with(folder),
|
|
|
|
b: self.b.fold_with(folder)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
|
|
|
self.a.visit_with(visitor) || self.b.visit_with(visitor)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-06 21:51:58 +03:00
|
|
|
impl<'tcx> TypeFoldable<'tcx> for ty::TraitPredicate<'tcx> {
|
2016-04-29 06:00:23 +03:00
|
|
|
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
2015-09-06 21:51:58 +03:00
|
|
|
ty::TraitPredicate {
|
|
|
|
trait_ref: self.trait_ref.fold_with(folder)
|
|
|
|
}
|
|
|
|
}
|
2015-11-18 09:38:57 +00:00
|
|
|
|
2016-01-06 02:01:28 +00:00
|
|
|
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
2015-11-18 09:38:57 +00:00
|
|
|
self.trait_ref.visit_with(visitor)
|
|
|
|
}
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx,T,U> TypeFoldable<'tcx> for ty::OutlivesPredicate<T,U>
|
|
|
|
where T : TypeFoldable<'tcx>,
|
|
|
|
U : TypeFoldable<'tcx>,
|
|
|
|
{
|
2016-04-29 06:00:23 +03:00
|
|
|
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
2015-09-06 21:51:58 +03:00
|
|
|
ty::OutlivesPredicate(self.0.fold_with(folder),
|
|
|
|
self.1.fold_with(folder))
|
|
|
|
}
|
2015-11-18 09:38:57 +00:00
|
|
|
|
2016-01-06 02:01:28 +00:00
|
|
|
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
2015-11-18 09:38:57 +00:00
|
|
|
self.0.visit_with(visitor) || self.1.visit_with(visitor)
|
|
|
|
}
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx> TypeFoldable<'tcx> for ty::ClosureUpvar<'tcx> {
|
2016-04-29 06:00:23 +03:00
|
|
|
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
2015-09-06 21:51:58 +03:00
|
|
|
ty::ClosureUpvar {
|
|
|
|
def: self.def,
|
|
|
|
span: self.span,
|
|
|
|
ty: self.ty.fold_with(folder),
|
|
|
|
}
|
|
|
|
}
|
2015-11-18 09:38:57 +00:00
|
|
|
|
2016-01-06 02:01:28 +00:00
|
|
|
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
2015-11-18 09:38:57 +00:00
|
|
|
self.ty.visit_with(visitor)
|
|
|
|
}
|
2015-09-06 21:51:58 +03:00
|
|
|
}
|
|
|
|
|
2016-07-16 19:38:17 +03:00
|
|
|
impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::error::ExpectedFound<T> {
|
|
|
|
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
|
|
|
ty::error::ExpectedFound {
|
|
|
|
expected: self.expected.fold_with(folder),
|
|
|
|
found: self.found.fold_with(folder),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
|
|
|
self.expected.visit_with(visitor) || self.found.visit_with(visitor)
|
|
|
|
}
|
|
|
|
}
|
2017-02-08 22:19:22 +13:00
|
|
|
|
|
|
|
impl<'tcx, T: TypeFoldable<'tcx>, I: Idx> TypeFoldable<'tcx> for IndexVec<I, T> {
|
|
|
|
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
|
|
|
self.iter().map(|x| x.fold_with(folder)).collect()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
|
|
|
self.iter().any(|t| t.visit_with(visitor))
|
|
|
|
}
|
|
|
|
}
|
2017-07-08 23:24:00 +02:00
|
|
|
|
|
|
|
impl<'tcx> TypeFoldable<'tcx> for ty::error::TypeError<'tcx> {
|
|
|
|
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
|
|
|
use ty::error::TypeError::*;
|
|
|
|
|
|
|
|
match *self {
|
|
|
|
Mismatch => Mismatch,
|
|
|
|
UnsafetyMismatch(x) => UnsafetyMismatch(x.fold_with(folder)),
|
|
|
|
AbiMismatch(x) => AbiMismatch(x.fold_with(folder)),
|
|
|
|
Mutability => Mutability,
|
|
|
|
TupleSize(x) => TupleSize(x),
|
|
|
|
FixedArraySize(x) => FixedArraySize(x),
|
|
|
|
ArgCount => ArgCount,
|
|
|
|
RegionsDoesNotOutlive(a, b) => {
|
|
|
|
RegionsDoesNotOutlive(a.fold_with(folder), b.fold_with(folder))
|
|
|
|
},
|
2017-07-29 17:19:57 +03:00
|
|
|
RegionsInsufficientlyPolymorphic(a, b) => {
|
|
|
|
RegionsInsufficientlyPolymorphic(a, b.fold_with(folder))
|
2017-07-08 23:24:00 +02:00
|
|
|
},
|
2017-07-29 17:19:57 +03:00
|
|
|
RegionsOverlyPolymorphic(a, b) => {
|
|
|
|
RegionsOverlyPolymorphic(a, b.fold_with(folder))
|
2017-07-08 23:24:00 +02:00
|
|
|
},
|
|
|
|
IntMismatch(x) => IntMismatch(x),
|
|
|
|
FloatMismatch(x) => FloatMismatch(x),
|
|
|
|
Traits(x) => Traits(x),
|
|
|
|
VariadicMismatch(x) => VariadicMismatch(x),
|
2017-11-17 11:13:13 -05:00
|
|
|
CyclicTy(t) => CyclicTy(t.fold_with(folder)),
|
2017-07-11 10:33:09 -04:00
|
|
|
ProjectionMismatched(x) => ProjectionMismatched(x),
|
2017-07-08 23:24:00 +02:00
|
|
|
ProjectionBoundsLength(x) => ProjectionBoundsLength(x),
|
|
|
|
Sorts(x) => Sorts(x.fold_with(folder)),
|
|
|
|
ExistentialMismatch(x) => ExistentialMismatch(x.fold_with(folder)),
|
2017-08-30 16:06:05 -04:00
|
|
|
OldStyleLUB(ref x) => OldStyleLUB(x.fold_with(folder)),
|
2017-07-08 23:24:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
|
|
|
use ty::error::TypeError::*;
|
|
|
|
|
|
|
|
match *self {
|
|
|
|
UnsafetyMismatch(x) => x.visit_with(visitor),
|
|
|
|
AbiMismatch(x) => x.visit_with(visitor),
|
2017-08-30 02:39:06 +03:00
|
|
|
RegionsDoesNotOutlive(a, b) => {
|
2017-07-08 23:24:00 +02:00
|
|
|
a.visit_with(visitor) || b.visit_with(visitor)
|
|
|
|
},
|
2017-07-29 17:19:57 +03:00
|
|
|
RegionsInsufficientlyPolymorphic(_, b) |
|
|
|
|
RegionsOverlyPolymorphic(_, b) => {
|
2017-07-08 23:24:00 +02:00
|
|
|
b.visit_with(visitor)
|
|
|
|
},
|
|
|
|
Sorts(x) => x.visit_with(visitor),
|
2017-08-30 16:06:05 -04:00
|
|
|
OldStyleLUB(ref x) => x.visit_with(visitor),
|
2017-07-08 23:24:00 +02:00
|
|
|
ExistentialMismatch(x) => x.visit_with(visitor),
|
2017-11-17 11:13:13 -05:00
|
|
|
CyclicTy(t) => t.visit_with(visitor),
|
2017-07-08 23:24:00 +02:00
|
|
|
Mismatch |
|
|
|
|
Mutability |
|
|
|
|
TupleSize(_) |
|
|
|
|
FixedArraySize(_) |
|
|
|
|
ArgCount |
|
|
|
|
IntMismatch(_) |
|
|
|
|
FloatMismatch(_) |
|
|
|
|
Traits(_) |
|
|
|
|
VariadicMismatch(_) |
|
2017-07-11 10:33:09 -04:00
|
|
|
ProjectionMismatched(_) |
|
2017-07-08 23:24:00 +02:00
|
|
|
ProjectionBoundsLength(_) => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-08-04 11:25:13 +03:00
|
|
|
|
|
|
|
impl<'tcx> TypeFoldable<'tcx> for ConstVal<'tcx> {
|
|
|
|
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
|
|
|
match *self {
|
2018-01-16 09:12:54 +01:00
|
|
|
ConstVal::Value(v) => ConstVal::Value(v),
|
2017-08-07 08:08:53 +03:00
|
|
|
ConstVal::Unevaluated(def_id, substs) => {
|
|
|
|
ConstVal::Unevaluated(def_id, substs.fold_with(folder))
|
|
|
|
}
|
2017-08-04 11:25:13 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
|
|
|
match *self {
|
2018-01-16 09:28:27 +01:00
|
|
|
ConstVal::Value(_) => false,
|
2017-08-07 08:08:53 +03:00
|
|
|
ConstVal::Unevaluated(_, substs) => substs.visit_with(visitor),
|
2017-08-04 11:25:13 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::Const<'tcx> {
|
|
|
|
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
|
|
|
let ty = self.ty.fold_with(folder);
|
|
|
|
let val = self.val.fold_with(folder);
|
|
|
|
folder.tcx().mk_const(ty::Const {
|
|
|
|
ty,
|
|
|
|
val
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-08-07 08:08:53 +03:00
|
|
|
fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
|
|
|
folder.fold_const(*self)
|
|
|
|
}
|
|
|
|
|
2017-08-04 11:25:13 +03:00
|
|
|
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
|
|
|
self.ty.visit_with(visitor) || self.val.visit_with(visitor)
|
|
|
|
}
|
2017-08-07 08:08:53 +03:00
|
|
|
|
|
|
|
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
|
|
|
visitor.visit_const(self)
|
|
|
|
}
|
2017-08-04 11:25:13 +03:00
|
|
|
}
|