rustc: Generalize a minimum set of functions over 'tcx != 'gcx.
This commit is contained in:
parent
f0b2b3c441
commit
8f72d8127f
@ -36,24 +36,24 @@ pub struct Bivariate<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
|
||||
fields: CombineFields<'a, 'gcx, 'tcx>
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Bivariate<'a, 'tcx, 'tcx> {
|
||||
pub fn new(fields: CombineFields<'a, 'tcx, 'tcx>) -> Bivariate<'a, 'tcx, 'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> Bivariate<'a, 'gcx, 'tcx> {
|
||||
pub fn new(fields: CombineFields<'a, 'gcx, 'tcx>) -> Bivariate<'a, 'gcx, 'tcx> {
|
||||
Bivariate { fields: fields }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> TypeRelation<'a, 'tcx> for Bivariate<'a, 'tcx, 'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> TypeRelation<'a, 'gcx, 'tcx> for Bivariate<'a, 'gcx, 'tcx> {
|
||||
fn tag(&self) -> &'static str { "Bivariate" }
|
||||
|
||||
fn tcx(&self) -> TyCtxt<'a, 'tcx, 'tcx> { self.fields.tcx() }
|
||||
fn tcx(&self) -> TyCtxt<'a, 'gcx, 'tcx> { self.fields.tcx() }
|
||||
|
||||
fn a_is_expected(&self) -> bool { self.fields.a_is_expected }
|
||||
|
||||
fn relate_with_variance<T:Relate<'a,'tcx>>(&mut self,
|
||||
variance: ty::Variance,
|
||||
a: &T,
|
||||
b: &T)
|
||||
-> RelateResult<'tcx, T>
|
||||
fn relate_with_variance<T: Relate<'tcx>>(&mut self,
|
||||
variance: ty::Variance,
|
||||
a: &T,
|
||||
b: &T)
|
||||
-> RelateResult<'tcx, T>
|
||||
{
|
||||
match variance {
|
||||
// If we have Foo<A> and Foo is invariant w/r/t A,
|
||||
@ -107,7 +107,7 @@ impl<'a, 'tcx> TypeRelation<'a, 'tcx> for Bivariate<'a, 'tcx, 'tcx> {
|
||||
|
||||
fn binders<T>(&mut self, a: &ty::Binder<T>, b: &ty::Binder<T>)
|
||||
-> RelateResult<'tcx, ty::Binder<T>>
|
||||
where T: Relate<'a,'tcx>
|
||||
where T: Relate<'tcx>
|
||||
{
|
||||
let a1 = self.tcx().erase_late_bound_regions(a);
|
||||
let b1 = self.tcx().erase_late_bound_regions(b);
|
||||
|
@ -60,13 +60,13 @@ pub struct CombineFields<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
|
||||
pub obligations: PredicateObligations<'tcx>,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> InferCtxt<'a, 'tcx, 'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
pub fn super_combine_tys<R>(&self,
|
||||
relation: &mut R,
|
||||
a: Ty<'tcx>,
|
||||
b: Ty<'tcx>)
|
||||
-> RelateResult<'tcx, Ty<'tcx>>
|
||||
where R: TypeRelation<'a,'tcx>
|
||||
where R: TypeRelation<'a, 'gcx, 'tcx>
|
||||
{
|
||||
let a_is_expected = relation.a_is_expected();
|
||||
|
||||
@ -150,35 +150,35 @@ fn unify_float_variable(&self,
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> CombineFields<'a, 'tcx, 'tcx> {
|
||||
pub fn tcx(&self) -> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
|
||||
pub fn tcx(&self) -> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
self.infcx.tcx
|
||||
}
|
||||
|
||||
pub fn switch_expected(&self) -> CombineFields<'a, 'tcx, 'tcx> {
|
||||
pub fn switch_expected(&self) -> CombineFields<'a, 'gcx, 'tcx> {
|
||||
CombineFields {
|
||||
a_is_expected: !self.a_is_expected,
|
||||
..(*self).clone()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn equate(&self) -> Equate<'a, 'tcx, 'tcx> {
|
||||
pub fn equate(&self) -> Equate<'a, 'gcx, 'tcx> {
|
||||
Equate::new(self.clone())
|
||||
}
|
||||
|
||||
pub fn bivariate(&self) -> Bivariate<'a, 'tcx, 'tcx> {
|
||||
pub fn bivariate(&self) -> Bivariate<'a, 'gcx, 'tcx> {
|
||||
Bivariate::new(self.clone())
|
||||
}
|
||||
|
||||
pub fn sub(&self) -> Sub<'a, 'tcx, 'tcx> {
|
||||
pub fn sub(&self) -> Sub<'a, 'gcx, 'tcx> {
|
||||
Sub::new(self.clone())
|
||||
}
|
||||
|
||||
pub fn lub(&self) -> Lub<'a, 'tcx, 'tcx> {
|
||||
pub fn lub(&self) -> Lub<'a, 'gcx, 'tcx> {
|
||||
Lub::new(self.clone())
|
||||
}
|
||||
|
||||
pub fn glb(&self) -> Glb<'a, 'tcx, 'tcx> {
|
||||
pub fn glb(&self) -> Glb<'a, 'gcx, 'tcx> {
|
||||
Glb::new(self.clone())
|
||||
}
|
||||
|
||||
@ -299,8 +299,8 @@ struct Generalizer<'cx, 'gcx: 'cx+'tcx, 'tcx: 'cx> {
|
||||
cycle_detected: bool,
|
||||
}
|
||||
|
||||
impl<'cx, 'tcx> ty::fold::TypeFolder<'tcx> for Generalizer<'cx, 'tcx, 'tcx> {
|
||||
fn tcx<'a>(&'a self) -> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
impl<'cx, 'gcx, 'tcx> ty::fold::TypeFolder<'gcx, 'tcx> for Generalizer<'cx, 'gcx, 'tcx> {
|
||||
fn tcx<'a>(&'a self) -> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
self.infcx.tcx
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,6 @@
|
||||
// except according to those terms.
|
||||
|
||||
use super::combine::CombineFields;
|
||||
use super::higher_ranked::HigherRankedRelations;
|
||||
use super::{Subtype};
|
||||
use super::type_variable::{EqTo};
|
||||
|
||||
@ -23,8 +22,8 @@ pub struct Equate<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
|
||||
fields: CombineFields<'a, 'gcx, 'tcx>
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Equate<'a, 'tcx, 'tcx> {
|
||||
pub fn new(fields: CombineFields<'a, 'tcx, 'tcx>) -> Equate<'a, 'tcx, 'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> Equate<'a, 'gcx, 'tcx> {
|
||||
pub fn new(fields: CombineFields<'a, 'gcx, 'tcx>) -> Equate<'a, 'gcx, 'tcx> {
|
||||
Equate { fields: fields }
|
||||
}
|
||||
|
||||
@ -33,18 +32,18 @@ impl<'a, 'tcx> Equate<'a, 'tcx, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> TypeRelation<'a,'tcx> for Equate<'a, 'tcx, 'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> TypeRelation<'a, 'gcx, 'tcx> for Equate<'a, 'gcx, 'tcx> {
|
||||
fn tag(&self) -> &'static str { "Equate" }
|
||||
|
||||
fn tcx(&self) -> TyCtxt<'a, 'tcx, 'tcx> { self.fields.tcx() }
|
||||
fn tcx(&self) -> TyCtxt<'a, 'gcx, 'tcx> { self.fields.tcx() }
|
||||
|
||||
fn a_is_expected(&self) -> bool { self.fields.a_is_expected }
|
||||
|
||||
fn relate_with_variance<T:Relate<'a,'tcx>>(&mut self,
|
||||
_: ty::Variance,
|
||||
a: &T,
|
||||
b: &T)
|
||||
-> RelateResult<'tcx, T>
|
||||
fn relate_with_variance<T: Relate<'tcx>>(&mut self,
|
||||
_: ty::Variance,
|
||||
a: &T,
|
||||
b: &T)
|
||||
-> RelateResult<'tcx, T>
|
||||
{
|
||||
self.relate(a, b)
|
||||
}
|
||||
@ -92,7 +91,7 @@ impl<'a, 'tcx> TypeRelation<'a,'tcx> for Equate<'a, 'tcx, 'tcx> {
|
||||
|
||||
fn binders<T>(&mut self, a: &ty::Binder<T>, b: &ty::Binder<T>)
|
||||
-> RelateResult<'tcx, ty::Binder<T>>
|
||||
where T: Relate<'a, 'tcx>
|
||||
where T: Relate<'tcx>
|
||||
{
|
||||
self.fields.higher_ranked_sub(a, b)?;
|
||||
self.fields.higher_ranked_sub(b, a)
|
||||
|
@ -95,7 +95,7 @@ use syntax::codemap::{self, Pos, Span};
|
||||
use syntax::parse::token;
|
||||
use syntax::ptr::P;
|
||||
|
||||
impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
pub fn note_and_explain_region(self,
|
||||
err: &mut DiagnosticBuilder,
|
||||
prefix: &str,
|
||||
@ -112,9 +112,9 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn explain_span<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
heading: &str, span: Span)
|
||||
-> (String, Option<Span>) {
|
||||
fn explain_span<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
heading: &str, span: Span)
|
||||
-> (String, Option<Span>) {
|
||||
let lo = tcx.sess.codemap().lookup_char_pos_adj(span.lo);
|
||||
(format!("the {} at {}:{}", heading, lo.line, lo.col.to_usize()),
|
||||
Some(span))
|
||||
@ -228,83 +228,9 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ErrorReporting<'tcx> {
|
||||
fn report_region_errors(&self,
|
||||
errors: &Vec<RegionResolutionError<'tcx>>);
|
||||
|
||||
fn process_errors(&self, errors: &Vec<RegionResolutionError<'tcx>>)
|
||||
-> Option<Vec<RegionResolutionError<'tcx>>>;
|
||||
|
||||
fn report_type_error(&self,
|
||||
trace: TypeTrace<'tcx>,
|
||||
terr: &TypeError<'tcx>)
|
||||
-> DiagnosticBuilder<'tcx>;
|
||||
|
||||
fn check_and_note_conflicting_crates(&self,
|
||||
err: &mut DiagnosticBuilder,
|
||||
terr: &TypeError<'tcx>,
|
||||
sp: Span);
|
||||
|
||||
fn report_and_explain_type_error(&self,
|
||||
trace: TypeTrace<'tcx>,
|
||||
terr: &TypeError<'tcx>)
|
||||
-> DiagnosticBuilder<'tcx>;
|
||||
|
||||
fn values_str(&self, values: &ValuePairs<'tcx>) -> Option<(String, String)>;
|
||||
|
||||
fn expected_found_str<T: fmt::Display + Resolvable<'tcx> + TypeFoldable<'tcx>>(
|
||||
&self,
|
||||
exp_found: &ty::error::ExpectedFound<T>)
|
||||
-> Option<(String, String)>;
|
||||
|
||||
fn report_concrete_failure(&self,
|
||||
origin: SubregionOrigin<'tcx>,
|
||||
sub: Region,
|
||||
sup: Region)
|
||||
-> DiagnosticBuilder<'tcx>;
|
||||
|
||||
fn report_generic_bound_failure(&self,
|
||||
origin: SubregionOrigin<'tcx>,
|
||||
kind: GenericKind<'tcx>,
|
||||
sub: Region);
|
||||
|
||||
fn report_sub_sup_conflict(&self,
|
||||
var_origin: RegionVariableOrigin,
|
||||
sub_origin: SubregionOrigin<'tcx>,
|
||||
sub_region: Region,
|
||||
sup_origin: SubregionOrigin<'tcx>,
|
||||
sup_region: Region);
|
||||
|
||||
fn report_processed_errors(&self,
|
||||
origins: &[ProcessedErrorOrigin<'tcx>],
|
||||
same_regions: &[SameRegions]);
|
||||
|
||||
fn give_suggestion(&self, err: &mut DiagnosticBuilder, same_regions: &[SameRegions]);
|
||||
}
|
||||
|
||||
trait ErrorReportingHelpers<'tcx> {
|
||||
fn report_inference_failure(&self,
|
||||
var_origin: RegionVariableOrigin)
|
||||
-> DiagnosticBuilder<'tcx>;
|
||||
|
||||
fn note_region_origin(&self,
|
||||
err: &mut DiagnosticBuilder,
|
||||
origin: &SubregionOrigin<'tcx>);
|
||||
|
||||
fn give_expl_lifetime_param(&self,
|
||||
err: &mut DiagnosticBuilder,
|
||||
decl: &hir::FnDecl,
|
||||
unsafety: hir::Unsafety,
|
||||
constness: hir::Constness,
|
||||
name: ast::Name,
|
||||
opt_explicit_self: Option<&hir::ExplicitSelf_>,
|
||||
generics: &hir::Generics,
|
||||
span: Span);
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx, 'tcx> {
|
||||
fn report_region_errors(&self,
|
||||
errors: &Vec<RegionResolutionError<'tcx>>) {
|
||||
impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
pub fn report_region_errors(&self,
|
||||
errors: &Vec<RegionResolutionError<'tcx>>) {
|
||||
debug!("report_region_errors(): {} errors to start", errors.len());
|
||||
|
||||
// try to pre-process the errors, which will group some of them
|
||||
@ -475,10 +401,10 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn free_regions_from_same_fn<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
sub: Region,
|
||||
sup: Region)
|
||||
-> Option<FreeRegionsFromSameFn> {
|
||||
fn free_regions_from_same_fn<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
sub: Region,
|
||||
sup: Region)
|
||||
-> Option<FreeRegionsFromSameFn> {
|
||||
debug!("free_regions_from_same_fn(sub={:?}, sup={:?})", sub, sup);
|
||||
let (scope_id, fr1, fr2) = match (sub, sup) {
|
||||
(ReFree(fr1), ReFree(fr2)) => {
|
||||
@ -620,10 +546,10 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn report_and_explain_type_error(&self,
|
||||
trace: TypeTrace<'tcx>,
|
||||
terr: &TypeError<'tcx>)
|
||||
-> DiagnosticBuilder<'tcx> {
|
||||
pub fn report_and_explain_type_error(&self,
|
||||
trace: TypeTrace<'tcx>,
|
||||
terr: &TypeError<'tcx>)
|
||||
-> DiagnosticBuilder<'tcx> {
|
||||
let span = trace.origin.span();
|
||||
let mut err = self.report_type_error(trace, terr);
|
||||
self.tcx.note_and_explain_type_err(&mut err, terr, span);
|
||||
@ -1109,8 +1035,8 @@ struct RebuildPathInfo<'a> {
|
||||
region_names: &'a HashSet<ast::Name>
|
||||
}
|
||||
|
||||
struct Rebuilder<'a, 'tcx: 'a> {
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
struct Rebuilder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
|
||||
tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
fn_decl: &'a hir::FnDecl,
|
||||
expl_self_opt: Option<&'a hir::ExplicitSelf_>,
|
||||
generics: &'a hir::Generics,
|
||||
@ -1125,14 +1051,14 @@ enum FreshOrKept {
|
||||
Kept
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
|
||||
fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
impl<'a, 'gcx, 'tcx> Rebuilder<'a, 'gcx, 'tcx> {
|
||||
fn new(tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
fn_decl: &'a hir::FnDecl,
|
||||
expl_self_opt: Option<&'a hir::ExplicitSelf_>,
|
||||
generics: &'a hir::Generics,
|
||||
same_regions: &'a [SameRegions],
|
||||
life_giver: &'a LifeGiver)
|
||||
-> Rebuilder<'a, 'tcx> {
|
||||
-> Rebuilder<'a, 'gcx, 'tcx> {
|
||||
Rebuilder {
|
||||
tcx: tcx,
|
||||
fn_decl: fn_decl,
|
||||
@ -1642,7 +1568,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> ErrorReportingHelpers<'tcx> for InferCtxt<'a, 'tcx, 'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
fn give_expl_lifetime_param(&self,
|
||||
err: &mut DiagnosticBuilder,
|
||||
decl: &hir::FnDecl,
|
||||
@ -1905,34 +1831,34 @@ impl<'a, 'tcx> ErrorReportingHelpers<'tcx> for InferCtxt<'a, 'tcx, 'tcx> {
|
||||
}
|
||||
|
||||
pub trait Resolvable<'tcx> {
|
||||
fn resolve<'a>(&self, infcx: &InferCtxt<'a, 'tcx, 'tcx>) -> Self;
|
||||
fn resolve<'a, 'gcx>(&self, infcx: &InferCtxt<'a, 'gcx, 'tcx>) -> Self;
|
||||
}
|
||||
|
||||
impl<'tcx> Resolvable<'tcx> for Ty<'tcx> {
|
||||
fn resolve<'a>(&self, infcx: &InferCtxt<'a, 'tcx, 'tcx>) -> Ty<'tcx> {
|
||||
fn resolve<'a, 'gcx>(&self, infcx: &InferCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> {
|
||||
infcx.resolve_type_vars_if_possible(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Resolvable<'tcx> for ty::TraitRef<'tcx> {
|
||||
fn resolve<'a>(&self, infcx: &InferCtxt<'a, 'tcx, 'tcx>)
|
||||
-> ty::TraitRef<'tcx> {
|
||||
fn resolve<'a, 'gcx>(&self, infcx: &InferCtxt<'a, 'gcx, 'tcx>)
|
||||
-> ty::TraitRef<'tcx> {
|
||||
infcx.resolve_type_vars_if_possible(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Resolvable<'tcx> for ty::PolyTraitRef<'tcx> {
|
||||
fn resolve<'a>(&self,
|
||||
infcx: &InferCtxt<'a, 'tcx, 'tcx>)
|
||||
-> ty::PolyTraitRef<'tcx>
|
||||
fn resolve<'a, 'gcx>(&self,
|
||||
infcx: &InferCtxt<'a, 'gcx, 'tcx>)
|
||||
-> ty::PolyTraitRef<'tcx>
|
||||
{
|
||||
infcx.resolve_type_vars_if_possible(self)
|
||||
}
|
||||
}
|
||||
|
||||
fn lifetimes_in_scope<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
scope_id: ast::NodeId)
|
||||
-> Vec<hir::LifetimeDef> {
|
||||
fn lifetimes_in_scope<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
scope_id: ast::NodeId)
|
||||
-> Vec<hir::LifetimeDef> {
|
||||
let mut taken = Vec::new();
|
||||
let parent = tcx.map.get_parent(scope_id);
|
||||
let method_id_opt = match tcx.map.find(parent) {
|
||||
|
@ -43,8 +43,9 @@ pub struct TypeFreshener<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
|
||||
freshen_map: hash_map::HashMap<ty::InferTy, Ty<'tcx>>,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> TypeFreshener<'a, 'tcx, 'tcx> {
|
||||
pub fn new(infcx: &'a InferCtxt<'a, 'tcx, 'tcx>) -> TypeFreshener<'a, 'tcx, 'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> TypeFreshener<'a, 'gcx, 'tcx> {
|
||||
pub fn new(infcx: &'a InferCtxt<'a, 'gcx, 'tcx>)
|
||||
-> TypeFreshener<'a, 'gcx, 'tcx> {
|
||||
TypeFreshener {
|
||||
infcx: infcx,
|
||||
freshen_count: 0,
|
||||
@ -77,8 +78,8 @@ impl<'a, 'tcx> TypeFreshener<'a, 'tcx, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx, 'tcx> {
|
||||
fn tcx<'b>(&'b self) -> TyCtxt<'b, 'tcx, 'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for TypeFreshener<'a, 'gcx, 'tcx> {
|
||||
fn tcx<'b>(&'b self) -> TyCtxt<'b, 'gcx, 'tcx> {
|
||||
self.infcx.tcx
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,6 @@
|
||||
// except according to those terms.
|
||||
|
||||
use super::combine::CombineFields;
|
||||
use super::higher_ranked::HigherRankedRelations;
|
||||
use super::InferCtxt;
|
||||
use super::lattice::{self, LatticeDir};
|
||||
use super::Subtype;
|
||||
@ -23,8 +22,8 @@ pub struct Glb<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
|
||||
fields: CombineFields<'a, 'gcx, 'tcx>
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Glb<'a, 'tcx, 'tcx> {
|
||||
pub fn new(fields: CombineFields<'a, 'tcx, 'tcx>) -> Glb<'a, 'tcx, 'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> Glb<'a, 'gcx, 'tcx> {
|
||||
pub fn new(fields: CombineFields<'a, 'gcx, 'tcx>) -> Glb<'a, 'gcx, 'tcx> {
|
||||
Glb { fields: fields }
|
||||
}
|
||||
|
||||
@ -33,18 +32,18 @@ impl<'a, 'tcx> Glb<'a, 'tcx, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> TypeRelation<'a, 'tcx> for Glb<'a, 'tcx, 'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> TypeRelation<'a, 'gcx, 'tcx> for Glb<'a, 'gcx, 'tcx> {
|
||||
fn tag(&self) -> &'static str { "Glb" }
|
||||
|
||||
fn tcx(&self) -> TyCtxt<'a, 'tcx, 'tcx> { self.fields.tcx() }
|
||||
fn tcx(&self) -> TyCtxt<'a, 'gcx, 'tcx> { self.fields.tcx() }
|
||||
|
||||
fn a_is_expected(&self) -> bool { self.fields.a_is_expected }
|
||||
|
||||
fn relate_with_variance<T:Relate<'a,'tcx>>(&mut self,
|
||||
variance: ty::Variance,
|
||||
a: &T,
|
||||
b: &T)
|
||||
-> RelateResult<'tcx, T>
|
||||
fn relate_with_variance<T: Relate<'tcx>>(&mut self,
|
||||
variance: ty::Variance,
|
||||
a: &T,
|
||||
b: &T)
|
||||
-> RelateResult<'tcx, T>
|
||||
{
|
||||
match variance {
|
||||
ty::Invariant => self.fields.equate().relate(a, b),
|
||||
@ -70,14 +69,14 @@ impl<'a, 'tcx> TypeRelation<'a, 'tcx> for Glb<'a, 'tcx, 'tcx> {
|
||||
|
||||
fn binders<T>(&mut self, a: &ty::Binder<T>, b: &ty::Binder<T>)
|
||||
-> RelateResult<'tcx, ty::Binder<T>>
|
||||
where T: Relate<'a, 'tcx>
|
||||
where T: Relate<'tcx>
|
||||
{
|
||||
self.fields.higher_ranked_glb(a, b)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> LatticeDir<'a,'tcx> for Glb<'a, 'tcx, 'tcx> {
|
||||
fn infcx(&self) -> &'a InferCtxt<'a, 'tcx, 'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> LatticeDir<'a, 'gcx, 'tcx> for Glb<'a, 'gcx, 'tcx> {
|
||||
fn infcx(&self) -> &'a InferCtxt<'a, 'gcx, 'tcx> {
|
||||
self.fields.infcx
|
||||
}
|
||||
|
||||
|
@ -20,21 +20,10 @@ use ty::relate::{Relate, RelateResult, TypeRelation};
|
||||
use syntax::codemap::Span;
|
||||
use util::nodemap::{FnvHashMap, FnvHashSet};
|
||||
|
||||
pub trait HigherRankedRelations<'a,'tcx> {
|
||||
fn higher_ranked_sub<T>(&self, a: &Binder<T>, b: &Binder<T>) -> RelateResult<'tcx, Binder<T>>
|
||||
where T: Relate<'a,'tcx>;
|
||||
|
||||
fn higher_ranked_lub<T>(&self, a: &Binder<T>, b: &Binder<T>) -> RelateResult<'tcx, Binder<T>>
|
||||
where T: Relate<'a,'tcx>;
|
||||
|
||||
fn higher_ranked_glb<T>(&self, a: &Binder<T>, b: &Binder<T>) -> RelateResult<'tcx, Binder<T>>
|
||||
where T: Relate<'a,'tcx>;
|
||||
}
|
||||
|
||||
impl<'a,'tcx> HigherRankedRelations<'a,'tcx> for CombineFields<'a, 'tcx, 'tcx> {
|
||||
fn higher_ranked_sub<T>(&self, a: &Binder<T>, b: &Binder<T>)
|
||||
-> RelateResult<'tcx, Binder<T>>
|
||||
where T: Relate<'a,'tcx>
|
||||
impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
|
||||
pub fn higher_ranked_sub<T>(&self, a: &Binder<T>, b: &Binder<T>)
|
||||
-> RelateResult<'tcx, Binder<T>>
|
||||
where T: Relate<'tcx>
|
||||
{
|
||||
debug!("higher_ranked_sub(a={:?}, b={:?})",
|
||||
a, b);
|
||||
@ -79,8 +68,9 @@ impl<'a,'tcx> HigherRankedRelations<'a,'tcx> for CombineFields<'a, 'tcx, 'tcx> {
|
||||
});
|
||||
}
|
||||
|
||||
fn higher_ranked_lub<T>(&self, a: &Binder<T>, b: &Binder<T>) -> RelateResult<'tcx, Binder<T>>
|
||||
where T: Relate<'a,'tcx>
|
||||
pub fn higher_ranked_lub<T>(&self, a: &Binder<T>, b: &Binder<T>)
|
||||
-> RelateResult<'tcx, Binder<T>>
|
||||
where T: Relate<'tcx>
|
||||
{
|
||||
// Start a snapshot so we can examine "all bindings that were
|
||||
// created as part of this type comparison".
|
||||
@ -119,14 +109,14 @@ impl<'a,'tcx> HigherRankedRelations<'a,'tcx> for CombineFields<'a, 'tcx, 'tcx> {
|
||||
Ok(ty::Binder(result1))
|
||||
});
|
||||
|
||||
fn generalize_region<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx, 'tcx>,
|
||||
span: Span,
|
||||
snapshot: &CombinedSnapshot,
|
||||
debruijn: ty::DebruijnIndex,
|
||||
new_vars: &[ty::RegionVid],
|
||||
a_map: &FnvHashMap<ty::BoundRegion, ty::Region>,
|
||||
r0: ty::Region)
|
||||
-> ty::Region {
|
||||
fn generalize_region<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
|
||||
span: Span,
|
||||
snapshot: &CombinedSnapshot,
|
||||
debruijn: ty::DebruijnIndex,
|
||||
new_vars: &[ty::RegionVid],
|
||||
a_map: &FnvHashMap<ty::BoundRegion, ty::Region>,
|
||||
r0: ty::Region)
|
||||
-> ty::Region {
|
||||
// Regions that pre-dated the LUB computation stay as they are.
|
||||
if !is_var_in_set(new_vars, r0) {
|
||||
assert!(!r0.is_bound());
|
||||
@ -168,8 +158,9 @@ impl<'a,'tcx> HigherRankedRelations<'a,'tcx> for CombineFields<'a, 'tcx, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn higher_ranked_glb<T>(&self, a: &Binder<T>, b: &Binder<T>) -> RelateResult<'tcx, Binder<T>>
|
||||
where T: Relate<'a,'tcx>
|
||||
pub fn higher_ranked_glb<T>(&self, a: &Binder<T>, b: &Binder<T>)
|
||||
-> RelateResult<'tcx, Binder<T>>
|
||||
where T: Relate<'tcx>
|
||||
{
|
||||
debug!("higher_ranked_glb({:?}, {:?})",
|
||||
a, b);
|
||||
@ -214,15 +205,15 @@ impl<'a,'tcx> HigherRankedRelations<'a,'tcx> for CombineFields<'a, 'tcx, 'tcx> {
|
||||
Ok(ty::Binder(result1))
|
||||
});
|
||||
|
||||
fn generalize_region<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx, 'tcx>,
|
||||
span: Span,
|
||||
snapshot: &CombinedSnapshot,
|
||||
debruijn: ty::DebruijnIndex,
|
||||
new_vars: &[ty::RegionVid],
|
||||
a_map: &FnvHashMap<ty::BoundRegion, ty::Region>,
|
||||
a_vars: &[ty::RegionVid],
|
||||
b_vars: &[ty::RegionVid],
|
||||
r0: ty::Region) -> ty::Region {
|
||||
fn generalize_region<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
|
||||
span: Span,
|
||||
snapshot: &CombinedSnapshot,
|
||||
debruijn: ty::DebruijnIndex,
|
||||
new_vars: &[ty::RegionVid],
|
||||
a_map: &FnvHashMap<ty::BoundRegion, ty::Region>,
|
||||
a_vars: &[ty::RegionVid],
|
||||
b_vars: &[ty::RegionVid],
|
||||
r0: ty::Region) -> ty::Region {
|
||||
if !is_var_in_set(new_vars, r0) {
|
||||
assert!(!r0.is_bound());
|
||||
return r0;
|
||||
@ -306,9 +297,9 @@ impl<'a,'tcx> HigherRankedRelations<'a,'tcx> for CombineFields<'a, 'tcx, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn var_ids<'a, 'tcx>(fields: &CombineFields<'a, 'tcx, 'tcx>,
|
||||
map: &FnvHashMap<ty::BoundRegion, ty::Region>)
|
||||
-> Vec<ty::RegionVid> {
|
||||
fn var_ids<'a, 'gcx, 'tcx>(fields: &CombineFields<'a, 'gcx, 'tcx>,
|
||||
map: &FnvHashMap<ty::BoundRegion, ty::Region>)
|
||||
-> Vec<ty::RegionVid> {
|
||||
map.iter()
|
||||
.map(|(_, r)| match *r {
|
||||
ty::ReVar(r) => { r }
|
||||
@ -329,10 +320,10 @@ fn is_var_in_set(new_vars: &[ty::RegionVid], r: ty::Region) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
fn fold_regions_in<'a, 'tcx, T, F>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
unbound_value: &T,
|
||||
mut fldr: F)
|
||||
-> T
|
||||
fn fold_regions_in<'a, 'gcx, 'tcx, T, F>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
unbound_value: &T,
|
||||
mut fldr: F)
|
||||
-> T
|
||||
where T: TypeFoldable<'tcx>,
|
||||
F: FnMut(ty::Region, ty::DebruijnIndex) -> ty::Region,
|
||||
{
|
||||
@ -349,7 +340,7 @@ fn fold_regions_in<'a, 'tcx, T, F>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
})
|
||||
}
|
||||
|
||||
impl<'a,'tcx> InferCtxt<'a,'tcx, 'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
fn tainted_regions(&self, snapshot: &CombinedSnapshot, r: ty::Region) -> Vec<ty::Region> {
|
||||
self.region_vars.tainted(&snapshot.region_vars_snapshot, r)
|
||||
}
|
||||
|
@ -35,19 +35,19 @@ use ty::TyVar;
|
||||
use ty::{self, Ty};
|
||||
use ty::relate::{RelateResult, TypeRelation};
|
||||
|
||||
pub trait LatticeDir<'f,'tcx> : TypeRelation<'f,'tcx> {
|
||||
fn infcx(&self) -> &'f InferCtxt<'f, 'tcx, 'tcx>;
|
||||
pub trait LatticeDir<'f, 'gcx: 'f+'tcx, 'tcx: 'f> : TypeRelation<'f, 'gcx, 'tcx> {
|
||||
fn infcx(&self) -> &'f InferCtxt<'f, 'gcx, 'tcx>;
|
||||
|
||||
// Relates the type `v` to `a` and `b` such that `v` represents
|
||||
// the LUB/GLB of `a` and `b` as appropriate.
|
||||
fn relate_bound(&self, v: Ty<'tcx>, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, ()>;
|
||||
}
|
||||
|
||||
pub fn super_lattice_tys<'a,'tcx,L:LatticeDir<'a,'tcx>>(this: &mut L,
|
||||
a: Ty<'tcx>,
|
||||
b: Ty<'tcx>)
|
||||
-> RelateResult<'tcx, Ty<'tcx>>
|
||||
where 'tcx: 'a
|
||||
pub fn super_lattice_tys<'a, 'gcx, 'tcx, L>(this: &mut L,
|
||||
a: Ty<'tcx>,
|
||||
b: Ty<'tcx>)
|
||||
-> RelateResult<'tcx, Ty<'tcx>>
|
||||
where L: LatticeDir<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
|
||||
{
|
||||
debug!("{}.lattice_tys({:?}, {:?})",
|
||||
this.tag(),
|
||||
|
@ -9,7 +9,6 @@
|
||||
// except according to those terms.
|
||||
|
||||
use super::combine::CombineFields;
|
||||
use super::higher_ranked::HigherRankedRelations;
|
||||
use super::InferCtxt;
|
||||
use super::lattice::{self, LatticeDir};
|
||||
use super::Subtype;
|
||||
@ -23,8 +22,8 @@ pub struct Lub<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
|
||||
fields: CombineFields<'a, 'gcx, 'tcx>
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Lub<'a, 'tcx, 'tcx> {
|
||||
pub fn new(fields: CombineFields<'a, 'tcx, 'tcx>) -> Lub<'a, 'tcx, 'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> Lub<'a, 'gcx, 'tcx> {
|
||||
pub fn new(fields: CombineFields<'a, 'gcx, 'tcx>) -> Lub<'a, 'gcx, 'tcx> {
|
||||
Lub { fields: fields }
|
||||
}
|
||||
|
||||
@ -33,18 +32,18 @@ impl<'a, 'tcx> Lub<'a, 'tcx, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> TypeRelation<'a, 'tcx> for Lub<'a, 'tcx, 'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> TypeRelation<'a, 'gcx, 'tcx> for Lub<'a, 'gcx, 'tcx> {
|
||||
fn tag(&self) -> &'static str { "Lub" }
|
||||
|
||||
fn tcx(&self) -> TyCtxt<'a, 'tcx, 'tcx> { self.fields.tcx() }
|
||||
fn tcx(&self) -> TyCtxt<'a, 'gcx, 'tcx> { self.fields.tcx() }
|
||||
|
||||
fn a_is_expected(&self) -> bool { self.fields.a_is_expected }
|
||||
|
||||
fn relate_with_variance<T:Relate<'a,'tcx>>(&mut self,
|
||||
variance: ty::Variance,
|
||||
a: &T,
|
||||
b: &T)
|
||||
-> RelateResult<'tcx, T>
|
||||
fn relate_with_variance<T: Relate<'tcx>>(&mut self,
|
||||
variance: ty::Variance,
|
||||
a: &T,
|
||||
b: &T)
|
||||
-> RelateResult<'tcx, T>
|
||||
{
|
||||
match variance {
|
||||
ty::Invariant => self.fields.equate().relate(a, b),
|
||||
@ -70,14 +69,14 @@ impl<'a, 'tcx> TypeRelation<'a, 'tcx> for Lub<'a, 'tcx, 'tcx> {
|
||||
|
||||
fn binders<T>(&mut self, a: &ty::Binder<T>, b: &ty::Binder<T>)
|
||||
-> RelateResult<'tcx, ty::Binder<T>>
|
||||
where T: Relate<'a, 'tcx>
|
||||
where T: Relate<'tcx>
|
||||
{
|
||||
self.fields.higher_ranked_lub(a, b)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> LatticeDir<'a,'tcx> for Lub<'a, 'tcx, 'tcx> {
|
||||
fn infcx(&self) -> &'a InferCtxt<'a, 'tcx, 'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> LatticeDir<'a, 'gcx, 'tcx> for Lub<'a, 'gcx, 'tcx> {
|
||||
fn infcx(&self) -> &'a InferCtxt<'a, 'gcx, 'tcx> {
|
||||
self.fields.infcx
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,6 @@ use util::nodemap::{FnvHashMap, FnvHashSet, NodeMap};
|
||||
|
||||
use self::combine::CombineFields;
|
||||
use self::region_inference::{RegionVarBindings, RegionSnapshot};
|
||||
use self::error_reporting::ErrorReporting;
|
||||
use self::unify_key::ToType;
|
||||
|
||||
pub mod bivariate;
|
||||
@ -94,6 +93,13 @@ pub struct InferCtxt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
|
||||
|
||||
pub parameter_environment: ty::ParameterEnvironment<'gcx>,
|
||||
|
||||
/// Caches the results of trait selection. This cache is used
|
||||
/// for things that have to do with the parameters in scope.
|
||||
pub selection_cache: traits::SelectionCache<'tcx>,
|
||||
|
||||
/// Caches the results of trait evaluation.
|
||||
pub evaluation_cache: traits::EvaluationCache<'tcx>,
|
||||
|
||||
// the set of predicates on which errors have been reported, to
|
||||
// avoid reporting the same error twice.
|
||||
pub reported_trait_errors: RefCell<FnvHashSet<traits::TraitErrorKey<'tcx>>>,
|
||||
@ -407,6 +413,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx, 'tcx> {
|
||||
float_unification_table: RefCell::new(UnificationTable::new()),
|
||||
region_vars: RegionVarBindings::new(tcx),
|
||||
parameter_environment: param_env.unwrap_or(tcx.empty_parameter_environment()),
|
||||
selection_cache: traits::SelectionCache::new(),
|
||||
evaluation_cache: traits::EvaluationCache::new(),
|
||||
reported_trait_errors: RefCell::new(FnvHashSet()),
|
||||
normalize: false,
|
||||
projection_mode: projection_mode,
|
||||
@ -465,26 +473,32 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
}
|
||||
|
||||
InferCtxt::enter(self, None, None, ProjectionMode::Any, |infcx| {
|
||||
let mut selcx = traits::SelectionContext::new(&infcx);
|
||||
let cause = traits::ObligationCause::dummy();
|
||||
let traits::Normalized { value: result, obligations } =
|
||||
traits::normalize(&mut selcx, cause, &value);
|
||||
|
||||
debug!("normalize_associated_type: result={:?} obligations={:?}",
|
||||
result, obligations);
|
||||
|
||||
let mut fulfill_cx = traits::FulfillmentContext::new();
|
||||
|
||||
for obligation in obligations {
|
||||
fulfill_cx.register_predicate_obligation(&infcx, obligation);
|
||||
}
|
||||
|
||||
infcx.drain_fulfillment_cx_or_panic(DUMMY_SP, &mut fulfill_cx, &result)
|
||||
infcx.normalize_projections_in(&value)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> InferCtxt<'a, 'tcx, 'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
fn normalize_projections_in<T>(&self, value: &T) -> T
|
||||
where T : TypeFoldable<'tcx>
|
||||
{
|
||||
let mut selcx = traits::SelectionContext::new(self);
|
||||
let cause = traits::ObligationCause::dummy();
|
||||
let traits::Normalized { value: result, obligations } =
|
||||
traits::normalize(&mut selcx, cause, value);
|
||||
|
||||
debug!("normalize_projections_in: result={:?} obligations={:?}",
|
||||
result, obligations);
|
||||
|
||||
let mut fulfill_cx = traits::FulfillmentContext::new();
|
||||
|
||||
for obligation in obligations {
|
||||
fulfill_cx.register_predicate_obligation(self, obligation);
|
||||
}
|
||||
|
||||
self.drain_fulfillment_cx_or_panic(DUMMY_SP, &mut fulfill_cx, &result)
|
||||
}
|
||||
|
||||
pub fn drain_fulfillment_cx_or_panic<T>(&self,
|
||||
span: Span,
|
||||
fulfill_cx: &mut traits::FulfillmentContext<'tcx>,
|
||||
@ -543,7 +557,7 @@ pub fn drain_fulfillment_cx<T>(&self,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn freshener<'b>(&'b self) -> TypeFreshener<'b, 'tcx, 'tcx> {
|
||||
pub fn freshener<'b>(&'b self) -> TypeFreshener<'b, 'gcx, 'tcx> {
|
||||
freshen::TypeFreshener::new(self)
|
||||
}
|
||||
|
||||
@ -614,7 +628,7 @@ pub fn drain_fulfillment_cx<T>(&self,
|
||||
}
|
||||
|
||||
fn combine_fields(&'a self, a_is_expected: bool, trace: TypeTrace<'tcx>)
|
||||
-> CombineFields<'a, 'tcx, 'tcx> {
|
||||
-> CombineFields<'a, 'gcx, 'tcx> {
|
||||
CombineFields {
|
||||
infcx: self,
|
||||
a_is_expected: a_is_expected,
|
||||
@ -626,7 +640,7 @@ pub fn drain_fulfillment_cx<T>(&self,
|
||||
|
||||
pub fn equate<T>(&'a self, a_is_expected: bool, trace: TypeTrace<'tcx>, a: &T, b: &T)
|
||||
-> InferResult<'tcx, T>
|
||||
where T: Relate<'a, 'tcx>
|
||||
where T: Relate<'tcx>
|
||||
{
|
||||
let mut equate = self.combine_fields(a_is_expected, trace).equate();
|
||||
let result = equate.relate(a, b);
|
||||
@ -635,7 +649,7 @@ pub fn drain_fulfillment_cx<T>(&self,
|
||||
|
||||
pub fn sub<T>(&'a self, a_is_expected: bool, trace: TypeTrace<'tcx>, a: &T, b: &T)
|
||||
-> InferResult<'tcx, T>
|
||||
where T: Relate<'a, 'tcx>
|
||||
where T: Relate<'tcx>
|
||||
{
|
||||
let mut sub = self.combine_fields(a_is_expected, trace).sub();
|
||||
let result = sub.relate(a, b);
|
||||
@ -644,7 +658,7 @@ pub fn drain_fulfillment_cx<T>(&self,
|
||||
|
||||
pub fn lub<T>(&'a self, a_is_expected: bool, trace: TypeTrace<'tcx>, a: &T, b: &T)
|
||||
-> InferResult<'tcx, T>
|
||||
where T: Relate<'a, 'tcx>
|
||||
where T: Relate<'tcx>
|
||||
{
|
||||
let mut lub = self.combine_fields(a_is_expected, trace).lub();
|
||||
let result = lub.relate(a, b);
|
||||
@ -653,7 +667,7 @@ pub fn drain_fulfillment_cx<T>(&self,
|
||||
|
||||
pub fn glb<T>(&'a self, a_is_expected: bool, trace: TypeTrace<'tcx>, a: &T, b: &T)
|
||||
-> InferResult<'tcx, T>
|
||||
where T: Relate<'a, 'tcx>
|
||||
where T: Relate<'tcx>
|
||||
{
|
||||
let mut glb = self.combine_fields(a_is_expected, trace).glb();
|
||||
let result = glb.relate(a, b);
|
||||
@ -1412,8 +1426,8 @@ pub fn drain_fulfillment_cx<T>(&self,
|
||||
self.region_vars.verify_generic_bound(origin, kind, a, bound);
|
||||
}
|
||||
|
||||
pub fn can_equate<'b,T>(&'b self, a: &T, b: &T) -> UnitResult<'tcx>
|
||||
where T: Relate<'b,'tcx> + fmt::Debug
|
||||
pub fn can_equate<T>(&self, a: &T, b: &T) -> UnitResult<'tcx>
|
||||
where T: Relate<'tcx> + fmt::Debug
|
||||
{
|
||||
debug!("can_equate({:?}, {:?})", a, b);
|
||||
self.probe(|_| {
|
||||
@ -1438,21 +1452,24 @@ pub fn drain_fulfillment_cx<T>(&self,
|
||||
pub fn tables_are_tcx_tables(&self) -> bool {
|
||||
let tables: &RefCell<ty::Tables> = &self.tables;
|
||||
let tcx_tables: &RefCell<ty::Tables> = &self.tcx.tables;
|
||||
tables as *const _ == tcx_tables as *const _
|
||||
tables as *const _ as usize == tcx_tables as *const _ as usize
|
||||
}
|
||||
|
||||
pub fn type_moves_by_default(&self, ty: Ty<'tcx>, span: Span) -> bool {
|
||||
let ty = self.resolve_type_vars_if_possible(&ty);
|
||||
if ty.needs_infer() ||
|
||||
(ty.has_closure_types() && !self.tables_are_tcx_tables()) {
|
||||
// this can get called from typeck (by euv), and moves_by_default
|
||||
// rightly refuses to work with inference variables, but
|
||||
// moves_by_default has a cache, which we want to use in other
|
||||
// cases.
|
||||
!traits::type_known_to_meet_builtin_bound(self, ty, ty::BoundCopy, span)
|
||||
} else {
|
||||
ty.moves_by_default(self.tcx, &self.parameter_environment, span)
|
||||
if let Some(ty) = self.tcx.lift_to_global(&ty) {
|
||||
// HACK(eddyb) Temporarily handle infer type in the global tcx.
|
||||
if !ty.needs_infer() &&
|
||||
!(ty.has_closure_types() && !self.tables_are_tcx_tables()) {
|
||||
return ty.moves_by_default(self.tcx.global_tcx(), self.param_env(), span);
|
||||
}
|
||||
}
|
||||
|
||||
// this can get called from typeck (by euv), and moves_by_default
|
||||
// rightly refuses to work with inference variables, but
|
||||
// moves_by_default has a cache, which we want to use in other
|
||||
// cases.
|
||||
!traits::type_known_to_meet_builtin_bound(self, ty, ty::BoundCopy, span)
|
||||
}
|
||||
|
||||
pub fn node_method_ty(&self, method_call: ty::MethodCall)
|
||||
@ -1495,7 +1512,7 @@ pub fn drain_fulfillment_cx<T>(&self,
|
||||
self.tables.borrow().upvar_capture_map.get(&upvar_id).cloned()
|
||||
}
|
||||
|
||||
pub fn param_env(&self) -> &ty::ParameterEnvironment<'tcx> {
|
||||
pub fn param_env(&self) -> &ty::ParameterEnvironment<'gcx> {
|
||||
&self.parameter_environment
|
||||
}
|
||||
|
||||
@ -1526,14 +1543,20 @@ pub fn drain_fulfillment_cx<T>(&self,
|
||||
substs);
|
||||
|
||||
if self.normalize {
|
||||
self.tcx.normalize_associated_type(&closure_ty)
|
||||
let closure_ty = self.tcx.erase_regions(&closure_ty);
|
||||
|
||||
if !closure_ty.has_projection_types() {
|
||||
return closure_ty;
|
||||
}
|
||||
|
||||
self.normalize_projections_in(&closure_ty)
|
||||
} else {
|
||||
closure_ty
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> TypeTrace<'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> TypeTrace<'tcx> {
|
||||
pub fn span(&self) -> Span {
|
||||
self.origin.span()
|
||||
}
|
||||
@ -1549,7 +1572,7 @@ impl<'a, 'tcx> TypeTrace<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn dummy(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> TypeTrace<'tcx> {
|
||||
pub fn dummy(tcx: TyCtxt<'a, 'gcx, 'tcx>) -> TypeTrace<'tcx> {
|
||||
TypeTrace {
|
||||
origin: TypeOrigin::Misc(codemap::DUMMY_SP),
|
||||
values: Types(ExpectedFound {
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
use super::{InferCtxt, FixupError, FixupResult};
|
||||
use ty::{self, Ty, TyCtxt, TypeFoldable};
|
||||
use ty::fold::TypeFolder;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// OPPORTUNISTIC TYPE RESOLVER
|
||||
@ -23,14 +24,14 @@ pub struct OpportunisticTypeResolver<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
|
||||
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> OpportunisticTypeResolver<'a, 'tcx, 'tcx> {
|
||||
pub fn new(infcx: &'a InferCtxt<'a, 'tcx, 'tcx>) -> OpportunisticTypeResolver<'a, 'tcx, 'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> OpportunisticTypeResolver<'a, 'gcx, 'tcx> {
|
||||
pub fn new(infcx: &'a InferCtxt<'a, 'gcx, 'tcx>) -> Self {
|
||||
OpportunisticTypeResolver { infcx: infcx }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> ty::fold::TypeFolder<'tcx> for OpportunisticTypeResolver<'a, 'tcx, 'tcx> {
|
||||
fn tcx<'b>(&'b self) -> TyCtxt<'b, 'tcx, 'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for OpportunisticTypeResolver<'a, 'gcx, 'tcx> {
|
||||
fn tcx<'b>(&'b self) -> TyCtxt<'b, 'gcx, 'tcx> {
|
||||
self.infcx.tcx
|
||||
}
|
||||
|
||||
@ -51,14 +52,14 @@ pub struct OpportunisticTypeAndRegionResolver<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
|
||||
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> OpportunisticTypeAndRegionResolver<'a, 'tcx, 'tcx> {
|
||||
pub fn new(infcx: &'a InferCtxt<'a, 'tcx, 'tcx>) -> Self {
|
||||
impl<'a, 'gcx, 'tcx> OpportunisticTypeAndRegionResolver<'a, 'gcx, 'tcx> {
|
||||
pub fn new(infcx: &'a InferCtxt<'a, 'gcx, 'tcx>) -> Self {
|
||||
OpportunisticTypeAndRegionResolver { infcx: infcx }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> ty::fold::TypeFolder<'tcx> for OpportunisticTypeAndRegionResolver<'a, 'tcx, 'tcx> {
|
||||
fn tcx<'b>(&'b self) -> TyCtxt<'b, 'tcx, 'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for OpportunisticTypeAndRegionResolver<'a, 'gcx, 'tcx> {
|
||||
fn tcx<'b>(&'b self) -> TyCtxt<'b, 'gcx, 'tcx> {
|
||||
self.infcx.tcx
|
||||
}
|
||||
|
||||
@ -85,8 +86,8 @@ impl<'a, 'tcx> ty::fold::TypeFolder<'tcx> for OpportunisticTypeAndRegionResolver
|
||||
/// Full type resolution replaces all type and region variables with
|
||||
/// their concrete results. If any variable cannot be replaced (never unified, etc)
|
||||
/// then an `Err` result is returned.
|
||||
pub fn fully_resolve<'a, 'tcx, T>(infcx: &InferCtxt<'a, 'tcx, 'tcx>,
|
||||
value: &T) -> FixupResult<T>
|
||||
pub fn fully_resolve<'a, 'gcx, 'tcx, T>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
|
||||
value: &T) -> FixupResult<T>
|
||||
where T : TypeFoldable<'tcx>
|
||||
{
|
||||
let mut full_resolver = FullTypeResolver { infcx: infcx, err: None };
|
||||
@ -104,8 +105,8 @@ struct FullTypeResolver<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
|
||||
err: Option<FixupError>,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> ty::fold::TypeFolder<'tcx> for FullTypeResolver<'a, 'tcx, 'tcx> {
|
||||
fn tcx<'b>(&'b self) -> TyCtxt<'b, 'tcx, 'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for FullTypeResolver<'a, 'gcx, 'tcx> {
|
||||
fn tcx<'b>(&'b self) -> TyCtxt<'b, 'gcx, 'tcx> {
|
||||
self.infcx.tcx
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,6 @@
|
||||
// except according to those terms.
|
||||
|
||||
use super::combine::CombineFields;
|
||||
use super::higher_ranked::HigherRankedRelations;
|
||||
use super::SubregionOrigin;
|
||||
use super::type_variable::{SubtypeOf, SupertypeOf};
|
||||
|
||||
@ -24,8 +23,8 @@ pub struct Sub<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
|
||||
fields: CombineFields<'a, 'gcx, 'tcx>,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Sub<'a, 'tcx, 'tcx> {
|
||||
pub fn new(f: CombineFields<'a, 'tcx, 'tcx>) -> Sub<'a, 'tcx, 'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> Sub<'a, 'gcx, 'tcx> {
|
||||
pub fn new(f: CombineFields<'a, 'gcx, 'tcx>) -> Sub<'a, 'gcx, 'tcx> {
|
||||
Sub { fields: f }
|
||||
}
|
||||
|
||||
@ -34,9 +33,9 @@ impl<'a, 'tcx> Sub<'a, 'tcx, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> TypeRelation<'a, 'tcx> for Sub<'a, 'tcx, 'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> TypeRelation<'a, 'gcx, 'tcx> for Sub<'a, 'gcx, 'tcx> {
|
||||
fn tag(&self) -> &'static str { "Sub" }
|
||||
fn tcx(&self) -> TyCtxt<'a, 'tcx, 'tcx> { self.fields.infcx.tcx }
|
||||
fn tcx(&self) -> TyCtxt<'a, 'gcx, 'tcx> { self.fields.infcx.tcx }
|
||||
fn a_is_expected(&self) -> bool { self.fields.a_is_expected }
|
||||
|
||||
fn with_cause<F,R>(&mut self, cause: Cause, f: F) -> R
|
||||
@ -50,11 +49,11 @@ impl<'a, 'tcx> TypeRelation<'a, 'tcx> for Sub<'a, 'tcx, 'tcx> {
|
||||
r
|
||||
}
|
||||
|
||||
fn relate_with_variance<T:Relate<'a,'tcx>>(&mut self,
|
||||
variance: ty::Variance,
|
||||
a: &T,
|
||||
b: &T)
|
||||
-> RelateResult<'tcx, T>
|
||||
fn relate_with_variance<T: Relate<'tcx>>(&mut self,
|
||||
variance: ty::Variance,
|
||||
a: &T,
|
||||
b: &T)
|
||||
-> RelateResult<'tcx, T>
|
||||
{
|
||||
match variance {
|
||||
ty::Invariant => self.fields.equate().relate(a, b),
|
||||
@ -115,7 +114,7 @@ impl<'a, 'tcx> TypeRelation<'a, 'tcx> for Sub<'a, 'tcx, 'tcx> {
|
||||
|
||||
fn binders<T>(&mut self, a: &ty::Binder<T>, b: &ty::Binder<T>)
|
||||
-> RelateResult<'tcx, ty::Binder<T>>
|
||||
where T: Relate<'a,'tcx>
|
||||
where T: Relate<'tcx>
|
||||
{
|
||||
self.fields.higher_ranked_sub(a, b)
|
||||
}
|
||||
|
@ -12,8 +12,8 @@ use syntax::ast;
|
||||
use ty::{self, IntVarValue, Ty, TyCtxt};
|
||||
use rustc_data_structures::unify::{Combine, UnifyKey};
|
||||
|
||||
pub trait ToType<'tcx> {
|
||||
fn to_type<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Ty<'tcx>;
|
||||
pub trait ToType {
|
||||
fn to_type<'a, 'gcx, 'tcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx>;
|
||||
}
|
||||
|
||||
impl UnifyKey for ty::IntVid {
|
||||
@ -50,8 +50,8 @@ impl UnifyKey for ty::RegionVid {
|
||||
fn tag(_: Option<ty::RegionVid>) -> &'static str { "RegionVid" }
|
||||
}
|
||||
|
||||
impl<'tcx> ToType<'tcx> for IntVarValue {
|
||||
fn to_type<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Ty<'tcx> {
|
||||
impl ToType for IntVarValue {
|
||||
fn to_type<'a, 'gcx, 'tcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> {
|
||||
match *self {
|
||||
ty::IntType(i) => tcx.mk_mach_int(i),
|
||||
ty::UintType(i) => tcx.mk_mach_uint(i),
|
||||
@ -68,8 +68,8 @@ impl UnifyKey for ty::FloatVid {
|
||||
fn tag(_: Option<ty::FloatVid>) -> &'static str { "FloatVid" }
|
||||
}
|
||||
|
||||
impl<'tcx> ToType<'tcx> for ast::FloatTy {
|
||||
fn to_type<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Ty<'tcx> {
|
||||
impl ToType for ast::FloatTy {
|
||||
fn to_type<'a, 'gcx, 'tcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> {
|
||||
tcx.mk_mach_float(*self)
|
||||
}
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ impl<'a, 'tcx> LvalueTy<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for LvalueTy<'tcx> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
match *self {
|
||||
LvalueTy::Ty { ty } => LvalueTy::Ty { ty: ty.fold_with(folder) },
|
||||
LvalueTy::Downcast { adt_def, substs, variant_index } => {
|
||||
|
@ -86,8 +86,8 @@ fn overlap<'cx, 'tcx>(selcx: &mut SelectionContext<'cx, 'tcx, 'tcx>,
|
||||
Some(selcx.infcx().resolve_type_vars_if_possible(&a_impl_header))
|
||||
}
|
||||
|
||||
pub fn trait_ref_is_knowable<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
trait_ref: &ty::TraitRef<'tcx>) -> bool
|
||||
pub fn trait_ref_is_knowable<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
trait_ref: &ty::TraitRef<'tcx>) -> bool
|
||||
{
|
||||
debug!("trait_ref_is_knowable(trait_ref={:?})", trait_ref);
|
||||
|
||||
@ -129,9 +129,9 @@ pub enum OrphanCheckErr<'tcx> {
|
||||
///
|
||||
/// 1. All type parameters in `Self` must be "covered" by some local type constructor.
|
||||
/// 2. Some local type must appear in `Self`.
|
||||
pub fn orphan_check<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
impl_def_id: DefId)
|
||||
-> Result<(), OrphanCheckErr<'tcx>>
|
||||
pub fn orphan_check<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
impl_def_id: DefId)
|
||||
-> Result<(), OrphanCheckErr<'tcx>>
|
||||
{
|
||||
debug!("orphan_check({:?})", impl_def_id);
|
||||
|
||||
@ -150,10 +150,10 @@ pub fn orphan_check<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
orphan_check_trait_ref(tcx, &trait_ref, InferIsLocal(false))
|
||||
}
|
||||
|
||||
fn orphan_check_trait_ref<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
trait_ref: &ty::TraitRef<'tcx>,
|
||||
infer_is_local: InferIsLocal)
|
||||
-> Result<(), OrphanCheckErr<'tcx>>
|
||||
fn orphan_check_trait_ref<'tcx>(tcx: TyCtxt,
|
||||
trait_ref: &ty::TraitRef<'tcx>,
|
||||
infer_is_local: InferIsLocal)
|
||||
-> Result<(), OrphanCheckErr<'tcx>>
|
||||
{
|
||||
debug!("orphan_check_trait_ref(trait_ref={:?}, infer_is_local={})",
|
||||
trait_ref, infer_is_local.0);
|
||||
@ -198,11 +198,8 @@ fn orphan_check_trait_ref<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
return Err(OrphanCheckErr::NoLocalInputType);
|
||||
}
|
||||
|
||||
fn uncovered_tys<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
ty: Ty<'tcx>,
|
||||
infer_is_local: InferIsLocal)
|
||||
-> Vec<Ty<'tcx>>
|
||||
{
|
||||
fn uncovered_tys<'tcx>(tcx: TyCtxt, ty: Ty<'tcx>, infer_is_local: InferIsLocal)
|
||||
-> Vec<Ty<'tcx>> {
|
||||
if ty_is_local_constructor(tcx, ty, infer_is_local) {
|
||||
vec![]
|
||||
} else if fundamental_ty(tcx, ty) {
|
||||
@ -214,7 +211,7 @@ fn uncovered_tys<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
}
|
||||
}
|
||||
|
||||
fn is_type_parameter<'tcx>(ty: Ty<'tcx>) -> bool {
|
||||
fn is_type_parameter(ty: Ty) -> bool {
|
||||
match ty.sty {
|
||||
// FIXME(#20590) straighten story about projection types
|
||||
ty::TyProjection(..) | ty::TyParam(..) => true,
|
||||
@ -222,16 +219,12 @@ fn is_type_parameter<'tcx>(ty: Ty<'tcx>) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
fn ty_is_local<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
ty: Ty<'tcx>,
|
||||
infer_is_local: InferIsLocal) -> bool
|
||||
{
|
||||
fn ty_is_local(tcx: TyCtxt, ty: Ty, infer_is_local: InferIsLocal) -> bool {
|
||||
ty_is_local_constructor(tcx, ty, infer_is_local) ||
|
||||
fundamental_ty(tcx, ty) && ty.walk_shallow().any(|t| ty_is_local(tcx, t, infer_is_local))
|
||||
}
|
||||
|
||||
fn fundamental_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> bool
|
||||
{
|
||||
fn fundamental_ty(tcx: TyCtxt, ty: Ty) -> bool {
|
||||
match ty.sty {
|
||||
ty::TyBox(..) | ty::TyRef(..) =>
|
||||
true,
|
||||
@ -244,11 +237,7 @@ fn fundamental_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> bool
|
||||
}
|
||||
}
|
||||
|
||||
fn ty_is_local_constructor<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
ty: Ty<'tcx>,
|
||||
infer_is_local: InferIsLocal)
|
||||
-> bool
|
||||
{
|
||||
fn ty_is_local_constructor(tcx: TyCtxt, ty: Ty, infer_is_local: InferIsLocal)-> bool {
|
||||
debug!("ty_is_local_constructor({:?})", ty);
|
||||
|
||||
match ty.sty {
|
||||
|
@ -46,10 +46,10 @@ pub struct TraitErrorKey<'tcx> {
|
||||
predicate: ty::Predicate<'tcx>
|
||||
}
|
||||
|
||||
impl<'tcx> TraitErrorKey<'tcx> {
|
||||
fn from_error<'a>(infcx: &InferCtxt<'a, 'tcx, 'tcx>,
|
||||
e: &FulfillmentError<'tcx>,
|
||||
warning_node_id: Option<ast::NodeId>) -> Self {
|
||||
impl<'a, 'gcx, 'tcx> TraitErrorKey<'tcx> {
|
||||
fn from_error(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
|
||||
e: &FulfillmentError<'tcx>,
|
||||
warning_node_id: Option<ast::NodeId>) -> Self {
|
||||
let predicate =
|
||||
infcx.resolve_type_vars_if_possible(&e.obligation.predicate);
|
||||
TraitErrorKey {
|
||||
@ -60,7 +60,7 @@ impl<'tcx> TraitErrorKey<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> InferCtxt<'a, 'tcx, 'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
pub fn report_fulfillment_errors(&self, errors: &Vec<FulfillmentError<'tcx>>) {
|
||||
for error in errors {
|
||||
self.report_fulfillment_error(error, None);
|
||||
@ -558,7 +558,7 @@ pub fn report_selection_error(&self,
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
pub fn recursive_type_with_infinite_size_error(self,
|
||||
type_def_id: DefId)
|
||||
-> DiagnosticBuilder<'tcx>
|
||||
@ -646,7 +646,7 @@ pub fn report_object_safety_error(self,
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> InferCtxt<'a, 'tcx, 'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
fn maybe_report_ambiguity(&self, obligation: &PredicateObligation<'tcx>) {
|
||||
// Unable to successfully determine, probably means
|
||||
// insufficient type information, but could mean
|
||||
@ -737,14 +737,13 @@ fn maybe_report_ambiguity(&self, obligation: &PredicateObligation<'tcx>) {
|
||||
/// Returns whether the trait predicate may apply for *some* assignment
|
||||
/// to the type parameters.
|
||||
fn predicate_can_apply(&self, pred: ty::PolyTraitRef<'tcx>) -> bool {
|
||||
struct ParamToVarFolder<'a, 'tcx: 'a> {
|
||||
infcx: &'a InferCtxt<'a, 'tcx, 'tcx>,
|
||||
struct ParamToVarFolder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
|
||||
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
|
||||
var_map: FnvHashMap<Ty<'tcx>, Ty<'tcx>>
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> TypeFolder<'tcx> for ParamToVarFolder<'a, 'tcx>
|
||||
{
|
||||
fn tcx<'b>(&'b self) -> TyCtxt<'b, 'tcx, 'tcx> { self.infcx.tcx }
|
||||
impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for ParamToVarFolder<'a, 'gcx, 'tcx> {
|
||||
fn tcx<'b>(&'b self) -> TyCtxt<'b, 'gcx, 'tcx> { self.infcx.tcx }
|
||||
|
||||
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
|
||||
if let ty::TyParam(..) = ty.sty {
|
||||
|
@ -111,7 +111,7 @@ pub struct PendingPredicateObligation<'tcx> {
|
||||
pub stalled_on: Vec<Ty<'tcx>>,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> FulfillmentContext<'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> FulfillmentContext<'tcx> {
|
||||
/// Creates a new fulfillment context.
|
||||
pub fn new() -> FulfillmentContext<'tcx> {
|
||||
FulfillmentContext {
|
||||
@ -130,7 +130,7 @@ impl<'a, 'tcx> FulfillmentContext<'tcx> {
|
||||
/// something concrete. If this fails, we'll unify `$0` with
|
||||
/// `projection_ty` again.
|
||||
pub fn normalize_projection_type(&mut self,
|
||||
infcx: &InferCtxt<'a, 'tcx, 'tcx>,
|
||||
infcx: &InferCtxt<'a, 'gcx, 'tcx>,
|
||||
projection_ty: ty::ProjectionTy<'tcx>,
|
||||
cause: ObligationCause<'tcx>)
|
||||
-> Ty<'tcx>
|
||||
@ -155,7 +155,7 @@ impl<'a, 'tcx> FulfillmentContext<'tcx> {
|
||||
}
|
||||
|
||||
pub fn register_builtin_bound(&mut self,
|
||||
infcx: &InferCtxt<'a, 'tcx, 'tcx>,
|
||||
infcx: &InferCtxt<'a, 'gcx, 'tcx>,
|
||||
ty: Ty<'tcx>,
|
||||
builtin_bound: ty::BuiltinBound,
|
||||
cause: ObligationCause<'tcx>)
|
||||
@ -177,7 +177,7 @@ impl<'a, 'tcx> FulfillmentContext<'tcx> {
|
||||
}
|
||||
|
||||
pub fn register_predicate_obligation(&mut self,
|
||||
infcx: &InferCtxt<'a, 'tcx, 'tcx>,
|
||||
infcx: &InferCtxt<'a, 'gcx, 'tcx>,
|
||||
obligation: PredicateObligation<'tcx>)
|
||||
{
|
||||
// this helps to reduce duplicate errors, as well as making
|
||||
@ -200,7 +200,7 @@ impl<'a, 'tcx> FulfillmentContext<'tcx> {
|
||||
}
|
||||
|
||||
pub fn register_rfc1592_obligation(&mut self,
|
||||
_infcx: &InferCtxt<'a, 'tcx, 'tcx>,
|
||||
_infcx: &InferCtxt<'a, 'gcx, 'tcx>,
|
||||
obligation: PredicateObligation<'tcx>)
|
||||
{
|
||||
self.rfc1592_obligations.push(obligation);
|
||||
@ -217,7 +217,7 @@ impl<'a, 'tcx> FulfillmentContext<'tcx> {
|
||||
}
|
||||
|
||||
pub fn select_rfc1592_obligations(&mut self,
|
||||
infcx: &InferCtxt<'a, 'tcx, 'tcx>)
|
||||
infcx: &InferCtxt<'a, 'gcx, 'tcx>)
|
||||
-> Result<(),Vec<FulfillmentError<'tcx>>>
|
||||
{
|
||||
while !self.rfc1592_obligations.is_empty() {
|
||||
@ -232,7 +232,7 @@ impl<'a, 'tcx> FulfillmentContext<'tcx> {
|
||||
}
|
||||
|
||||
pub fn select_all_or_error(&mut self,
|
||||
infcx: &InferCtxt<'a, 'tcx, 'tcx>)
|
||||
infcx: &InferCtxt<'a, 'gcx, 'tcx>)
|
||||
-> Result<(),Vec<FulfillmentError<'tcx>>>
|
||||
{
|
||||
self.select_where_possible(infcx)?;
|
||||
@ -250,7 +250,7 @@ impl<'a, 'tcx> FulfillmentContext<'tcx> {
|
||||
}
|
||||
|
||||
pub fn select_where_possible(&mut self,
|
||||
infcx: &InferCtxt<'a, 'tcx, 'tcx>)
|
||||
infcx: &InferCtxt<'a, 'gcx, 'tcx>)
|
||||
-> Result<(),Vec<FulfillmentError<'tcx>>>
|
||||
{
|
||||
let mut selcx = SelectionContext::new(infcx);
|
||||
@ -261,7 +261,7 @@ impl<'a, 'tcx> FulfillmentContext<'tcx> {
|
||||
self.predicates.pending_obligations()
|
||||
}
|
||||
|
||||
fn is_duplicate_or_add(&mut self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
fn is_duplicate_or_add(&mut self, tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
predicate: &ty::Predicate<'tcx>)
|
||||
-> bool {
|
||||
// For "global" predicates -- that is, predicates that don't
|
||||
@ -289,7 +289,7 @@ impl<'a, 'tcx> FulfillmentContext<'tcx> {
|
||||
|
||||
/// Attempts to select obligations using `selcx`. If `only_new_obligations` is true, then it
|
||||
/// only attempts to select obligations that haven't been seen before.
|
||||
fn select(&mut self, selcx: &mut SelectionContext<'a, 'tcx, 'tcx>)
|
||||
fn select(&mut self, selcx: &mut SelectionContext<'a, 'gcx, 'tcx>)
|
||||
-> Result<(),Vec<FulfillmentError<'tcx>>> {
|
||||
debug!("select(obligation-forest-size={})", self.predicates.len());
|
||||
|
||||
@ -316,7 +316,8 @@ impl<'a, 'tcx> FulfillmentContext<'tcx> {
|
||||
// these are obligations that were proven to be true.
|
||||
for pending_obligation in outcome.completed {
|
||||
let predicate = &pending_obligation.obligation.predicate;
|
||||
selcx.tcx().fulfilled_predicates.borrow_mut().add_if_global(predicate);
|
||||
selcx.tcx().fulfilled_predicates.borrow_mut()
|
||||
.add_if_global(selcx.tcx(), predicate);
|
||||
}
|
||||
|
||||
errors.extend(
|
||||
@ -341,14 +342,15 @@ impl<'a, 'tcx> FulfillmentContext<'tcx> {
|
||||
}
|
||||
|
||||
/// Like `process_predicate1`, but wrap result into a pending predicate.
|
||||
fn process_predicate<'a,'tcx>(selcx: &mut SelectionContext<'a,'tcx, 'tcx>,
|
||||
tree_cache: &mut LocalFulfilledPredicates<'tcx>,
|
||||
pending_obligation: &mut PendingPredicateObligation<'tcx>,
|
||||
backtrace: Backtrace<PendingPredicateObligation<'tcx>>,
|
||||
region_obligations: &mut NodeMap<Vec<RegionObligation<'tcx>>>,
|
||||
rfc1592_obligations: &mut Vec<PredicateObligation<'tcx>>)
|
||||
-> Result<Option<Vec<PendingPredicateObligation<'tcx>>>,
|
||||
FulfillmentErrorCode<'tcx>>
|
||||
fn process_predicate<'a, 'gcx, 'tcx>(
|
||||
selcx: &mut SelectionContext<'a, 'gcx, 'tcx>,
|
||||
tree_cache: &mut LocalFulfilledPredicates<'tcx>,
|
||||
pending_obligation: &mut PendingPredicateObligation<'tcx>,
|
||||
backtrace: Backtrace<PendingPredicateObligation<'tcx>>,
|
||||
region_obligations: &mut NodeMap<Vec<RegionObligation<'tcx>>>,
|
||||
rfc1592_obligations: &mut Vec<PredicateObligation<'tcx>>)
|
||||
-> Result<Option<Vec<PendingPredicateObligation<'tcx>>>,
|
||||
FulfillmentErrorCode<'tcx>>
|
||||
{
|
||||
match process_predicate1(selcx, pending_obligation, region_obligations,
|
||||
rfc1592_obligations) {
|
||||
@ -362,8 +364,8 @@ fn process_predicate<'a,'tcx>(selcx: &mut SelectionContext<'a,'tcx, 'tcx>,
|
||||
}
|
||||
}
|
||||
|
||||
fn process_child_obligations<'a, 'tcx>(
|
||||
selcx: &mut SelectionContext<'a, 'tcx, 'tcx>,
|
||||
fn process_child_obligations<'a, 'gcx, 'tcx>(
|
||||
selcx: &mut SelectionContext<'a, 'gcx, 'tcx>,
|
||||
tree_cache: &mut LocalFulfilledPredicates<'tcx>,
|
||||
pending_obligation: &PredicateObligation<'tcx>,
|
||||
backtrace: Backtrace<PendingPredicateObligation<'tcx>>,
|
||||
@ -464,7 +466,7 @@ struct AncestorSet<'b, 'tcx: 'b> {
|
||||
backtrace: Backtrace<'b, PendingPredicateObligation<'tcx>>,
|
||||
}
|
||||
|
||||
impl<'a, 'b, 'tcx> AncestorSet<'b, 'tcx> {
|
||||
impl<'a, 'b, 'gcx, 'tcx> AncestorSet<'b, 'tcx> {
|
||||
fn new(backtrace: &Backtrace<'b, PendingPredicateObligation<'tcx>>) -> Self {
|
||||
AncestorSet {
|
||||
populated: false,
|
||||
@ -478,7 +480,7 @@ impl<'a, 'b, 'tcx> AncestorSet<'b, 'tcx> {
|
||||
/// type-resolved). Returns `None` if not; otherwise, returns
|
||||
/// `Some` with the index within the backtrace.
|
||||
fn has(&mut self,
|
||||
infcx: &InferCtxt<'a, 'tcx, 'tcx>,
|
||||
infcx: &InferCtxt<'a, 'gcx, 'tcx>,
|
||||
predicate: &ty::Predicate<'tcx>)
|
||||
-> Option<usize> {
|
||||
// the first time, we have to populate the cache
|
||||
@ -514,8 +516,8 @@ impl<'a, 'b, 'tcx> AncestorSet<'b, 'tcx> {
|
||||
}
|
||||
|
||||
/// Return the set of type variables contained in a trait ref
|
||||
fn trait_ref_type_vars<'a, 'tcx>(selcx: &mut SelectionContext<'a, 'tcx, 'tcx>,
|
||||
t: ty::PolyTraitRef<'tcx>) -> Vec<Ty<'tcx>>
|
||||
fn trait_ref_type_vars<'a, 'gcx, 'tcx>(selcx: &mut SelectionContext<'a, 'gcx, 'tcx>,
|
||||
t: ty::PolyTraitRef<'tcx>) -> Vec<Ty<'tcx>>
|
||||
{
|
||||
t.skip_binder() // ok b/c this check doesn't care about regions
|
||||
.input_types()
|
||||
@ -531,12 +533,13 @@ fn trait_ref_type_vars<'a, 'tcx>(selcx: &mut SelectionContext<'a, 'tcx, 'tcx>,
|
||||
/// - `Ok(Some(v))` if the predicate is true, presuming that `v` are also true
|
||||
/// - `Ok(None)` if we don't have enough info to be sure
|
||||
/// - `Err` if the predicate does not hold
|
||||
fn process_predicate1<'a,'tcx>(selcx: &mut SelectionContext<'a,'tcx, 'tcx>,
|
||||
pending_obligation: &mut PendingPredicateObligation<'tcx>,
|
||||
region_obligations: &mut NodeMap<Vec<RegionObligation<'tcx>>>,
|
||||
rfc1592_obligations: &mut Vec<PredicateObligation<'tcx>>)
|
||||
-> Result<Option<Vec<PredicateObligation<'tcx>>>,
|
||||
FulfillmentErrorCode<'tcx>>
|
||||
fn process_predicate1<'a, 'gcx, 'tcx>(
|
||||
selcx: &mut SelectionContext<'a, 'gcx, 'tcx>,
|
||||
pending_obligation: &mut PendingPredicateObligation<'tcx>,
|
||||
region_obligations: &mut NodeMap<Vec<RegionObligation<'tcx>>>,
|
||||
rfc1592_obligations: &mut Vec<PredicateObligation<'tcx>>)
|
||||
-> Result<Option<Vec<PredicateObligation<'tcx>>>,
|
||||
FulfillmentErrorCode<'tcx>>
|
||||
{
|
||||
// if we were stalled on some unresolved variables, first check
|
||||
// whether any of them have been resolved; if not, don't bother
|
||||
@ -722,9 +725,9 @@ fn process_predicate1<'a,'tcx>(selcx: &mut SelectionContext<'a,'tcx, 'tcx>,
|
||||
/// - it also appears in the backtrace at some position `X`; and,
|
||||
/// - all the predicates at positions `X..` between `X` an the top are
|
||||
/// also defaulted traits.
|
||||
fn coinductive_match<'a, 'tcx>(selcx: &mut SelectionContext<'a, 'tcx, 'tcx>,
|
||||
cycle: &[PredicateObligation<'tcx>])
|
||||
-> bool
|
||||
fn coinductive_match<'a, 'gcx, 'tcx>(selcx: &mut SelectionContext<'a, 'gcx, 'tcx>,
|
||||
cycle: &[PredicateObligation<'tcx>])
|
||||
-> bool
|
||||
{
|
||||
let len = cycle.len();
|
||||
|
||||
@ -740,9 +743,9 @@ fn coinductive_match<'a, 'tcx>(selcx: &mut SelectionContext<'a, 'tcx, 'tcx>,
|
||||
})
|
||||
}
|
||||
|
||||
fn coinductive_obligation<'a, 'tcx>(selcx: &SelectionContext<'a, 'tcx, 'tcx>,
|
||||
obligation: &PredicateObligation<'tcx>)
|
||||
-> bool {
|
||||
fn coinductive_obligation<'a, 'gcx, 'tcx>(selcx: &SelectionContext<'a, 'gcx, 'tcx>,
|
||||
obligation: &PredicateObligation<'tcx>)
|
||||
-> bool {
|
||||
match obligation.predicate {
|
||||
ty::Predicate::Trait(ref data) => {
|
||||
selcx.tcx().trait_has_default_impl(data.def_id())
|
||||
@ -790,8 +793,8 @@ impl<'tcx> LocalFulfilledPredicates<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> GlobalFulfilledPredicates<'tcx> {
|
||||
pub fn new(dep_graph: DepGraph) -> GlobalFulfilledPredicates<'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> GlobalFulfilledPredicates<'gcx> {
|
||||
pub fn new(dep_graph: DepGraph) -> GlobalFulfilledPredicates<'gcx> {
|
||||
GlobalFulfilledPredicates {
|
||||
set: FnvHashSet(),
|
||||
dep_graph: dep_graph,
|
||||
@ -822,15 +825,17 @@ impl<'tcx> GlobalFulfilledPredicates<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn add_if_global(&mut self, key: &ty::Predicate<'tcx>) {
|
||||
fn add_if_global(&mut self, tcx: TyCtxt<'a, 'gcx, 'tcx>, key: &ty::Predicate<'tcx>) {
|
||||
if let ty::Predicate::Trait(ref data) = *key {
|
||||
// We only add things to the global predicate registry
|
||||
// after the current task has proved them, and hence
|
||||
// already has the required read edges, so we don't need
|
||||
// to add any more edges here.
|
||||
if data.is_global() {
|
||||
if self.set.insert(data.clone()) {
|
||||
debug!("add_if_global: global predicate `{:?}` added", data);
|
||||
if let Some(data) = tcx.lift_to_global(data) {
|
||||
if self.set.insert(data.clone()) {
|
||||
debug!("add_if_global: global predicate `{:?}` added", data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -316,11 +316,11 @@ pub fn predicates_for_generics<'tcx>(cause: ObligationCause<'tcx>,
|
||||
/// `bound` or is not known to meet bound (note that this is
|
||||
/// conservative towards *no impl*, which is the opposite of the
|
||||
/// `evaluate` methods).
|
||||
pub fn type_known_to_meet_builtin_bound<'a,'tcx>(infcx: &InferCtxt<'a,'tcx, 'tcx>,
|
||||
ty: Ty<'tcx>,
|
||||
bound: ty::BuiltinBound,
|
||||
span: Span)
|
||||
-> bool
|
||||
pub fn type_known_to_meet_builtin_bound<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
|
||||
ty: Ty<'tcx>,
|
||||
bound: ty::BuiltinBound,
|
||||
span: Span)
|
||||
-> bool
|
||||
{
|
||||
debug!("type_known_to_meet_builtin_bound(ty={:?}, bound={:?})",
|
||||
ty,
|
||||
|
@ -53,7 +53,7 @@ pub enum MethodViolationCode {
|
||||
Generic,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
pub fn is_object_safe(self, trait_def_id: DefId) -> bool {
|
||||
// Because we query yes/no results frequently, we keep a cache:
|
||||
let def = self.lookup_trait_def(trait_def_id);
|
||||
@ -173,8 +173,8 @@ fn trait_has_sized_self(self, trait_def_id: DefId) -> bool {
|
||||
}
|
||||
|
||||
fn generics_require_sized_self(self,
|
||||
generics: &ty::Generics<'tcx>,
|
||||
predicates: &ty::GenericPredicates<'tcx>)
|
||||
generics: &ty::Generics<'gcx>,
|
||||
predicates: &ty::GenericPredicates<'gcx>)
|
||||
-> bool
|
||||
{
|
||||
let sized_def_id = match self.lang_items.sized_trait() {
|
||||
@ -210,7 +210,7 @@ fn generics_require_sized_self(self,
|
||||
/// Returns `Some(_)` if this method makes the containing trait not object safe.
|
||||
fn object_safety_violation_for_method(self,
|
||||
trait_def_id: DefId,
|
||||
method: &ty::Method<'tcx>)
|
||||
method: &ty::Method<'gcx>)
|
||||
-> Option<MethodViolationCode>
|
||||
{
|
||||
// Any method that has a `Self : Sized` requisite is otherwise
|
||||
|
@ -171,8 +171,8 @@ struct ProjectionTyCandidateSet<'tcx> {
|
||||
/// for<...> <T as Trait>::U == V
|
||||
///
|
||||
/// If successful, this may result in additional obligations.
|
||||
pub fn poly_project_and_unify_type<'cx,'tcx>(
|
||||
selcx: &mut SelectionContext<'cx,'tcx, 'tcx>,
|
||||
pub fn poly_project_and_unify_type<'cx, 'gcx, 'tcx>(
|
||||
selcx: &mut SelectionContext<'cx, 'gcx, 'tcx>,
|
||||
obligation: &PolyProjectionObligation<'tcx>)
|
||||
-> Result<Option<Vec<PredicateObligation<'tcx>>>, MismatchedProjectionTypes<'tcx>>
|
||||
{
|
||||
@ -204,8 +204,8 @@ pub fn poly_project_and_unify_type<'cx,'tcx>(
|
||||
/// <T as Trait>::U == V
|
||||
///
|
||||
/// If successful, this may result in additional obligations.
|
||||
fn project_and_unify_type<'cx,'tcx>(
|
||||
selcx: &mut SelectionContext<'cx,'tcx, 'tcx>,
|
||||
fn project_and_unify_type<'cx, 'gcx, 'tcx>(
|
||||
selcx: &mut SelectionContext<'cx, 'gcx, 'tcx>,
|
||||
obligation: &ProjectionObligation<'tcx>)
|
||||
-> Result<Option<Vec<PredicateObligation<'tcx>>>, MismatchedProjectionTypes<'tcx>>
|
||||
{
|
||||
@ -240,8 +240,10 @@ fn project_and_unify_type<'cx,'tcx>(
|
||||
}
|
||||
}
|
||||
|
||||
fn consider_unification_despite_ambiguity<'cx,'tcx>(selcx: &mut SelectionContext<'cx,'tcx, 'tcx>,
|
||||
obligation: &ProjectionObligation<'tcx>) {
|
||||
fn consider_unification_despite_ambiguity<'cx, 'gcx, 'tcx>(
|
||||
selcx: &mut SelectionContext<'cx, 'gcx, 'tcx>,
|
||||
obligation: &ProjectionObligation<'tcx>)
|
||||
{
|
||||
debug!("consider_unification_despite_ambiguity(obligation={:?})",
|
||||
obligation);
|
||||
|
||||
@ -295,21 +297,23 @@ fn consider_unification_despite_ambiguity<'cx,'tcx>(selcx: &mut SelectionContext
|
||||
/// them with a fully resolved type where possible. The return value
|
||||
/// combines the normalized result and any additional obligations that
|
||||
/// were incurred as result.
|
||||
pub fn normalize<'a,'b,'tcx,T>(selcx: &'a mut SelectionContext<'b,'tcx, 'tcx>,
|
||||
cause: ObligationCause<'tcx>,
|
||||
value: &T)
|
||||
-> Normalized<'tcx, T>
|
||||
pub fn normalize<'a, 'b, 'gcx, 'tcx, T>(selcx: &'a mut SelectionContext<'b, 'gcx, 'tcx>,
|
||||
cause: ObligationCause<'tcx>,
|
||||
value: &T)
|
||||
-> Normalized<'tcx, T>
|
||||
where T : TypeFoldable<'tcx>
|
||||
{
|
||||
normalize_with_depth(selcx, cause, 0, value)
|
||||
}
|
||||
|
||||
/// As `normalize`, but with a custom depth.
|
||||
pub fn normalize_with_depth<'a,'b,'tcx,T>(selcx: &'a mut SelectionContext<'b,'tcx, 'tcx>,
|
||||
cause: ObligationCause<'tcx>,
|
||||
depth: usize,
|
||||
value: &T)
|
||||
-> Normalized<'tcx, T>
|
||||
pub fn normalize_with_depth<'a, 'b, 'gcx, 'tcx, T>(
|
||||
selcx: &'a mut SelectionContext<'b, 'gcx, 'tcx>,
|
||||
cause: ObligationCause<'tcx>,
|
||||
depth: usize,
|
||||
value: &T)
|
||||
-> Normalized<'tcx, T>
|
||||
|
||||
where T : TypeFoldable<'tcx>
|
||||
{
|
||||
let mut normalizer = AssociatedTypeNormalizer::new(selcx, cause, depth);
|
||||
@ -321,18 +325,18 @@ pub fn normalize_with_depth<'a,'b,'tcx,T>(selcx: &'a mut SelectionContext<'b,'tc
|
||||
}
|
||||
}
|
||||
|
||||
struct AssociatedTypeNormalizer<'a,'b:'a,'tcx:'b> {
|
||||
selcx: &'a mut SelectionContext<'b,'tcx, 'tcx>,
|
||||
struct AssociatedTypeNormalizer<'a, 'b: 'a, 'gcx: 'b+'tcx, 'tcx: 'b> {
|
||||
selcx: &'a mut SelectionContext<'b, 'gcx, 'tcx>,
|
||||
cause: ObligationCause<'tcx>,
|
||||
obligations: Vec<PredicateObligation<'tcx>>,
|
||||
depth: usize,
|
||||
}
|
||||
|
||||
impl<'a,'b,'tcx> AssociatedTypeNormalizer<'a,'b,'tcx> {
|
||||
fn new(selcx: &'a mut SelectionContext<'b,'tcx, 'tcx>,
|
||||
impl<'a, 'b, 'gcx, 'tcx> AssociatedTypeNormalizer<'a, 'b, 'gcx, 'tcx> {
|
||||
fn new(selcx: &'a mut SelectionContext<'b, 'gcx, 'tcx>,
|
||||
cause: ObligationCause<'tcx>,
|
||||
depth: usize)
|
||||
-> AssociatedTypeNormalizer<'a,'b,'tcx>
|
||||
-> AssociatedTypeNormalizer<'a, 'b, 'gcx, 'tcx>
|
||||
{
|
||||
AssociatedTypeNormalizer {
|
||||
selcx: selcx,
|
||||
@ -353,8 +357,8 @@ impl<'a,'b,'tcx> AssociatedTypeNormalizer<'a,'b,'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a,'b,'tcx> TypeFolder<'tcx> for AssociatedTypeNormalizer<'a,'b,'tcx> {
|
||||
fn tcx<'c>(&'c self) -> TyCtxt<'c, 'tcx, 'tcx> {
|
||||
impl<'a, 'b, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for AssociatedTypeNormalizer<'a, 'b, 'gcx, 'tcx> {
|
||||
fn tcx<'c>(&'c self) -> TyCtxt<'c, 'gcx, 'tcx> {
|
||||
self.selcx.tcx()
|
||||
}
|
||||
|
||||
@ -422,8 +426,8 @@ impl<'tcx,T> Normalized<'tcx,T> {
|
||||
/// there are unresolved type variables in the projection, we will
|
||||
/// substitute a fresh type variable `$X` and generate a new
|
||||
/// obligation `<T as Trait>::Item == $X` for later.
|
||||
pub fn normalize_projection_type<'a,'b,'tcx>(
|
||||
selcx: &'a mut SelectionContext<'b,'tcx, 'tcx>,
|
||||
pub fn normalize_projection_type<'a, 'b, 'gcx, 'tcx>(
|
||||
selcx: &'a mut SelectionContext<'b, 'gcx, 'tcx>,
|
||||
projection_ty: ty::ProjectionTy<'tcx>,
|
||||
cause: ObligationCause<'tcx>,
|
||||
depth: usize)
|
||||
@ -453,8 +457,8 @@ pub fn normalize_projection_type<'a,'b,'tcx>(
|
||||
/// as Trait>::Item`. The result is always a type (and possibly
|
||||
/// additional obligations). Returns `None` in the case of ambiguity,
|
||||
/// which indicates that there are unbound type variables.
|
||||
fn opt_normalize_projection_type<'a,'b,'tcx>(
|
||||
selcx: &'a mut SelectionContext<'b,'tcx, 'tcx>,
|
||||
fn opt_normalize_projection_type<'a, 'b, 'gcx, 'tcx>(
|
||||
selcx: &'a mut SelectionContext<'b, 'gcx, 'tcx>,
|
||||
projection_ty: ty::ProjectionTy<'tcx>,
|
||||
cause: ObligationCause<'tcx>,
|
||||
depth: usize)
|
||||
@ -542,11 +546,11 @@ fn opt_normalize_projection_type<'a,'b,'tcx>(
|
||||
/// an error for this obligation, but we legitimately should not,
|
||||
/// because it contains `[type error]`. Yuck! (See issue #29857 for
|
||||
/// one case where this arose.)
|
||||
fn normalize_to_error<'a,'tcx>(selcx: &mut SelectionContext<'a,'tcx, 'tcx>,
|
||||
projection_ty: ty::ProjectionTy<'tcx>,
|
||||
cause: ObligationCause<'tcx>,
|
||||
depth: usize)
|
||||
-> NormalizedTy<'tcx>
|
||||
fn normalize_to_error<'a, 'gcx, 'tcx>(selcx: &mut SelectionContext<'a, 'gcx, 'tcx>,
|
||||
projection_ty: ty::ProjectionTy<'tcx>,
|
||||
cause: ObligationCause<'tcx>,
|
||||
depth: usize)
|
||||
-> NormalizedTy<'tcx>
|
||||
{
|
||||
let trait_ref = projection_ty.trait_ref.to_poly_trait_ref();
|
||||
let trait_obligation = Obligation { cause: cause,
|
||||
@ -565,8 +569,8 @@ enum ProjectedTy<'tcx> {
|
||||
}
|
||||
|
||||
/// Compute the result of a projection type (if we can).
|
||||
fn project_type<'cx,'tcx>(
|
||||
selcx: &mut SelectionContext<'cx,'tcx, 'tcx>,
|
||||
fn project_type<'cx, 'gcx, 'tcx>(
|
||||
selcx: &mut SelectionContext<'cx, 'gcx, 'tcx>,
|
||||
obligation: &ProjectionTyObligation<'tcx>)
|
||||
-> Result<ProjectedTy<'tcx>, ProjectionTyError<'tcx>>
|
||||
{
|
||||
@ -748,8 +752,8 @@ fn project_type<'cx,'tcx>(
|
||||
/// The first thing we have to do is scan through the parameter
|
||||
/// environment to see whether there are any projection predicates
|
||||
/// there that can answer this question.
|
||||
fn assemble_candidates_from_param_env<'cx,'tcx>(
|
||||
selcx: &mut SelectionContext<'cx,'tcx, 'tcx>,
|
||||
fn assemble_candidates_from_param_env<'cx, 'gcx, 'tcx>(
|
||||
selcx: &mut SelectionContext<'cx, 'gcx, 'tcx>,
|
||||
obligation: &ProjectionTyObligation<'tcx>,
|
||||
obligation_trait_ref: &ty::TraitRef<'tcx>,
|
||||
candidate_set: &mut ProjectionTyCandidateSet<'tcx>)
|
||||
@ -774,8 +778,8 @@ fn assemble_candidates_from_param_env<'cx,'tcx>(
|
||||
/// ```
|
||||
///
|
||||
/// Here, for example, we could conclude that the result is `i32`.
|
||||
fn assemble_candidates_from_trait_def<'cx,'tcx>(
|
||||
selcx: &mut SelectionContext<'cx,'tcx, 'tcx>,
|
||||
fn assemble_candidates_from_trait_def<'cx, 'gcx, 'tcx>(
|
||||
selcx: &mut SelectionContext<'cx, 'gcx, 'tcx>,
|
||||
obligation: &ProjectionTyObligation<'tcx>,
|
||||
obligation_trait_ref: &ty::TraitRef<'tcx>,
|
||||
candidate_set: &mut ProjectionTyCandidateSet<'tcx>)
|
||||
@ -806,8 +810,8 @@ fn assemble_candidates_from_trait_def<'cx,'tcx>(
|
||||
bounds)
|
||||
}
|
||||
|
||||
fn assemble_candidates_from_predicates<'cx,'tcx,I>(
|
||||
selcx: &mut SelectionContext<'cx,'tcx, 'tcx>,
|
||||
fn assemble_candidates_from_predicates<'cx, 'gcx, 'tcx, I>(
|
||||
selcx: &mut SelectionContext<'cx, 'gcx, 'tcx>,
|
||||
obligation: &ProjectionTyObligation<'tcx>,
|
||||
obligation_trait_ref: &ty::TraitRef<'tcx>,
|
||||
candidate_set: &mut ProjectionTyCandidateSet<'tcx>,
|
||||
@ -853,8 +857,8 @@ fn assemble_candidates_from_predicates<'cx,'tcx,I>(
|
||||
}
|
||||
}
|
||||
|
||||
fn assemble_candidates_from_object_type<'cx,'tcx>(
|
||||
selcx: &mut SelectionContext<'cx,'tcx, 'tcx>,
|
||||
fn assemble_candidates_from_object_type<'cx, 'gcx, 'tcx>(
|
||||
selcx: &mut SelectionContext<'cx, 'gcx, 'tcx>,
|
||||
obligation: &ProjectionTyObligation<'tcx>,
|
||||
obligation_trait_ref: &ty::TraitRef<'tcx>,
|
||||
candidate_set: &mut ProjectionTyCandidateSet<'tcx>)
|
||||
@ -885,8 +889,8 @@ fn assemble_candidates_from_object_type<'cx,'tcx>(
|
||||
env_predicates)
|
||||
}
|
||||
|
||||
fn assemble_candidates_from_impls<'cx,'tcx>(
|
||||
selcx: &mut SelectionContext<'cx,'tcx, 'tcx>,
|
||||
fn assemble_candidates_from_impls<'cx, 'gcx, 'tcx>(
|
||||
selcx: &mut SelectionContext<'cx, 'gcx, 'tcx>,
|
||||
obligation: &ProjectionTyObligation<'tcx>,
|
||||
obligation_trait_ref: &ty::TraitRef<'tcx>,
|
||||
candidate_set: &mut ProjectionTyCandidateSet<'tcx>)
|
||||
@ -969,8 +973,8 @@ fn assemble_candidates_from_impls<'cx,'tcx>(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn confirm_candidate<'cx,'tcx>(
|
||||
selcx: &mut SelectionContext<'cx,'tcx, 'tcx>,
|
||||
fn confirm_candidate<'cx, 'gcx, 'tcx>(
|
||||
selcx: &mut SelectionContext<'cx, 'gcx, 'tcx>,
|
||||
obligation: &ProjectionTyObligation<'tcx>,
|
||||
candidate: ProjectionTyCandidate<'tcx>)
|
||||
-> (Ty<'tcx>, Vec<PredicateObligation<'tcx>>)
|
||||
@ -999,8 +1003,8 @@ fn confirm_candidate<'cx,'tcx>(
|
||||
}
|
||||
}
|
||||
|
||||
fn confirm_fn_pointer_candidate<'cx,'tcx>(
|
||||
selcx: &mut SelectionContext<'cx,'tcx, 'tcx>,
|
||||
fn confirm_fn_pointer_candidate<'cx, 'gcx, 'tcx>(
|
||||
selcx: &mut SelectionContext<'cx, 'gcx, 'tcx>,
|
||||
obligation: &ProjectionTyObligation<'tcx>,
|
||||
fn_type: Ty<'tcx>)
|
||||
-> (Ty<'tcx>, Vec<PredicateObligation<'tcx>>)
|
||||
@ -1010,8 +1014,8 @@ fn confirm_fn_pointer_candidate<'cx,'tcx>(
|
||||
confirm_callable_candidate(selcx, obligation, sig, util::TupleArgumentsFlag::Yes)
|
||||
}
|
||||
|
||||
fn confirm_closure_candidate<'cx,'tcx>(
|
||||
selcx: &mut SelectionContext<'cx,'tcx, 'tcx>,
|
||||
fn confirm_closure_candidate<'cx, 'gcx, 'tcx>(
|
||||
selcx: &mut SelectionContext<'cx, 'gcx, 'tcx>,
|
||||
obligation: &ProjectionTyObligation<'tcx>,
|
||||
vtable: VtableClosureData<'tcx, PredicateObligation<'tcx>>)
|
||||
-> (Ty<'tcx>, Vec<PredicateObligation<'tcx>>)
|
||||
@ -1033,8 +1037,8 @@ fn confirm_closure_candidate<'cx,'tcx>(
|
||||
(ty, obligations)
|
||||
}
|
||||
|
||||
fn confirm_callable_candidate<'cx,'tcx>(
|
||||
selcx: &mut SelectionContext<'cx,'tcx, 'tcx>,
|
||||
fn confirm_callable_candidate<'cx, 'gcx, 'tcx>(
|
||||
selcx: &mut SelectionContext<'cx, 'gcx, 'tcx>,
|
||||
obligation: &ProjectionTyObligation<'tcx>,
|
||||
fn_sig: &ty::PolyFnSig<'tcx>,
|
||||
flag: util::TupleArgumentsFlag)
|
||||
@ -1067,8 +1071,8 @@ fn confirm_callable_candidate<'cx,'tcx>(
|
||||
confirm_param_env_candidate(selcx, obligation, predicate)
|
||||
}
|
||||
|
||||
fn confirm_param_env_candidate<'cx,'tcx>(
|
||||
selcx: &mut SelectionContext<'cx,'tcx, 'tcx>,
|
||||
fn confirm_param_env_candidate<'cx, 'gcx, 'tcx>(
|
||||
selcx: &mut SelectionContext<'cx, 'gcx, 'tcx>,
|
||||
obligation: &ProjectionTyObligation<'tcx>,
|
||||
poly_projection: ty::PolyProjectionPredicate<'tcx>)
|
||||
-> (Ty<'tcx>, Vec<PredicateObligation<'tcx>>)
|
||||
@ -1106,8 +1110,8 @@ fn confirm_param_env_candidate<'cx,'tcx>(
|
||||
(projection.ty, vec!())
|
||||
}
|
||||
|
||||
fn confirm_impl_candidate<'cx,'tcx>(
|
||||
selcx: &mut SelectionContext<'cx,'tcx, 'tcx>,
|
||||
fn confirm_impl_candidate<'cx, 'gcx, 'tcx>(
|
||||
selcx: &mut SelectionContext<'cx, 'gcx, 'tcx>,
|
||||
obligation: &ProjectionTyObligation<'tcx>,
|
||||
impl_vtable: VtableImplData<'tcx, PredicateObligation<'tcx>>)
|
||||
-> (Ty<'tcx>, Vec<PredicateObligation<'tcx>>)
|
||||
@ -1146,10 +1150,11 @@ fn confirm_impl_candidate<'cx,'tcx>(
|
||||
///
|
||||
/// Based on the "projection mode", this lookup may in fact only examine the
|
||||
/// topmost impl. See the comments for `ProjectionMode` for more details.
|
||||
fn assoc_ty_def<'cx, 'tcx>(selcx: &SelectionContext<'cx, 'tcx, 'tcx>,
|
||||
impl_def_id: DefId,
|
||||
assoc_ty_name: ast::Name)
|
||||
-> Option<specialization_graph::NodeItem<Rc<ty::AssociatedType<'tcx>>>>
|
||||
fn assoc_ty_def<'cx, 'gcx, 'tcx>(
|
||||
selcx: &SelectionContext<'cx, 'gcx, 'tcx>,
|
||||
impl_def_id: DefId,
|
||||
assoc_ty_name: ast::Name)
|
||||
-> Option<specialization_graph::NodeItem<Rc<ty::AssociatedType<'tcx>>>>
|
||||
{
|
||||
let trait_def_id = selcx.tcx().impl_trait_ref(impl_def_id).unwrap().def_id;
|
||||
|
||||
|
@ -57,7 +57,7 @@ pub struct SelectionContext<'cx, 'gcx: 'cx+'tcx, 'tcx: 'cx> {
|
||||
/// at one time will have the same set of skolemized entries,
|
||||
/// which is important for checking for trait bounds that
|
||||
/// recursively require themselves.
|
||||
freshener: TypeFreshener<'cx, 'tcx, 'tcx>,
|
||||
freshener: TypeFreshener<'cx, 'gcx, 'tcx>,
|
||||
|
||||
/// If true, indicates that the evaluation should be conservative
|
||||
/// and consider the possibility of types outside this crate.
|
||||
@ -210,6 +210,38 @@ enum SelectionCandidate<'tcx> {
|
||||
BuiltinUnsizeCandidate,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> ty::Lift<'tcx> for SelectionCandidate<'a> {
|
||||
type Lifted = SelectionCandidate<'tcx>;
|
||||
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
||||
Some(match *self {
|
||||
BuiltinCandidate { has_nested } => {
|
||||
BuiltinCandidate {
|
||||
has_nested: has_nested
|
||||
}
|
||||
}
|
||||
ImplCandidate(def_id) => ImplCandidate(def_id),
|
||||
DefaultImplCandidate(def_id) => DefaultImplCandidate(def_id),
|
||||
DefaultImplObjectCandidate(def_id) => {
|
||||
DefaultImplObjectCandidate(def_id)
|
||||
}
|
||||
ProjectionCandidate => ProjectionCandidate,
|
||||
FnPointerCandidate => FnPointerCandidate,
|
||||
ObjectCandidate => ObjectCandidate,
|
||||
BuiltinObjectCandidate => BuiltinObjectCandidate,
|
||||
BuiltinUnsizeCandidate => BuiltinUnsizeCandidate,
|
||||
|
||||
ParamCandidate(ref trait_ref) => {
|
||||
return tcx.lift(trait_ref).map(ParamCandidate);
|
||||
}
|
||||
ClosureCandidate(def_id, ref substs, kind) => {
|
||||
return tcx.lift(substs).map(|substs| {
|
||||
ClosureCandidate(def_id, substs, kind)
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
struct SelectionCandidateSet<'tcx> {
|
||||
// a list of candidates that definitely apply to the current
|
||||
// obligation (meaning: types unify).
|
||||
@ -262,8 +294,8 @@ pub struct EvaluationCache<'tcx> {
|
||||
hashmap: RefCell<FnvHashMap<ty::PolyTraitRef<'tcx>, EvaluationResult>>
|
||||
}
|
||||
|
||||
impl<'cx, 'tcx> SelectionContext<'cx, 'tcx, 'tcx> {
|
||||
pub fn new(infcx: &'cx InferCtxt<'cx, 'tcx, 'tcx>) -> SelectionContext<'cx, 'tcx, 'tcx> {
|
||||
impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
|
||||
pub fn new(infcx: &'cx InferCtxt<'cx, 'gcx, 'tcx>) -> SelectionContext<'cx, 'gcx, 'tcx> {
|
||||
SelectionContext {
|
||||
infcx: infcx,
|
||||
freshener: infcx.freshener(),
|
||||
@ -271,7 +303,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn intercrate(infcx: &'cx InferCtxt<'cx, 'tcx, 'tcx>) -> SelectionContext<'cx, 'tcx, 'tcx> {
|
||||
pub fn intercrate(infcx: &'cx InferCtxt<'cx, 'gcx, 'tcx>) -> SelectionContext<'cx, 'gcx, 'tcx> {
|
||||
SelectionContext {
|
||||
infcx: infcx,
|
||||
freshener: infcx.freshener(),
|
||||
@ -279,11 +311,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn infcx(&self) -> &'cx InferCtxt<'cx, 'tcx, 'tcx> {
|
||||
pub fn infcx(&self) -> &'cx InferCtxt<'cx, 'gcx, 'tcx> {
|
||||
self.infcx
|
||||
}
|
||||
|
||||
pub fn tcx(&self) -> TyCtxt<'cx, 'tcx, 'tcx> {
|
||||
pub fn tcx(&self) -> TyCtxt<'cx, 'gcx, 'tcx> {
|
||||
self.infcx.tcx
|
||||
}
|
||||
|
||||
@ -291,7 +323,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx, 'tcx> {
|
||||
self.infcx.param_env()
|
||||
}
|
||||
|
||||
pub fn closure_typer(&self) -> &'cx InferCtxt<'cx, 'tcx, 'tcx> {
|
||||
pub fn closure_typer(&self) -> &'cx InferCtxt<'cx, 'gcx, 'tcx> {
|
||||
self.infcx
|
||||
}
|
||||
|
||||
@ -627,23 +659,16 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx, 'tcx> {
|
||||
result
|
||||
}
|
||||
|
||||
fn pick_evaluation_cache(&self) -> &EvaluationCache<'tcx> {
|
||||
// see comment in `pick_candidate_cache`
|
||||
if self.intercrate ||
|
||||
!self.param_env().caller_bounds.is_empty()
|
||||
{
|
||||
&self.param_env().evaluation_cache
|
||||
} else
|
||||
{
|
||||
&self.tcx().evaluation_cache
|
||||
}
|
||||
}
|
||||
|
||||
fn check_evaluation_cache(&self, trait_ref: ty::PolyTraitRef<'tcx>)
|
||||
-> Option<EvaluationResult>
|
||||
{
|
||||
let cache = self.pick_evaluation_cache();
|
||||
cache.hashmap.borrow().get(&trait_ref).cloned()
|
||||
if self.can_use_global_caches() {
|
||||
let cache = self.tcx().evaluation_cache.hashmap.borrow();
|
||||
if let Some(cached) = cache.get(&trait_ref) {
|
||||
return Some(cached.clone());
|
||||
}
|
||||
}
|
||||
self.infcx.evaluation_cache.hashmap.borrow().get(&trait_ref).cloned()
|
||||
}
|
||||
|
||||
fn insert_evaluation_cache(&mut self,
|
||||
@ -661,8 +686,15 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx, 'tcx> {
|
||||
return;
|
||||
}
|
||||
|
||||
let cache = self.pick_evaluation_cache();
|
||||
cache.hashmap.borrow_mut().insert(trait_ref, result);
|
||||
if self.can_use_global_caches() {
|
||||
let mut cache = self.tcx().evaluation_cache.hashmap.borrow_mut();
|
||||
if let Some(trait_ref) = self.tcx().lift_to_global(&trait_ref) {
|
||||
cache.insert(trait_ref, result);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
self.infcx.evaluation_cache.hashmap.borrow_mut().insert(trait_ref, result);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
@ -871,7 +903,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx, 'tcx> {
|
||||
coherence::trait_ref_is_knowable(self.tcx(), trait_ref)
|
||||
}
|
||||
|
||||
fn pick_candidate_cache(&self) -> &SelectionCache<'tcx> {
|
||||
/// Returns true if the global caches can be used.
|
||||
/// Do note that if the type itself is not in the
|
||||
/// global tcx, the local caches will be used.
|
||||
fn can_use_global_caches(&self) -> bool {
|
||||
// If there are any where-clauses in scope, then we always use
|
||||
// a cache local to this particular scope. Otherwise, we
|
||||
// switch to a global cache. We used to try and draw
|
||||
@ -880,7 +915,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx, 'tcx> {
|
||||
// rule seems to be pretty clearly safe and also still retains
|
||||
// a very high hit rate (~95% when compiling rustc).
|
||||
if !self.param_env().caller_bounds.is_empty() {
|
||||
return &self.param_env().selection_cache;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Avoid using the master cache during coherence and just rely
|
||||
@ -891,29 +926,43 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx, 'tcx> {
|
||||
// it's not worth going to more trouble to increase the
|
||||
// hit-rate I don't think.
|
||||
if self.intercrate {
|
||||
return &self.param_env().selection_cache;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Otherwise, we can use the global cache.
|
||||
&self.tcx().selection_cache
|
||||
true
|
||||
}
|
||||
|
||||
fn check_candidate_cache(&mut self,
|
||||
cache_fresh_trait_pred: &ty::PolyTraitPredicate<'tcx>)
|
||||
-> Option<SelectionResult<'tcx, SelectionCandidate<'tcx>>>
|
||||
{
|
||||
let cache = self.pick_candidate_cache();
|
||||
let hashmap = cache.hashmap.borrow();
|
||||
hashmap.get(&cache_fresh_trait_pred.0.trait_ref).cloned()
|
||||
let trait_ref = &cache_fresh_trait_pred.0.trait_ref;
|
||||
if self.can_use_global_caches() {
|
||||
let cache = self.tcx().selection_cache.hashmap.borrow();
|
||||
if let Some(cached) = cache.get(&trait_ref) {
|
||||
return Some(cached.clone());
|
||||
}
|
||||
}
|
||||
self.infcx.selection_cache.hashmap.borrow().get(trait_ref).cloned()
|
||||
}
|
||||
|
||||
fn insert_candidate_cache(&mut self,
|
||||
cache_fresh_trait_pred: ty::PolyTraitPredicate<'tcx>,
|
||||
candidate: SelectionResult<'tcx, SelectionCandidate<'tcx>>)
|
||||
{
|
||||
let cache = self.pick_candidate_cache();
|
||||
let mut hashmap = cache.hashmap.borrow_mut();
|
||||
hashmap.insert(cache_fresh_trait_pred.0.trait_ref.clone(), candidate);
|
||||
let trait_ref = cache_fresh_trait_pred.0.trait_ref;
|
||||
if self.can_use_global_caches() {
|
||||
let mut cache = self.tcx().selection_cache.hashmap.borrow_mut();
|
||||
if let Some(trait_ref) = self.tcx().lift_to_global(&trait_ref) {
|
||||
if let Some(candidate) = self.tcx().lift_to_global(&candidate) {
|
||||
cache.insert(trait_ref, candidate);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.infcx.selection_cache.hashmap.borrow_mut().insert(trait_ref, candidate);
|
||||
}
|
||||
|
||||
fn should_update_candidate_cache(&mut self,
|
||||
@ -1592,7 +1641,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx, 'tcx> {
|
||||
// i.e. EvaluatedToOk:
|
||||
if other.evaluation == EvaluatedToOk {
|
||||
if let ImplCandidate(victim_def) = victim.candidate {
|
||||
return traits::specializes(self.tcx(), other_def, victim_def);
|
||||
let tcx = self.tcx().global_tcx();
|
||||
return traits::specializes(tcx, other_def, victim_def);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -72,11 +72,11 @@ pub struct OverlapError {
|
||||
/// through associated type projection. We deal with such cases by using
|
||||
/// *fulfillment* to relate the two impls, requiring that all projections are
|
||||
/// resolved.
|
||||
pub fn translate_substs<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx, 'tcx>,
|
||||
source_impl: DefId,
|
||||
source_substs: &'tcx Substs<'tcx>,
|
||||
target_node: specialization_graph::Node)
|
||||
-> &'tcx Substs<'tcx> {
|
||||
pub fn translate_substs<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
|
||||
source_impl: DefId,
|
||||
source_substs: &'tcx Substs<'tcx>,
|
||||
target_node: specialization_graph::Node)
|
||||
-> &'tcx Substs<'tcx> {
|
||||
let source_trait_ref = infcx.tcx
|
||||
.impl_trait_ref(source_impl)
|
||||
.unwrap()
|
||||
@ -168,10 +168,10 @@ pub fn specializes<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
/// generics of `target_impl`, including both those needed to unify with
|
||||
/// `source_trait_ref` and those whose identity is determined via a where
|
||||
/// clause in the impl.
|
||||
fn fulfill_implication<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx, 'tcx>,
|
||||
source_trait_ref: ty::TraitRef<'tcx>,
|
||||
target_impl: DefId)
|
||||
-> Result<Substs<'tcx>, ()> {
|
||||
fn fulfill_implication<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
|
||||
source_trait_ref: ty::TraitRef<'tcx>,
|
||||
target_impl: DefId)
|
||||
-> Result<Substs<'tcx>, ()> {
|
||||
infcx.commit_if_ok(|_| {
|
||||
let selcx = &mut SelectionContext::new(&infcx);
|
||||
let target_substs = fresh_type_vars_for_impl(&infcx, DUMMY_SP, target_impl);
|
||||
|
@ -77,7 +77,7 @@ enum Inserted {
|
||||
ShouldRecurseOn(DefId),
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Children {
|
||||
impl<'a, 'gcx, 'tcx> Children {
|
||||
fn new() -> Children {
|
||||
Children {
|
||||
nonblanket_impls: FnvHashMap(),
|
||||
@ -87,7 +87,7 @@ impl<'a, 'tcx> Children {
|
||||
|
||||
/// Insert an impl into this set of children without comparing to any existing impls
|
||||
fn insert_blindly(&mut self,
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
impl_def_id: DefId) {
|
||||
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
|
||||
if let Some(sty) = fast_reject::simplify_type(tcx, trait_ref.self_ty(), false) {
|
||||
@ -100,7 +100,7 @@ impl<'a, 'tcx> Children {
|
||||
/// Attempt to insert an impl into this set of children, while comparing for
|
||||
/// specialiation relationships.
|
||||
fn insert(&mut self,
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
impl_def_id: DefId,
|
||||
simplified_self: Option<SimplifiedType>)
|
||||
-> Result<Inserted, OverlapError>
|
||||
@ -111,6 +111,7 @@ impl<'a, 'tcx> Children {
|
||||
} {
|
||||
let possible_sibling = *slot;
|
||||
|
||||
let tcx = tcx.global_tcx();
|
||||
let (le, ge) = InferCtxt::enter(tcx, None, None,
|
||||
ProjectionMode::Topmost, |infcx| {
|
||||
let overlap = traits::overlapping_impls(&infcx,
|
||||
@ -181,7 +182,7 @@ impl<'a, 'tcx> Children {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Graph {
|
||||
impl<'a, 'gcx, 'tcx> Graph {
|
||||
pub fn new() -> Graph {
|
||||
Graph {
|
||||
parent: Default::default(),
|
||||
@ -193,7 +194,7 @@ impl<'a, 'tcx> Graph {
|
||||
/// conflicts with it (has overlap, but neither specializes the other),
|
||||
/// information about the area of overlap is returned in the `Err`.
|
||||
pub fn insert(&mut self,
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
impl_def_id: DefId)
|
||||
-> Result<(), OverlapError> {
|
||||
assert!(impl_def_id.is_local());
|
||||
@ -252,7 +253,7 @@ impl<'a, 'tcx> Graph {
|
||||
|
||||
/// Insert cached metadata mapping from a child impl back to its parent.
|
||||
pub fn record_impl_from_cstore(&mut self,
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
parent: DefId,
|
||||
child: DefId) {
|
||||
if self.parent.insert(child, parent).is_some() {
|
||||
@ -279,7 +280,7 @@ pub enum Node {
|
||||
Trait(DefId),
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Node {
|
||||
impl<'a, 'gcx, 'tcx> Node {
|
||||
pub fn is_from_trait(&self) -> bool {
|
||||
match *self {
|
||||
Node::Trait(..) => true,
|
||||
@ -288,11 +289,11 @@ impl<'a, 'tcx> Node {
|
||||
}
|
||||
|
||||
/// Iterate over the items defined directly by the given (impl or trait) node.
|
||||
pub fn items(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> NodeItems<'a, 'tcx> {
|
||||
pub fn items(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> NodeItems<'a, 'gcx> {
|
||||
match *self {
|
||||
Node::Impl(impl_def_id) => {
|
||||
NodeItems::Impl {
|
||||
tcx: tcx,
|
||||
tcx: tcx.global_tcx(),
|
||||
items: cell::Ref::map(tcx.impl_items.borrow(),
|
||||
|impl_items| &impl_items[&impl_def_id]),
|
||||
idx: 0,
|
||||
@ -427,10 +428,10 @@ impl<'a, 'tcx> Iterator for ConstDefs<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Ancestors<'a, 'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> Ancestors<'a, 'tcx> {
|
||||
/// Search the items from the given ancestors, returning each type definition
|
||||
/// with the given name.
|
||||
pub fn type_defs(self, tcx: TyCtxt<'a, 'tcx, 'tcx>, name: Name) -> TypeDefs<'a, 'tcx> {
|
||||
pub fn type_defs(self, tcx: TyCtxt<'a, 'gcx, 'tcx>, name: Name) -> TypeDefs<'a, 'gcx> {
|
||||
let iter = self.flat_map(move |node| {
|
||||
node.items(tcx)
|
||||
.filter_map(move |item| {
|
||||
@ -451,7 +452,7 @@ impl<'a, 'tcx> Ancestors<'a, 'tcx> {
|
||||
|
||||
/// Search the items from the given ancestors, returning each fn definition
|
||||
/// with the given name.
|
||||
pub fn fn_defs(self, tcx: TyCtxt<'a, 'tcx, 'tcx>, name: Name) -> FnDefs<'a, 'tcx> {
|
||||
pub fn fn_defs(self, tcx: TyCtxt<'a, 'gcx, 'tcx>, name: Name) -> FnDefs<'a, 'gcx> {
|
||||
let iter = self.flat_map(move |node| {
|
||||
node.items(tcx)
|
||||
.filter_map(move |item| {
|
||||
@ -472,7 +473,7 @@ impl<'a, 'tcx> Ancestors<'a, 'tcx> {
|
||||
|
||||
/// Search the items from the given ancestors, returning each const
|
||||
/// definition with the given name.
|
||||
pub fn const_defs(self, tcx: TyCtxt<'a, 'tcx, 'tcx>, name: Name) -> ConstDefs<'a, 'tcx> {
|
||||
pub fn const_defs(self, tcx: TyCtxt<'a, 'gcx, 'tcx>, name: Name) -> ConstDefs<'a, 'gcx> {
|
||||
let iter = self.flat_map(move |node| {
|
||||
node.items(tcx)
|
||||
.filter_map(move |item| {
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
use traits;
|
||||
use traits::project::Normalized;
|
||||
use ty::{Lift, TyCtxt};
|
||||
use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
|
||||
|
||||
use std::fmt;
|
||||
@ -130,9 +131,34 @@ impl<'tcx> fmt::Debug for traits::MismatchedProjectionTypes<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Lift implementations
|
||||
|
||||
impl<'a, 'tcx> Lift<'tcx> for traits::SelectionError<'a> {
|
||||
type Lifted = traits::SelectionError<'tcx>;
|
||||
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
||||
match *self {
|
||||
super::Unimplemented => Some(super::Unimplemented),
|
||||
super::OutputTypeParameterMismatch(a, b, ref err) => {
|
||||
tcx.lift(&(a, b)).and_then(|(a, b)| {
|
||||
tcx.lift(err).map(|err| {
|
||||
super::OutputTypeParameterMismatch(a, b, err)
|
||||
})
|
||||
})
|
||||
}
|
||||
super::TraitNotObjectSafe(def_id) => {
|
||||
Some(super::TraitNotObjectSafe(def_id))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// TypeFoldable implementations.
|
||||
|
||||
impl<'tcx, O: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::Obligation<'tcx, O>
|
||||
{
|
||||
fn super_fold_with<F:TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
traits::Obligation {
|
||||
cause: self.cause.clone(),
|
||||
recursion_depth: self.recursion_depth,
|
||||
@ -146,7 +172,7 @@ impl<'tcx, O: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::Obligation<'tcx
|
||||
}
|
||||
|
||||
impl<'tcx, N: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::VtableImplData<'tcx, N> {
|
||||
fn super_fold_with<F:TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
let substs = self.substs.fold_with(folder);
|
||||
traits::VtableImplData {
|
||||
impl_def_id: self.impl_def_id,
|
||||
@ -161,7 +187,7 @@ impl<'tcx, N: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::VtableImplData<
|
||||
}
|
||||
|
||||
impl<'tcx, N: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::VtableClosureData<'tcx, N> {
|
||||
fn super_fold_with<F:TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
traits::VtableClosureData {
|
||||
closure_def_id: self.closure_def_id,
|
||||
substs: self.substs.fold_with(folder),
|
||||
@ -175,7 +201,7 @@ impl<'tcx, N: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::VtableClosureDa
|
||||
}
|
||||
|
||||
impl<'tcx, N: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::VtableDefaultImplData<N> {
|
||||
fn super_fold_with<F:TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
traits::VtableDefaultImplData {
|
||||
trait_def_id: self.trait_def_id,
|
||||
nested: self.nested.fold_with(folder),
|
||||
@ -188,7 +214,7 @@ impl<'tcx, N: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::VtableDefaultIm
|
||||
}
|
||||
|
||||
impl<'tcx, N: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::VtableBuiltinData<N> {
|
||||
fn super_fold_with<F:TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
traits::VtableBuiltinData {
|
||||
nested: self.nested.fold_with(folder),
|
||||
}
|
||||
@ -200,7 +226,7 @@ impl<'tcx, N: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::VtableBuiltinDa
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for traits::VtableObjectData<'tcx> {
|
||||
fn super_fold_with<F:TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
traits::VtableObjectData {
|
||||
upcast_trait_ref: self.upcast_trait_ref.fold_with(folder),
|
||||
vtable_base: self.vtable_base
|
||||
@ -213,7 +239,7 @@ impl<'tcx> TypeFoldable<'tcx> for traits::VtableObjectData<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx, N: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::Vtable<'tcx, N> {
|
||||
fn super_fold_with<F:TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
match *self {
|
||||
traits::VtableImpl(ref v) => traits::VtableImpl(v.fold_with(folder)),
|
||||
traits::VtableDefaultImpl(ref t) => traits::VtableDefaultImpl(t.fold_with(folder)),
|
||||
@ -243,7 +269,7 @@ impl<'tcx, N: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::Vtable<'tcx, N>
|
||||
}
|
||||
|
||||
impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Normalized<'tcx, T> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
Normalized {
|
||||
value: self.value.fold_with(folder),
|
||||
obligations: self.obligations.fold_with(folder),
|
||||
|
@ -18,8 +18,9 @@ use util::nodemap::FnvHashSet;
|
||||
|
||||
use super::{Obligation, ObligationCause, PredicateObligation, SelectionContext, Normalized};
|
||||
|
||||
fn anonymize_predicate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, pred: &ty::Predicate<'tcx>)
|
||||
-> ty::Predicate<'tcx> {
|
||||
fn anonymize_predicate<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
pred: &ty::Predicate<'tcx>)
|
||||
-> ty::Predicate<'tcx> {
|
||||
match *pred {
|
||||
ty::Predicate::Trait(ref data) =>
|
||||
ty::Predicate::Trait(tcx.anonymize_late_bound_regions(data)),
|
||||
@ -51,13 +52,13 @@ fn anonymize_predicate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, pred: &ty::Predica
|
||||
}
|
||||
|
||||
|
||||
struct PredicateSet<'a,'tcx:'a> {
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
struct PredicateSet<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
|
||||
tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
set: FnvHashSet<ty::Predicate<'tcx>>,
|
||||
}
|
||||
|
||||
impl<'a,'tcx> PredicateSet<'a,'tcx> {
|
||||
fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> PredicateSet<'a,'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> PredicateSet<'a, 'gcx, 'tcx> {
|
||||
fn new(tcx: TyCtxt<'a, 'gcx, 'tcx>) -> PredicateSet<'a, 'gcx, 'tcx> {
|
||||
PredicateSet { tcx: tcx, set: FnvHashSet() }
|
||||
}
|
||||
|
||||
@ -87,24 +88,23 @@ impl<'a,'tcx> PredicateSet<'a,'tcx> {
|
||||
/// that `T : PartialOrd` holds as well. Similarly, if we have `trait
|
||||
/// Foo : 'static`, and we know that `T : Foo`, then we know that `T :
|
||||
/// 'static`.
|
||||
pub struct Elaborator<'cx, 'tcx:'cx> {
|
||||
tcx: TyCtxt<'cx, 'tcx, 'tcx>,
|
||||
pub struct Elaborator<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
|
||||
stack: Vec<ty::Predicate<'tcx>>,
|
||||
visited: PredicateSet<'cx,'tcx>,
|
||||
visited: PredicateSet<'a, 'gcx, 'tcx>,
|
||||
}
|
||||
|
||||
pub fn elaborate_trait_ref<'cx, 'tcx>(
|
||||
tcx: TyCtxt<'cx, 'tcx, 'tcx>,
|
||||
pub fn elaborate_trait_ref<'cx, 'gcx, 'tcx>(
|
||||
tcx: TyCtxt<'cx, 'gcx, 'tcx>,
|
||||
trait_ref: ty::PolyTraitRef<'tcx>)
|
||||
-> Elaborator<'cx, 'tcx>
|
||||
-> Elaborator<'cx, 'gcx, 'tcx>
|
||||
{
|
||||
elaborate_predicates(tcx, vec![trait_ref.to_predicate()])
|
||||
}
|
||||
|
||||
pub fn elaborate_trait_refs<'cx, 'tcx>(
|
||||
tcx: TyCtxt<'cx, 'tcx, 'tcx>,
|
||||
pub fn elaborate_trait_refs<'cx, 'gcx, 'tcx>(
|
||||
tcx: TyCtxt<'cx, 'gcx, 'tcx>,
|
||||
trait_refs: &[ty::PolyTraitRef<'tcx>])
|
||||
-> Elaborator<'cx, 'tcx>
|
||||
-> Elaborator<'cx, 'gcx, 'tcx>
|
||||
{
|
||||
let predicates = trait_refs.iter()
|
||||
.map(|trait_ref| trait_ref.to_predicate())
|
||||
@ -112,31 +112,32 @@ pub fn elaborate_trait_refs<'cx, 'tcx>(
|
||||
elaborate_predicates(tcx, predicates)
|
||||
}
|
||||
|
||||
pub fn elaborate_predicates<'cx, 'tcx>(
|
||||
tcx: TyCtxt<'cx, 'tcx, 'tcx>,
|
||||
pub fn elaborate_predicates<'cx, 'gcx, 'tcx>(
|
||||
tcx: TyCtxt<'cx, 'gcx, 'tcx>,
|
||||
mut predicates: Vec<ty::Predicate<'tcx>>)
|
||||
-> Elaborator<'cx, 'tcx>
|
||||
-> Elaborator<'cx, 'gcx, 'tcx>
|
||||
{
|
||||
let mut visited = PredicateSet::new(tcx);
|
||||
predicates.retain(|pred| visited.insert(pred));
|
||||
Elaborator { tcx: tcx, stack: predicates, visited: visited }
|
||||
Elaborator { stack: predicates, visited: visited }
|
||||
}
|
||||
|
||||
impl<'cx, 'tcx> Elaborator<'cx, 'tcx> {
|
||||
pub fn filter_to_traits(self) -> FilterToTraits<Elaborator<'cx, 'tcx>> {
|
||||
impl<'cx, 'gcx, 'tcx> Elaborator<'cx, 'gcx, 'tcx> {
|
||||
pub fn filter_to_traits(self) -> FilterToTraits<Self> {
|
||||
FilterToTraits::new(self)
|
||||
}
|
||||
|
||||
fn push(&mut self, predicate: &ty::Predicate<'tcx>) {
|
||||
let tcx = self.visited.tcx;
|
||||
match *predicate {
|
||||
ty::Predicate::Trait(ref data) => {
|
||||
// Predicates declared on the trait.
|
||||
let predicates = self.tcx.lookup_super_predicates(data.def_id());
|
||||
let predicates = tcx.lookup_super_predicates(data.def_id());
|
||||
|
||||
let mut predicates: Vec<_> =
|
||||
predicates.predicates
|
||||
.iter()
|
||||
.map(|p| p.subst_supertrait(self.tcx, &data.to_poly_trait_ref()))
|
||||
.map(|p| p.subst_supertrait(tcx, &data.to_poly_trait_ref()))
|
||||
.collect();
|
||||
|
||||
debug!("super_predicates: data={:?} predicates={:?}",
|
||||
@ -199,7 +200,7 @@ impl<'cx, 'tcx> Elaborator<'cx, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'cx, 'tcx> Iterator for Elaborator<'cx, 'tcx> {
|
||||
impl<'cx, 'gcx, 'tcx> Iterator for Elaborator<'cx, 'gcx, 'tcx> {
|
||||
type Item = ty::Predicate<'tcx>;
|
||||
|
||||
fn next(&mut self) -> Option<ty::Predicate<'tcx>> {
|
||||
@ -220,18 +221,18 @@ impl<'cx, 'tcx> Iterator for Elaborator<'cx, 'tcx> {
|
||||
// Supertrait iterator
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
pub type Supertraits<'cx, 'tcx> = FilterToTraits<Elaborator<'cx, 'tcx>>;
|
||||
pub type Supertraits<'cx, 'gcx, 'tcx> = FilterToTraits<Elaborator<'cx, 'gcx, 'tcx>>;
|
||||
|
||||
pub fn supertraits<'cx, 'tcx>(tcx: TyCtxt<'cx, 'tcx, 'tcx>,
|
||||
trait_ref: ty::PolyTraitRef<'tcx>)
|
||||
-> Supertraits<'cx, 'tcx>
|
||||
pub fn supertraits<'cx, 'gcx, 'tcx>(tcx: TyCtxt<'cx, 'gcx, 'tcx>,
|
||||
trait_ref: ty::PolyTraitRef<'tcx>)
|
||||
-> Supertraits<'cx, 'gcx, 'tcx>
|
||||
{
|
||||
elaborate_trait_ref(tcx, trait_ref).filter_to_traits()
|
||||
}
|
||||
|
||||
pub fn transitive_bounds<'cx, 'tcx>(tcx: TyCtxt<'cx, 'tcx, 'tcx>,
|
||||
bounds: &[ty::PolyTraitRef<'tcx>])
|
||||
-> Supertraits<'cx, 'tcx>
|
||||
pub fn transitive_bounds<'cx, 'gcx, 'tcx>(tcx: TyCtxt<'cx, 'gcx, 'tcx>,
|
||||
bounds: &[ty::PolyTraitRef<'tcx>])
|
||||
-> Supertraits<'cx, 'gcx, 'tcx>
|
||||
{
|
||||
elaborate_trait_refs(tcx, bounds).filter_to_traits()
|
||||
}
|
||||
@ -239,15 +240,15 @@ pub fn transitive_bounds<'cx, 'tcx>(tcx: TyCtxt<'cx, 'tcx, 'tcx>,
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Iterator over def-ids of supertraits
|
||||
|
||||
pub struct SupertraitDefIds<'cx, 'tcx:'cx> {
|
||||
tcx: TyCtxt<'cx, 'tcx, 'tcx>,
|
||||
pub struct SupertraitDefIds<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
|
||||
tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
stack: Vec<DefId>,
|
||||
visited: FnvHashSet<DefId>,
|
||||
}
|
||||
|
||||
pub fn supertrait_def_ids<'cx, 'tcx>(tcx: TyCtxt<'cx, 'tcx, 'tcx>,
|
||||
trait_def_id: DefId)
|
||||
-> SupertraitDefIds<'cx, 'tcx>
|
||||
pub fn supertrait_def_ids<'cx, 'gcx, 'tcx>(tcx: TyCtxt<'cx, 'gcx, 'tcx>,
|
||||
trait_def_id: DefId)
|
||||
-> SupertraitDefIds<'cx, 'gcx, 'tcx>
|
||||
{
|
||||
SupertraitDefIds {
|
||||
tcx: tcx,
|
||||
@ -256,7 +257,7 @@ pub fn supertrait_def_ids<'cx, 'tcx>(tcx: TyCtxt<'cx, 'tcx, 'tcx>,
|
||||
}
|
||||
}
|
||||
|
||||
impl<'cx, 'tcx> Iterator for SupertraitDefIds<'cx, 'tcx> {
|
||||
impl<'cx, 'gcx, 'tcx> Iterator for SupertraitDefIds<'cx, 'gcx, 'tcx> {
|
||||
type Item = DefId;
|
||||
|
||||
fn next(&mut self) -> Option<DefId> {
|
||||
@ -319,11 +320,11 @@ impl<'tcx,I:Iterator<Item=ty::Predicate<'tcx>>> Iterator for FilterToTraits<I> {
|
||||
/// Instantiate all bound parameters of the impl with the given substs,
|
||||
/// returning the resulting trait ref and all obligations that arise.
|
||||
/// The obligations are closed under normalization.
|
||||
pub fn impl_trait_ref_and_oblig<'a,'tcx>(selcx: &mut SelectionContext<'a,'tcx, 'tcx>,
|
||||
impl_def_id: DefId,
|
||||
impl_substs: &Substs<'tcx>)
|
||||
-> (ty::TraitRef<'tcx>,
|
||||
Vec<PredicateObligation<'tcx>>)
|
||||
pub fn impl_trait_ref_and_oblig<'a, 'gcx, 'tcx>(selcx: &mut SelectionContext<'a, 'gcx, 'tcx>,
|
||||
impl_def_id: DefId,
|
||||
impl_substs: &Substs<'tcx>)
|
||||
-> (ty::TraitRef<'tcx>,
|
||||
Vec<PredicateObligation<'tcx>>)
|
||||
{
|
||||
let impl_trait_ref =
|
||||
selcx.tcx().impl_trait_ref(impl_def_id).unwrap();
|
||||
@ -352,10 +353,10 @@ pub fn impl_trait_ref_and_oblig<'a,'tcx>(selcx: &mut SelectionContext<'a,'tcx, '
|
||||
// declared on the impl declaration e.g., `impl<A,B> for Box<[(A,B)]>`
|
||||
// would return ($0, $1) where $0 and $1 are freshly instantiated type
|
||||
// variables.
|
||||
pub fn fresh_type_vars_for_impl<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx, 'tcx>,
|
||||
span: Span,
|
||||
impl_def_id: DefId)
|
||||
-> Substs<'tcx>
|
||||
pub fn fresh_type_vars_for_impl<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
|
||||
span: Span,
|
||||
impl_def_id: DefId)
|
||||
-> Substs<'tcx>
|
||||
{
|
||||
let tcx = infcx.tcx;
|
||||
let impl_generics = tcx.lookup_item_type(impl_def_id).generics;
|
||||
@ -391,7 +392,7 @@ pub fn predicate_for_trait_ref<'tcx>(
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
pub fn trait_ref_for_builtin_bound(self,
|
||||
builtin_bound: ty::BuiltinBound,
|
||||
param_ty: Ty<'tcx>)
|
||||
|
@ -28,26 +28,26 @@ use ty::relate::{self, Relate, TypeRelation, RelateResult};
|
||||
/// Like subtyping, matching is really a binary relation, so the only
|
||||
/// important thing about the result is Ok/Err. Also, matching never
|
||||
/// affects any type variables or unification state.
|
||||
pub struct Match<'a, 'tcx: 'a> {
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>
|
||||
pub struct Match<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
|
||||
tcx: TyCtxt<'a, 'gcx, 'tcx>
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Match<'a, 'tcx> {
|
||||
pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Match<'a, 'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> Match<'a, 'gcx, 'tcx> {
|
||||
pub fn new(tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Match<'a, 'gcx, 'tcx> {
|
||||
Match { tcx: tcx }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> TypeRelation<'a, 'tcx> for Match<'a, 'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> TypeRelation<'a, 'gcx, 'tcx> for Match<'a, 'gcx, 'tcx> {
|
||||
fn tag(&self) -> &'static str { "Match" }
|
||||
fn tcx(&self) -> TyCtxt<'a, 'tcx, 'tcx> { self.tcx }
|
||||
fn tcx(&self) -> TyCtxt<'a, 'gcx, 'tcx> { self.tcx }
|
||||
fn a_is_expected(&self) -> bool { true } // irrelevant
|
||||
|
||||
fn relate_with_variance<T:Relate<'a,'tcx>>(&mut self,
|
||||
_: ty::Variance,
|
||||
a: &T,
|
||||
b: &T)
|
||||
-> RelateResult<'tcx, T>
|
||||
fn relate_with_variance<T: Relate<'tcx>>(&mut self,
|
||||
_: ty::Variance,
|
||||
a: &T,
|
||||
b: &T)
|
||||
-> RelateResult<'tcx, T>
|
||||
{
|
||||
self.relate(a, b)
|
||||
}
|
||||
@ -89,7 +89,7 @@ impl<'a, 'tcx> TypeRelation<'a, 'tcx> for Match<'a, 'tcx> {
|
||||
|
||||
fn binders<T>(&mut self, a: &ty::Binder<T>, b: &ty::Binder<T>)
|
||||
-> RelateResult<'tcx, ty::Binder<T>>
|
||||
where T: Relate<'a,'tcx>
|
||||
where T: Relate<'tcx>
|
||||
{
|
||||
Ok(ty::Binder(self.relate(a.skip_binder(), b.skip_binder())?))
|
||||
}
|
||||
|
@ -136,10 +136,10 @@ pub enum CustomCoerceUnsized {
|
||||
Struct(usize)
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> ty::TyS<'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> ty::TyS<'tcx> {
|
||||
/// See `expr_ty_adjusted`
|
||||
pub fn adjust<F>(&'tcx self,
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
span: Span,
|
||||
expr_id: ast::NodeId,
|
||||
adjustment: Option<&AutoAdjustment<'tcx>>,
|
||||
@ -216,7 +216,7 @@ impl<'a, 'tcx> ty::TyS<'tcx> {
|
||||
}
|
||||
|
||||
pub fn adjust_for_autoderef<F>(&'tcx self,
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
expr_id: ast::NodeId,
|
||||
expr_span: Span,
|
||||
autoderef: u32, // how many autoderefs so far?
|
||||
@ -244,7 +244,7 @@ impl<'a, 'tcx> ty::TyS<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn adjust_for_autoref(&'tcx self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
pub fn adjust_for_autoref(&'tcx self, tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
autoref: Option<AutoRef<'tcx>>)
|
||||
-> Ty<'tcx> {
|
||||
match autoref {
|
||||
|
@ -194,7 +194,7 @@ pub struct Tables<'tcx> {
|
||||
pub fru_field_types: NodeMap<Vec<Ty<'tcx>>>
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Tables<'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> Tables<'tcx> {
|
||||
pub fn empty() -> Tables<'tcx> {
|
||||
Tables {
|
||||
node_types: FnvHashMap(),
|
||||
@ -210,7 +210,7 @@ impl<'a, 'tcx> Tables<'tcx> {
|
||||
}
|
||||
|
||||
pub fn closure_kind(this: &RefCell<Self>,
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
def_id: DefId)
|
||||
-> ty::ClosureKind {
|
||||
// If this is a local def-id, it should be inserted into the
|
||||
@ -226,7 +226,7 @@ impl<'a, 'tcx> Tables<'tcx> {
|
||||
}
|
||||
|
||||
pub fn closure_type(this: &RefCell<Self>,
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
def_id: DefId,
|
||||
substs: &ClosureSubsts<'tcx>)
|
||||
-> ty::ClosureTy<'tcx>
|
||||
@ -238,7 +238,7 @@ impl<'a, 'tcx> Tables<'tcx> {
|
||||
return ty.subst(tcx, &substs.func_substs);
|
||||
}
|
||||
|
||||
let ty = tcx.sess.cstore.closure_ty(tcx, def_id);
|
||||
let ty = tcx.sess.cstore.closure_ty(tcx.global_tcx(), def_id);
|
||||
this.borrow_mut().closure_tys.insert(def_id, ty.clone());
|
||||
ty.subst(tcx, &substs.func_substs)
|
||||
}
|
||||
@ -494,7 +494,7 @@ impl<'tcx> GlobalCtxt<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
pub fn crate_name(self, cnum: ast::CrateNum) -> token::InternedString {
|
||||
if cnum == LOCAL_CRATE {
|
||||
self.crate_name.clone()
|
||||
@ -526,12 +526,12 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
Ref::map(self.tables.borrow(), projection)
|
||||
}
|
||||
|
||||
pub fn node_type_insert(self, id: NodeId, ty: Ty<'tcx>) {
|
||||
pub fn node_type_insert(self, id: NodeId, ty: Ty<'gcx>) {
|
||||
self.tables.borrow_mut().node_types.insert(id, ty);
|
||||
}
|
||||
|
||||
pub fn intern_trait_def(self, def: ty::TraitDef<'tcx>)
|
||||
-> &'tcx ty::TraitDef<'tcx> {
|
||||
pub fn intern_trait_def(self, def: ty::TraitDef<'gcx>)
|
||||
-> &'gcx ty::TraitDef<'gcx> {
|
||||
let did = def.trait_ref.def_id;
|
||||
let interned = self.global_interners.arenas.trait_defs.alloc(def);
|
||||
if let Some(prev) = self.trait_defs.borrow_mut().insert(did, interned) {
|
||||
@ -540,16 +540,16 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
interned
|
||||
}
|
||||
|
||||
pub fn alloc_trait_def(self, def: ty::TraitDef<'tcx>)
|
||||
-> &'tcx ty::TraitDef<'tcx> {
|
||||
pub fn alloc_trait_def(self, def: ty::TraitDef<'gcx>)
|
||||
-> &'gcx ty::TraitDef<'gcx> {
|
||||
self.global_interners.arenas.trait_defs.alloc(def)
|
||||
}
|
||||
|
||||
pub fn intern_adt_def(self,
|
||||
did: DefId,
|
||||
kind: ty::AdtKind,
|
||||
variants: Vec<ty::VariantDefData<'tcx, 'tcx>>)
|
||||
-> ty::AdtDefMaster<'tcx> {
|
||||
variants: Vec<ty::VariantDefData<'gcx, 'gcx>>)
|
||||
-> ty::AdtDefMaster<'gcx> {
|
||||
let def = ty::AdtDefData::new(self, did, kind, variants);
|
||||
let interned = self.global_interners.arenas.adt_defs.alloc(def);
|
||||
// this will need a transmute when reverse-variance is removed
|
||||
@ -601,6 +601,18 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
value.lift_to_tcx(self)
|
||||
}
|
||||
|
||||
/// Like lift, but only tries in the global tcx.
|
||||
pub fn lift_to_global<T: ?Sized + Lift<'gcx>>(self, value: &T) -> Option<T::Lifted> {
|
||||
value.lift_to_tcx(self.global_tcx())
|
||||
}
|
||||
|
||||
/// Returns true if self is the same as self.global_tcx().
|
||||
fn is_global(self) -> bool {
|
||||
let local = self.interners as *const _;
|
||||
let global = &self.global_interners as *const _;
|
||||
local as usize == global as usize
|
||||
}
|
||||
|
||||
/// Create a type context and call the closure with a `TyCtxt` reference
|
||||
/// to the context. The closure enforces that the type context and any interned
|
||||
/// value (types, substs, etc.) can only be used while `ty::tls` has a valid
|
||||
@ -693,30 +705,40 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
/// e.g. `()` or `u8`, was interned in a different context.
|
||||
pub trait Lift<'tcx> {
|
||||
type Lifted;
|
||||
fn lift_to_tcx<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Option<Self::Lifted>;
|
||||
fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted>;
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Lift<'tcx> for Ty<'a> {
|
||||
type Lifted = Ty<'tcx>;
|
||||
fn lift_to_tcx<'b>(&self, tcx: TyCtxt<'b, 'tcx, 'tcx>) -> Option<Ty<'tcx>> {
|
||||
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Ty<'tcx>> {
|
||||
if let Some(&InternedTy { ty }) = tcx.interners.type_.borrow().get(&self.sty) {
|
||||
if *self as *const _ == ty as *const _ {
|
||||
return Some(ty);
|
||||
}
|
||||
}
|
||||
None
|
||||
// Also try in the global tcx if we're not that.
|
||||
if !tcx.is_global() {
|
||||
self.lift_to_tcx(tcx.global_tcx())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Lift<'tcx> for &'a Substs<'a> {
|
||||
type Lifted = &'tcx Substs<'tcx>;
|
||||
fn lift_to_tcx<'b>(&self, tcx: TyCtxt<'b, 'tcx, 'tcx>) -> Option<&'tcx Substs<'tcx>> {
|
||||
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<&'tcx Substs<'tcx>> {
|
||||
if let Some(&InternedSubsts { substs }) = tcx.interners.substs.borrow().get(*self) {
|
||||
if *self as *const _ == substs as *const _ {
|
||||
return Some(substs);
|
||||
}
|
||||
}
|
||||
None
|
||||
// Also try in the global tcx if we're not that.
|
||||
if !tcx.is_global() {
|
||||
self.lift_to_tcx(tcx.global_tcx())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -910,7 +932,7 @@ fn bound_list_is_sorted(bounds: &[ty::PolyProjectionPredicate]) -> bool {
|
||||
|(index, bound)| bounds[index].sort_key() <= bound.sort_key())
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
// Type constructors
|
||||
pub fn mk_substs(self, substs: Substs<'tcx>) -> &'tcx Substs<'tcx> {
|
||||
if let Some(interned) = self.interners.substs.borrow().get(&substs) {
|
||||
@ -1139,7 +1161,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
self.mk_param(def.space, def.index, def.name)
|
||||
}
|
||||
|
||||
pub fn trait_items(self, trait_did: DefId) -> Rc<Vec<ty::ImplOrTraitItem<'tcx>>> {
|
||||
pub fn trait_items(self, trait_did: DefId) -> Rc<Vec<ty::ImplOrTraitItem<'gcx>>> {
|
||||
self.trait_items_cache.memoize(trait_did, || {
|
||||
let def_ids = self.trait_item_def_ids(trait_did);
|
||||
Rc::new(def_ids.iter()
|
||||
|
@ -210,8 +210,8 @@ impl<'tcx> fmt::Display for TypeError<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx, 'lcx> ty::TyS<'tcx> {
|
||||
fn sort_string(&self, tcx: TyCtxt<'a, 'lcx, 'lcx>) -> String {
|
||||
impl<'a, 'gcx, 'lcx, 'tcx> ty::TyS<'tcx> {
|
||||
fn sort_string(&self, tcx: TyCtxt<'a, 'gcx, 'lcx>) -> String {
|
||||
match self.sty {
|
||||
ty::TyBool | ty::TyChar | ty::TyInt(_) |
|
||||
ty::TyUint(_) | ty::TyFloat(_) | ty::TyStr => self.to_string(),
|
||||
@ -252,7 +252,7 @@ impl<'a, 'tcx, 'lcx> ty::TyS<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
pub fn note_and_explain_type_err(self,
|
||||
db: &mut DiagnosticBuilder,
|
||||
err: &TypeError<'tcx>,
|
||||
|
@ -43,10 +43,10 @@ pub enum SimplifiedType {
|
||||
/// then we can't say much about whether two types would unify. Put another way,
|
||||
/// `can_simplify_params` should be true if type parameters appear free in `ty` and `false` if they
|
||||
/// are to be considered bound.
|
||||
pub fn simplify_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
ty: Ty,
|
||||
can_simplify_params: bool)
|
||||
-> Option<SimplifiedType>
|
||||
pub fn simplify_type<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
ty: Ty,
|
||||
can_simplify_params: bool)
|
||||
-> Option<SimplifiedType>
|
||||
{
|
||||
match ty.sty {
|
||||
ty::TyBool => Some(BoolSimplifiedType),
|
||||
|
@ -50,8 +50,8 @@ use util::nodemap::{FnvHashMap, FnvHashSet};
|
||||
/// The TypeFoldable trait is implemented for every type that can be folded.
|
||||
/// Basically, every type that has a corresponding method in TypeFolder.
|
||||
pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self;
|
||||
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self;
|
||||
fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
self.super_fold_with(folder)
|
||||
}
|
||||
|
||||
@ -113,8 +113,8 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
|
||||
/// default implementation that does an "identity" fold. Within each
|
||||
/// identity fold, it should invoke `foo.fold_with(self)` to fold each
|
||||
/// sub-item.
|
||||
pub trait TypeFolder<'tcx> : Sized {
|
||||
fn tcx<'a>(&'a self) -> TyCtxt<'a, 'tcx, 'tcx>;
|
||||
pub trait TypeFolder<'gcx: 'tcx, 'tcx> : Sized {
|
||||
fn tcx<'a>(&'a self) -> TyCtxt<'a, 'gcx, 'tcx>;
|
||||
|
||||
fn fold_binder<T>(&mut self, t: &Binder<T>) -> Binder<T>
|
||||
where T : TypeFoldable<'tcx>
|
||||
@ -201,15 +201,17 @@ pub trait TypeVisitor<'tcx> : Sized {
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Some sample folders
|
||||
|
||||
pub struct BottomUpFolder<'a, 'tcx: 'a, F> where F: FnMut(Ty<'tcx>) -> Ty<'tcx> {
|
||||
pub tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
pub struct BottomUpFolder<'a, 'gcx: 'a+'tcx, 'tcx: 'a, F>
|
||||
where F: FnMut(Ty<'tcx>) -> Ty<'tcx>
|
||||
{
|
||||
pub tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
pub fldop: F,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx, F> TypeFolder<'tcx> for BottomUpFolder<'a, 'tcx, F> where
|
||||
F: FnMut(Ty<'tcx>) -> Ty<'tcx>,
|
||||
impl<'a, 'gcx, 'tcx, F> TypeFolder<'gcx, 'tcx> for BottomUpFolder<'a, 'gcx, 'tcx, F>
|
||||
where F: FnMut(Ty<'tcx>) -> Ty<'tcx>,
|
||||
{
|
||||
fn tcx<'b>(&'b self) -> TyCtxt<'b, 'tcx, 'tcx> { self.tcx }
|
||||
fn tcx<'b>(&'b self) -> TyCtxt<'b, 'gcx, 'tcx> { self.tcx }
|
||||
|
||||
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
|
||||
let t1 = ty.super_fold_with(self);
|
||||
@ -220,7 +222,7 @@ impl<'a, 'tcx, F> TypeFolder<'tcx> for BottomUpFolder<'a, 'tcx, F> where
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Region folder
|
||||
|
||||
impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
/// Collects the free and escaping regions in `value` into `region_set`. Returns
|
||||
/// whether any late-bound regions were skipped
|
||||
pub fn collect_regions<T>(self,
|
||||
@ -259,17 +261,17 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
/// visited by this folder; only regions that occur free will be
|
||||
/// visited by `fld_r`.
|
||||
|
||||
pub struct RegionFolder<'a, 'tcx: 'a> {
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
pub struct RegionFolder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
|
||||
tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
skipped_regions: &'a mut bool,
|
||||
current_depth: u32,
|
||||
fld_r: &'a mut (FnMut(ty::Region, u32) -> ty::Region + 'a),
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> RegionFolder<'a, 'tcx> {
|
||||
pub fn new<F>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
impl<'a, 'gcx, 'tcx> RegionFolder<'a, 'gcx, 'tcx> {
|
||||
pub fn new<F>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
skipped_regions: &'a mut bool,
|
||||
fld_r: &'a mut F) -> RegionFolder<'a, 'tcx>
|
||||
fld_r: &'a mut F) -> RegionFolder<'a, 'gcx, 'tcx>
|
||||
where F : FnMut(ty::Region, u32) -> ty::Region
|
||||
{
|
||||
RegionFolder {
|
||||
@ -281,9 +283,8 @@ impl<'a, 'tcx> RegionFolder<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> TypeFolder<'tcx> for RegionFolder<'a, 'tcx>
|
||||
{
|
||||
fn tcx<'b>(&'b self) -> TyCtxt<'b, 'tcx, 'tcx> { self.tcx }
|
||||
impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for RegionFolder<'a, 'gcx, 'tcx> {
|
||||
fn tcx<'b>(&'b self) -> TyCtxt<'b, 'gcx, 'tcx> { self.tcx }
|
||||
|
||||
fn fold_binder<T: TypeFoldable<'tcx>>(&mut self, t: &ty::Binder<T>) -> ty::Binder<T> {
|
||||
self.current_depth += 1;
|
||||
@ -314,14 +315,14 @@ impl<'a, 'tcx> TypeFolder<'tcx> for RegionFolder<'a, 'tcx>
|
||||
|
||||
// Replaces the escaping regions in a type.
|
||||
|
||||
struct RegionReplacer<'a, 'tcx: 'a> {
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
struct RegionReplacer<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
|
||||
tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
current_depth: u32,
|
||||
fld_r: &'a mut (FnMut(ty::BoundRegion) -> ty::Region + 'a),
|
||||
map: FnvHashMap<ty::BoundRegion, ty::Region>
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
pub fn replace_late_bound_regions<T,F>(self,
|
||||
value: &Binder<T>,
|
||||
mut f: F)
|
||||
@ -408,8 +409,9 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> RegionReplacer<'a, 'tcx> {
|
||||
fn new<F>(tcx: TyCtxt<'a, 'tcx, 'tcx>, fld_r: &'a mut F) -> RegionReplacer<'a, 'tcx>
|
||||
impl<'a, 'gcx, 'tcx> RegionReplacer<'a, 'gcx, 'tcx> {
|
||||
fn new<F>(tcx: TyCtxt<'a, 'gcx, 'tcx>, fld_r: &'a mut F)
|
||||
-> RegionReplacer<'a, 'gcx, 'tcx>
|
||||
where F : FnMut(ty::BoundRegion) -> ty::Region
|
||||
{
|
||||
RegionReplacer {
|
||||
@ -421,9 +423,8 @@ impl<'a, 'tcx> RegionReplacer<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> TypeFolder<'tcx> for RegionReplacer<'a, 'tcx>
|
||||
{
|
||||
fn tcx<'b>(&'b self) -> TyCtxt<'b, 'tcx, 'tcx> { self.tcx }
|
||||
impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for RegionReplacer<'a, 'gcx, 'tcx> {
|
||||
fn tcx<'b>(&'b self) -> TyCtxt<'b, 'gcx, 'tcx> { self.tcx }
|
||||
|
||||
fn fold_binder<T: TypeFoldable<'tcx>>(&mut self, t: &ty::Binder<T>) -> ty::Binder<T> {
|
||||
self.current_depth += 1;
|
||||
@ -463,7 +464,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for RegionReplacer<'a, 'tcx>
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Region eraser
|
||||
|
||||
impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
/// Returns an equivalent value with all free regions removed (note
|
||||
/// that late-bound regions remain, because they are important for
|
||||
/// subtyping, but they are anonymized and normalized as well)..
|
||||
@ -475,10 +476,10 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
value, value1);
|
||||
return value1;
|
||||
|
||||
struct RegionEraser<'a, 'tcx: 'a>(TyCtxt<'a, 'tcx, 'tcx>);
|
||||
struct RegionEraser<'a, 'gcx: 'a+'tcx, 'tcx: 'a>(TyCtxt<'a, 'gcx, 'tcx>);
|
||||
|
||||
impl<'a, 'tcx> TypeFolder<'tcx> for RegionEraser<'a, 'tcx> {
|
||||
fn tcx<'b>(&'b self) -> TyCtxt<'b, 'tcx, 'tcx> { self.0 }
|
||||
impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for RegionEraser<'a, 'gcx, 'tcx> {
|
||||
fn tcx<'b>(&'b self) -> TyCtxt<'b, 'gcx, 'tcx> { self.0 }
|
||||
|
||||
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
|
||||
match self.tcx().normalized_cache.borrow().get(&ty).cloned() {
|
||||
@ -486,9 +487,15 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
Some(u) => return u
|
||||
}
|
||||
|
||||
let t_norm = ty.super_fold_with(self);
|
||||
self.tcx().normalized_cache.borrow_mut().insert(ty, t_norm);
|
||||
return t_norm;
|
||||
// FIXME(eddyb) should local contexts have a cache too?
|
||||
if let Some(ty_lifted) = self.tcx().lift_to_global(&ty) {
|
||||
let tcx = self.tcx().global_tcx();
|
||||
let t_norm = ty_lifted.super_fold_with(&mut RegionEraser(tcx));
|
||||
tcx.normalized_cache.borrow_mut().insert(ty_lifted, t_norm);
|
||||
t_norm
|
||||
} else {
|
||||
ty.super_fold_with(self)
|
||||
}
|
||||
}
|
||||
|
||||
fn fold_binder<T>(&mut self, t: &ty::Binder<T>) -> ty::Binder<T>
|
||||
@ -543,8 +550,10 @@ pub fn shift_region(region: ty::Region, amount: u32) -> ty::Region {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn shift_regions<'a, 'tcx, T:TypeFoldable<'tcx>>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
amount: u32, value: &T) -> T {
|
||||
pub fn shift_regions<'a, 'gcx, 'tcx, T>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
amount: u32, value: &T) -> T
|
||||
where T: TypeFoldable<'tcx>
|
||||
{
|
||||
debug!("shift_regions(value={:?}, amount={})",
|
||||
value, amount);
|
||||
|
||||
|
@ -14,7 +14,7 @@ use hir::def_id::{DefId, CRATE_DEF_INDEX};
|
||||
use ty::{self, Ty, TyCtxt};
|
||||
use syntax::ast;
|
||||
|
||||
impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
/// Returns a string identifying this def-id. This string is
|
||||
/// suitable for user output. It is relative to the current crate
|
||||
/// root.
|
||||
|
@ -773,26 +773,28 @@ pub struct GenericPredicates<'tcx> {
|
||||
pub predicates: VecPerParamSpace<Predicate<'tcx>>,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> GenericPredicates<'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> GenericPredicates<'tcx> {
|
||||
pub fn empty() -> GenericPredicates<'tcx> {
|
||||
GenericPredicates {
|
||||
predicates: VecPerParamSpace::empty(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn instantiate(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, substs: &Substs<'tcx>)
|
||||
pub fn instantiate(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, substs: &Substs<'tcx>)
|
||||
-> InstantiatedPredicates<'tcx> {
|
||||
InstantiatedPredicates {
|
||||
predicates: self.predicates.subst(tcx, substs),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn instantiate_supertrait(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
pub fn instantiate_supertrait(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
poly_trait_ref: &ty::PolyTraitRef<'tcx>)
|
||||
-> InstantiatedPredicates<'tcx>
|
||||
{
|
||||
InstantiatedPredicates {
|
||||
predicates: self.predicates.map(|pred| pred.subst_supertrait(tcx, poly_trait_ref))
|
||||
predicates: self.predicates.map(|pred| {
|
||||
pred.subst_supertrait(tcx, poly_trait_ref)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -832,13 +834,13 @@ pub enum Predicate<'tcx> {
|
||||
ClosureKind(DefId, ClosureKind),
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Predicate<'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> Predicate<'tcx> {
|
||||
/// Performs a substitution suitable for going from a
|
||||
/// poly-trait-ref to supertraits that must hold if that
|
||||
/// poly-trait-ref holds. This is slightly different from a normal
|
||||
/// substitution in terms of what happens with bound regions. See
|
||||
/// lengthy comment below for details.
|
||||
pub fn subst_supertrait(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
pub fn subst_supertrait(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
trait_ref: &ty::PolyTraitRef<'tcx>)
|
||||
-> ty::Predicate<'tcx>
|
||||
{
|
||||
@ -1224,13 +1226,6 @@ pub struct ParameterEnvironment<'tcx> {
|
||||
/// into Obligations, and elaborated and normalized.
|
||||
pub caller_bounds: Vec<ty::Predicate<'tcx>>,
|
||||
|
||||
/// Caches the results of trait selection. This cache is used
|
||||
/// for things that have to do with the parameters in scope.
|
||||
pub selection_cache: traits::SelectionCache<'tcx>,
|
||||
|
||||
/// Caches the results of trait evaluation.
|
||||
pub evaluation_cache: traits::EvaluationCache<'tcx>,
|
||||
|
||||
/// Scope that is attached to free regions for this scope. This
|
||||
/// is usually the id of the fn body, but for more abstract scopes
|
||||
/// like structs we often use the node-id of the struct.
|
||||
@ -1250,8 +1245,6 @@ impl<'a, 'tcx> ParameterEnvironment<'tcx> {
|
||||
free_substs: self.free_substs.clone(),
|
||||
implicit_region_bound: self.implicit_region_bound,
|
||||
caller_bounds: caller_bounds,
|
||||
selection_cache: traits::SelectionCache::new(),
|
||||
evaluation_cache: traits::EvaluationCache::new(),
|
||||
free_id_outlive: self.free_id_outlive,
|
||||
}
|
||||
}
|
||||
@ -1566,11 +1559,11 @@ impl VariantKind {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx, 'container> AdtDefData<'tcx, 'container> {
|
||||
fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
impl<'a, 'gcx, 'tcx, 'container> AdtDefData<'gcx, 'container> {
|
||||
fn new(tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
did: DefId,
|
||||
kind: AdtKind,
|
||||
variants: Vec<VariantDefData<'tcx, 'container>>) -> Self {
|
||||
variants: Vec<VariantDefData<'gcx, 'container>>) -> Self {
|
||||
let mut flags = AdtFlags::NO_ADT_FLAGS;
|
||||
let attrs = tcx.get_attrs(did);
|
||||
if attr::contains_name(&attrs, "fundamental") {
|
||||
@ -1597,7 +1590,7 @@ impl<'a, 'tcx, 'container> AdtDefData<'tcx, 'container> {
|
||||
}
|
||||
}
|
||||
|
||||
fn calculate_dtorck(&'tcx self, tcx: TyCtxt<'a, 'tcx, 'tcx>) {
|
||||
fn calculate_dtorck(&'gcx self, tcx: TyCtxt<'a, 'gcx, 'tcx>) {
|
||||
if tcx.is_adt_dtorck(self) {
|
||||
self.flags.set(self.flags.get() | AdtFlags::IS_DTORCK);
|
||||
}
|
||||
@ -1618,7 +1611,7 @@ impl<'a, 'tcx, 'container> AdtDefData<'tcx, 'container> {
|
||||
/// true, this type being safe for destruction requires it to be
|
||||
/// alive; Otherwise, only the contents are required to be.
|
||||
#[inline]
|
||||
pub fn is_dtorck(&'tcx self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> bool {
|
||||
pub fn is_dtorck(&'gcx self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> bool {
|
||||
if !self.flags.get().intersects(AdtFlags::IS_DTORCK_VALID) {
|
||||
self.calculate_dtorck(tcx)
|
||||
}
|
||||
@ -1653,18 +1646,18 @@ impl<'a, 'tcx, 'container> AdtDefData<'tcx, 'container> {
|
||||
|
||||
/// Asserts this is a struct and returns the struct's unique
|
||||
/// variant.
|
||||
pub fn struct_variant(&self) -> &VariantDefData<'tcx, 'container> {
|
||||
pub fn struct_variant(&self) -> &VariantDefData<'gcx, 'container> {
|
||||
assert_eq!(self.adt_kind(), AdtKind::Struct);
|
||||
&self.variants[0]
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn type_scheme(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> TypeScheme<'tcx> {
|
||||
pub fn type_scheme(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> TypeScheme<'gcx> {
|
||||
tcx.lookup_item_type(self.did)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn predicates(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> GenericPredicates<'tcx> {
|
||||
pub fn predicates(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> GenericPredicates<'gcx> {
|
||||
tcx.lookup_predicates(self.did)
|
||||
}
|
||||
|
||||
@ -1673,10 +1666,10 @@ impl<'a, 'tcx, 'container> AdtDefData<'tcx, 'container> {
|
||||
#[inline]
|
||||
pub fn all_fields(&self) ->
|
||||
iter::FlatMap<
|
||||
slice::Iter<VariantDefData<'tcx, 'container>>,
|
||||
slice::Iter<FieldDefData<'tcx, 'container>>,
|
||||
for<'s> fn(&'s VariantDefData<'tcx, 'container>)
|
||||
-> slice::Iter<'s, FieldDefData<'tcx, 'container>>
|
||||
slice::Iter<VariantDefData<'gcx, 'container>>,
|
||||
slice::Iter<FieldDefData<'gcx, 'container>>,
|
||||
for<'s> fn(&'s VariantDefData<'gcx, 'container>)
|
||||
-> slice::Iter<'s, FieldDefData<'gcx, 'container>>
|
||||
> {
|
||||
self.variants.iter().flat_map(VariantDefData::fields_iter)
|
||||
}
|
||||
@ -1696,7 +1689,7 @@ impl<'a, 'tcx, 'container> AdtDefData<'tcx, 'container> {
|
||||
self.variants.iter().all(|v| v.fields.is_empty())
|
||||
}
|
||||
|
||||
pub fn variant_with_id(&self, vid: DefId) -> &VariantDefData<'tcx, 'container> {
|
||||
pub fn variant_with_id(&self, vid: DefId) -> &VariantDefData<'gcx, 'container> {
|
||||
self.variants
|
||||
.iter()
|
||||
.find(|v| v.did == vid)
|
||||
@ -1710,7 +1703,7 @@ impl<'a, 'tcx, 'container> AdtDefData<'tcx, 'container> {
|
||||
.expect("variant_index_with_id: unknown variant")
|
||||
}
|
||||
|
||||
pub fn variant_of_def(&self, def: Def) -> &VariantDefData<'tcx, 'container> {
|
||||
pub fn variant_of_def(&self, def: Def) -> &VariantDefData<'gcx, 'container> {
|
||||
match def {
|
||||
Def::Variant(_, vid) => self.variant_with_id(vid),
|
||||
Def::Struct(..) | Def::TyAlias(..) => self.struct_variant(),
|
||||
@ -1734,7 +1727,9 @@ impl<'a, 'tcx, 'container> AdtDefData<'tcx, 'container> {
|
||||
None => NoDtor,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'gcx, 'tcx, 'container> AdtDefData<'tcx, 'container> {
|
||||
/// Returns a simpler type such that `Self: Sized` if and only
|
||||
/// if that type is Sized, or `TyErr` if this type is recursive.
|
||||
///
|
||||
@ -1752,12 +1747,13 @@ impl<'a, 'tcx, 'container> AdtDefData<'tcx, 'container> {
|
||||
///
|
||||
/// Due to normalization being eager, this applies even if
|
||||
/// the associated type is behind a pointer, e.g. issue #31299.
|
||||
pub fn sized_constraint(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Ty<'tcx> {
|
||||
pub fn sized_constraint(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> {
|
||||
let dep_node = DepNode::SizedConstraint(self.did);
|
||||
match self.sized_constraint.get(dep_node) {
|
||||
None => {
|
||||
let this = tcx.lookup_adt_def_master(self.did);
|
||||
this.calculate_sized_constraint_inner(tcx, &mut Vec::new());
|
||||
let global_tcx = tcx.global_tcx();
|
||||
let this = global_tcx.lookup_adt_def_master(self.did);
|
||||
this.calculate_sized_constraint_inner(global_tcx, &mut Vec::new());
|
||||
self.sized_constraint(tcx)
|
||||
}
|
||||
Some(ty) => ty
|
||||
@ -1949,7 +1945,7 @@ impl<'tcx, 'container> VariantDefData<'tcx, 'container> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx, 'container> FieldDefData<'tcx, 'container> {
|
||||
impl<'a, 'gcx, 'tcx, 'container> FieldDefData<'tcx, 'container> {
|
||||
pub fn new(did: DefId,
|
||||
name: Name,
|
||||
vis: Visibility) -> Self {
|
||||
@ -1961,7 +1957,7 @@ impl<'a, 'tcx, 'container> FieldDefData<'tcx, 'container> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ty(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, subst: &Substs<'tcx>) -> Ty<'tcx> {
|
||||
pub fn ty(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, subst: &Substs<'tcx>) -> Ty<'tcx> {
|
||||
self.unsubst_ty().subst(tcx, subst)
|
||||
}
|
||||
|
||||
@ -2142,8 +2138,8 @@ impl BorrowKind {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
pub fn node_id_to_type(self, id: NodeId) -> Ty<'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
pub fn node_id_to_type(self, id: NodeId) -> Ty<'gcx> {
|
||||
match self.node_id_to_type_opt(id) {
|
||||
Some(ty) => ty,
|
||||
None => bug!("node_id_to_type: no type for node `{}`",
|
||||
@ -2151,11 +2147,11 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn node_id_to_type_opt(self, id: NodeId) -> Option<Ty<'tcx>> {
|
||||
pub fn node_id_to_type_opt(self, id: NodeId) -> Option<Ty<'gcx>> {
|
||||
self.tables.borrow().node_types.get(&id).cloned()
|
||||
}
|
||||
|
||||
pub fn node_id_item_substs(self, id: NodeId) -> ItemSubsts<'tcx> {
|
||||
pub fn node_id_item_substs(self, id: NodeId) -> ItemSubsts<'gcx> {
|
||||
match self.tables.borrow().item_substs.get(&id) {
|
||||
None => ItemSubsts::empty(),
|
||||
Some(ts) => ts.clone(),
|
||||
@ -2164,10 +2160,10 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
|
||||
// Returns the type of a pattern as a monotype. Like @expr_ty, this function
|
||||
// doesn't provide type parameter substitutions.
|
||||
pub fn pat_ty(self, pat: &hir::Pat) -> Ty<'tcx> {
|
||||
pub fn pat_ty(self, pat: &hir::Pat) -> Ty<'gcx> {
|
||||
self.node_id_to_type(pat.id)
|
||||
}
|
||||
pub fn pat_ty_opt(self, pat: &hir::Pat) -> Option<Ty<'tcx>> {
|
||||
pub fn pat_ty_opt(self, pat: &hir::Pat) -> Option<Ty<'gcx>> {
|
||||
self.node_id_to_type_opt(pat.id)
|
||||
}
|
||||
|
||||
@ -2181,11 +2177,11 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
// NB (2): This type doesn't provide type parameter substitutions; e.g. if you
|
||||
// ask for the type of "id" in "id(3)", it will return "fn(&isize) -> isize"
|
||||
// instead of "fn(ty) -> T with T = isize".
|
||||
pub fn expr_ty(self, expr: &hir::Expr) -> Ty<'tcx> {
|
||||
pub fn expr_ty(self, expr: &hir::Expr) -> Ty<'gcx> {
|
||||
self.node_id_to_type(expr.id)
|
||||
}
|
||||
|
||||
pub fn expr_ty_opt(self, expr: &hir::Expr) -> Option<Ty<'tcx>> {
|
||||
pub fn expr_ty_opt(self, expr: &hir::Expr) -> Option<Ty<'gcx>> {
|
||||
self.node_id_to_type_opt(expr.id)
|
||||
}
|
||||
|
||||
@ -2198,17 +2194,17 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
/// hard to do, I just hate that code so much I didn't want to touch it
|
||||
/// unless it was to fix it properly, which seemed a distraction from the
|
||||
/// thread at hand! -nmatsakis
|
||||
pub fn expr_ty_adjusted(self, expr: &hir::Expr) -> Ty<'tcx> {
|
||||
pub fn expr_ty_adjusted(self, expr: &hir::Expr) -> Ty<'gcx> {
|
||||
self.expr_ty(expr)
|
||||
.adjust(self, expr.span, expr.id,
|
||||
.adjust(self.global_tcx(), expr.span, expr.id,
|
||||
self.tables.borrow().adjustments.get(&expr.id),
|
||||
|method_call| {
|
||||
self.tables.borrow().method_map.get(&method_call).map(|method| method.ty)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn expr_ty_adjusted_opt(self, expr: &hir::Expr) -> Option<Ty<'tcx>> {
|
||||
self.expr_ty_opt(expr).map(|t| t.adjust(self,
|
||||
pub fn expr_ty_adjusted_opt(self, expr: &hir::Expr) -> Option<Ty<'gcx>> {
|
||||
self.expr_ty_opt(expr).map(|t| t.adjust(self.global_tcx(),
|
||||
expr.span,
|
||||
expr.id,
|
||||
self.tables.borrow().adjustments.get(&expr.id),
|
||||
@ -2316,7 +2312,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn provided_trait_methods(self, id: DefId) -> Vec<Rc<Method<'tcx>>> {
|
||||
pub fn provided_trait_methods(self, id: DefId) -> Vec<Rc<Method<'gcx>>> {
|
||||
if let Some(id) = self.map.as_local_node_id(id) {
|
||||
if let ItemTrait(_, _, _, ref ms) = self.map.expect_item(id).node {
|
||||
ms.iter().filter_map(|ti| {
|
||||
@ -2337,11 +2333,11 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
bug!("provided_trait_methods: `{:?}` is not a trait", id)
|
||||
}
|
||||
} else {
|
||||
self.sess.cstore.provided_trait_methods(self, id)
|
||||
self.sess.cstore.provided_trait_methods(self.global_tcx(), id)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn associated_consts(self, id: DefId) -> Vec<Rc<AssociatedConst<'tcx>>> {
|
||||
pub fn associated_consts(self, id: DefId) -> Vec<Rc<AssociatedConst<'gcx>>> {
|
||||
if let Some(id) = self.map.as_local_node_id(id) {
|
||||
match self.map.expect_item(id).node {
|
||||
ItemTrait(_, _, _, ref tis) => {
|
||||
@ -2381,7 +2377,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
self.sess.cstore.associated_consts(self, id)
|
||||
self.sess.cstore.associated_consts(self.global_tcx(), id)
|
||||
}
|
||||
}
|
||||
|
||||
@ -2420,10 +2416,10 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn impl_or_trait_item(self, id: DefId) -> ImplOrTraitItem<'tcx> {
|
||||
pub fn impl_or_trait_item(self, id: DefId) -> ImplOrTraitItem<'gcx> {
|
||||
lookup_locally_or_in_crate_store(
|
||||
"impl_or_trait_items", id, &self.impl_or_trait_items,
|
||||
|| self.sess.cstore.impl_or_trait_item(self, id)
|
||||
|| self.sess.cstore.impl_or_trait_item(self.global_tcx(), id)
|
||||
.expect("missing ImplOrTraitItem in metadata"))
|
||||
}
|
||||
|
||||
@ -2435,10 +2431,10 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
|
||||
/// Returns the trait-ref corresponding to a given impl, or None if it is
|
||||
/// an inherent impl.
|
||||
pub fn impl_trait_ref(self, id: DefId) -> Option<TraitRef<'tcx>> {
|
||||
pub fn impl_trait_ref(self, id: DefId) -> Option<TraitRef<'gcx>> {
|
||||
lookup_locally_or_in_crate_store(
|
||||
"impl_trait_refs", id, &self.impl_trait_refs,
|
||||
|| self.sess.cstore.impl_trait_ref(self, id))
|
||||
|| self.sess.cstore.impl_trait_ref(self.global_tcx(), id))
|
||||
}
|
||||
|
||||
/// Returns whether this DefId refers to an impl
|
||||
@ -2487,55 +2483,55 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
}
|
||||
|
||||
// Register a given item type
|
||||
pub fn register_item_type(self, did: DefId, ty: TypeScheme<'tcx>) {
|
||||
pub fn register_item_type(self, did: DefId, ty: TypeScheme<'gcx>) {
|
||||
self.tcache.borrow_mut().insert(did, ty);
|
||||
}
|
||||
|
||||
// If the given item is in an external crate, looks up its type and adds it to
|
||||
// the type cache. Returns the type parameters and type.
|
||||
pub fn lookup_item_type(self, did: DefId) -> TypeScheme<'tcx> {
|
||||
pub fn lookup_item_type(self, did: DefId) -> TypeScheme<'gcx> {
|
||||
lookup_locally_or_in_crate_store(
|
||||
"tcache", did, &self.tcache,
|
||||
|| self.sess.cstore.item_type(self, did))
|
||||
|| self.sess.cstore.item_type(self.global_tcx(), did))
|
||||
}
|
||||
|
||||
/// Given the did of a trait, returns its canonical trait ref.
|
||||
pub fn lookup_trait_def(self, did: DefId) -> &'tcx TraitDef<'tcx> {
|
||||
pub fn lookup_trait_def(self, did: DefId) -> &'gcx TraitDef<'gcx> {
|
||||
lookup_locally_or_in_crate_store(
|
||||
"trait_defs", did, &self.trait_defs,
|
||||
|| self.alloc_trait_def(self.sess.cstore.trait_def(self, did))
|
||||
|| self.alloc_trait_def(self.sess.cstore.trait_def(self.global_tcx(), did))
|
||||
)
|
||||
}
|
||||
|
||||
/// Given the did of an ADT, return a master reference to its
|
||||
/// definition. Unless you are planning on fulfilling the ADT's fields,
|
||||
/// use lookup_adt_def instead.
|
||||
pub fn lookup_adt_def_master(self, did: DefId) -> AdtDefMaster<'tcx> {
|
||||
pub fn lookup_adt_def_master(self, did: DefId) -> AdtDefMaster<'gcx> {
|
||||
lookup_locally_or_in_crate_store(
|
||||
"adt_defs", did, &self.adt_defs,
|
||||
|| self.sess.cstore.adt_def(self, did)
|
||||
|| self.sess.cstore.adt_def(self.global_tcx(), did)
|
||||
)
|
||||
}
|
||||
|
||||
/// Given the did of an ADT, return a reference to its definition.
|
||||
pub fn lookup_adt_def(self, did: DefId) -> AdtDef<'tcx> {
|
||||
pub fn lookup_adt_def(self, did: DefId) -> AdtDef<'gcx> {
|
||||
// when reverse-variance goes away, a transmute::<AdtDefMaster,AdtDef>
|
||||
// would be needed here.
|
||||
self.lookup_adt_def_master(did)
|
||||
}
|
||||
|
||||
/// Given the did of an item, returns its full set of predicates.
|
||||
pub fn lookup_predicates(self, did: DefId) -> GenericPredicates<'tcx> {
|
||||
pub fn lookup_predicates(self, did: DefId) -> GenericPredicates<'gcx> {
|
||||
lookup_locally_or_in_crate_store(
|
||||
"predicates", did, &self.predicates,
|
||||
|| self.sess.cstore.item_predicates(self, did))
|
||||
|| self.sess.cstore.item_predicates(self.global_tcx(), did))
|
||||
}
|
||||
|
||||
/// Given the did of a trait, returns its superpredicates.
|
||||
pub fn lookup_super_predicates(self, did: DefId) -> GenericPredicates<'tcx> {
|
||||
pub fn lookup_super_predicates(self, did: DefId) -> GenericPredicates<'gcx> {
|
||||
lookup_locally_or_in_crate_store(
|
||||
"super_predicates", did, &self.super_predicates,
|
||||
|| self.sess.cstore.item_super_predicates(self, did))
|
||||
|| self.sess.cstore.item_super_predicates(self.global_tcx(), did))
|
||||
}
|
||||
|
||||
/// If `type_needs_drop` returns true, then `ty` is definitely
|
||||
@ -2545,13 +2541,14 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
/// (Note that this implies that if `ty` has a destructor attached,
|
||||
/// then `type_needs_drop` will definitely return `true` for `ty`.)
|
||||
pub fn type_needs_drop_given_env(self,
|
||||
ty: Ty<'tcx>,
|
||||
param_env: &ty::ParameterEnvironment<'tcx>) -> bool {
|
||||
ty: Ty<'gcx>,
|
||||
param_env: &ty::ParameterEnvironment<'gcx>) -> bool {
|
||||
// Issue #22536: We first query type_moves_by_default. It sees a
|
||||
// normalized version of the type, and therefore will definitely
|
||||
// know whether the type implements Copy (and thus needs no
|
||||
// cleanup/drop/zeroing) ...
|
||||
let implements_copy = !ty.moves_by_default(self, param_env, DUMMY_SP);
|
||||
let tcx = self.global_tcx();
|
||||
let implements_copy = !ty.moves_by_default(tcx, param_env, DUMMY_SP);
|
||||
|
||||
if implements_copy { return false; }
|
||||
|
||||
@ -2566,13 +2563,13 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
// bound attached (see above), it is sound to treat it as having a
|
||||
// destructor (e.g. zero its memory on move).
|
||||
|
||||
let contents = ty.type_contents(self);
|
||||
let contents = ty.type_contents(tcx);
|
||||
debug!("type_needs_drop ty={:?} contents={:?}", ty, contents);
|
||||
contents.needs_drop(self)
|
||||
contents.needs_drop(tcx)
|
||||
}
|
||||
|
||||
/// Get the attributes of a definition.
|
||||
pub fn get_attrs(self, did: DefId) -> Cow<'tcx, [ast::Attribute]> {
|
||||
pub fn get_attrs(self, did: DefId) -> Cow<'gcx, [ast::Attribute]> {
|
||||
if let Some(id) = self.map.as_local_node_id(did) {
|
||||
Cow::Borrowed(self.map.attrs(id))
|
||||
} else {
|
||||
@ -2720,15 +2717,15 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
}
|
||||
|
||||
pub fn closure_kind(self, def_id: DefId) -> ty::ClosureKind {
|
||||
Tables::closure_kind(&self.tables, self, def_id)
|
||||
Tables::closure_kind(&self.tables, self.global_tcx(), def_id)
|
||||
}
|
||||
|
||||
pub fn closure_type(self,
|
||||
def_id: DefId,
|
||||
substs: &ClosureSubsts<'tcx>)
|
||||
-> ty::ClosureTy<'tcx>
|
||||
substs: &ClosureSubsts<'gcx>)
|
||||
-> ty::ClosureTy<'gcx>
|
||||
{
|
||||
Tables::closure_type(&self.tables, self, def_id, substs)
|
||||
Tables::closure_type(&self.tables, self.global_tcx(), def_id, substs)
|
||||
}
|
||||
|
||||
/// Given the def_id of an impl, return the def_id of the trait it implements.
|
||||
@ -2741,7 +2738,8 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
/// ID of the impl that the method belongs to. Otherwise, return `None`.
|
||||
pub fn impl_of_method(self, def_id: DefId) -> Option<DefId> {
|
||||
if def_id.krate != LOCAL_CRATE {
|
||||
return self.sess.cstore.impl_or_trait_item(self, def_id).and_then(|item| {
|
||||
return self.sess.cstore.impl_or_trait_item(self.global_tcx(), def_id)
|
||||
.and_then(|item| {
|
||||
match item.container() {
|
||||
TraitContainer(_) => None,
|
||||
ImplContainer(def_id) => Some(def_id),
|
||||
@ -2764,7 +2762,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
/// the trait that the method belongs to. Otherwise, return `None`.
|
||||
pub fn trait_of_item(self, def_id: DefId) -> Option<DefId> {
|
||||
if def_id.krate != LOCAL_CRATE {
|
||||
return self.sess.cstore.trait_of_item(self, def_id);
|
||||
return self.sess.cstore.trait_of_item(self.global_tcx(), def_id);
|
||||
}
|
||||
match self.impl_or_trait_items.borrow().get(&def_id).cloned() {
|
||||
Some(impl_or_trait_item) => {
|
||||
@ -2806,12 +2804,12 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
// for an empty parameter environment, there ARE no free
|
||||
// regions, so it shouldn't matter what we use for the free id
|
||||
let free_id_outlive = self.region_maps.node_extent(ast::DUMMY_NODE_ID);
|
||||
ty::ParameterEnvironment { free_substs: Substs::empty(),
|
||||
caller_bounds: Vec::new(),
|
||||
implicit_region_bound: ty::ReEmpty,
|
||||
selection_cache: traits::SelectionCache::new(),
|
||||
evaluation_cache: traits::EvaluationCache::new(),
|
||||
free_id_outlive: free_id_outlive }
|
||||
ty::ParameterEnvironment {
|
||||
free_substs: Substs::empty(),
|
||||
caller_bounds: Vec::new(),
|
||||
implicit_region_bound: ty::ReEmpty,
|
||||
free_id_outlive: free_id_outlive
|
||||
}
|
||||
}
|
||||
|
||||
/// Constructs and returns a substitution that can be applied to move from
|
||||
@ -2819,14 +2817,14 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
/// In general, this means converting from bound parameters to
|
||||
/// free parameters. Since we currently represent bound/free type
|
||||
/// parameters in the same way, this only has an effect on regions.
|
||||
pub fn construct_free_substs(self, generics: &Generics<'tcx>,
|
||||
free_id_outlive: CodeExtent) -> Substs<'tcx> {
|
||||
pub fn construct_free_substs(self, generics: &Generics<'gcx>,
|
||||
free_id_outlive: CodeExtent) -> Substs<'gcx> {
|
||||
// map T => T
|
||||
let mut types = VecPerParamSpace::empty();
|
||||
for def in generics.types.as_slice() {
|
||||
debug!("construct_parameter_environment(): push_types_from_defs: def={:?}",
|
||||
def);
|
||||
types.push(def.space, self.mk_param_from_def(def));
|
||||
types.push(def.space, self.global_tcx().mk_param_from_def(def));
|
||||
}
|
||||
|
||||
// map bound 'a => free 'a
|
||||
@ -2850,10 +2848,10 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
/// for the `free_id_outlive` parameter. (But note that that is not always quite right.)
|
||||
pub fn construct_parameter_environment(self,
|
||||
span: Span,
|
||||
generics: &ty::Generics<'tcx>,
|
||||
generic_predicates: &ty::GenericPredicates<'tcx>,
|
||||
generics: &ty::Generics<'gcx>,
|
||||
generic_predicates: &ty::GenericPredicates<'gcx>,
|
||||
free_id_outlive: CodeExtent)
|
||||
-> ParameterEnvironment<'tcx>
|
||||
-> ParameterEnvironment<'gcx>
|
||||
{
|
||||
//
|
||||
// Construct the free substs.
|
||||
@ -2865,8 +2863,9 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
// Compute the bounds on Self and the type parameters.
|
||||
//
|
||||
|
||||
let bounds = generic_predicates.instantiate(self, &free_substs);
|
||||
let bounds = self.liberate_late_bound_regions(free_id_outlive, &ty::Binder(bounds));
|
||||
let tcx = self.global_tcx();
|
||||
let bounds = generic_predicates.instantiate(tcx, &free_substs);
|
||||
let bounds = tcx.liberate_late_bound_regions(free_id_outlive, &ty::Binder(bounds));
|
||||
let predicates = bounds.predicates.into_vec();
|
||||
|
||||
// Finally, we have to normalize the bounds in the environment, in
|
||||
@ -2886,13 +2885,11 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
free_substs: free_substs,
|
||||
implicit_region_bound: ty::ReScope(free_id_outlive),
|
||||
caller_bounds: predicates,
|
||||
selection_cache: traits::SelectionCache::new(),
|
||||
evaluation_cache: traits::EvaluationCache::new(),
|
||||
free_id_outlive: free_id_outlive,
|
||||
};
|
||||
|
||||
let cause = traits::ObligationCause::misc(span, free_id_outlive.node_id(&self.region_maps));
|
||||
traits::normalize_param_env_or_error(self, unnormalized_env, cause)
|
||||
traits::normalize_param_env_or_error(tcx, unnormalized_env, cause)
|
||||
}
|
||||
|
||||
pub fn is_method_call(self, expr_id: NodeId) -> bool {
|
||||
@ -2911,9 +2908,9 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
pub fn visit_all_items_in_krate<V,F>(self,
|
||||
dep_node_fn: F,
|
||||
visitor: &mut V)
|
||||
where F: FnMut(DefId) -> DepNode<DefId>, V: Visitor<'tcx>
|
||||
where F: FnMut(DefId) -> DepNode<DefId>, V: Visitor<'gcx>
|
||||
{
|
||||
dep_graph::visit_all_items_in_krate(self, dep_node_fn, visitor);
|
||||
dep_graph::visit_all_items_in_krate(self.global_tcx(), dep_node_fn, visitor);
|
||||
}
|
||||
|
||||
/// Looks up the span of `impl_did` if the impl is local; otherwise returns `Err`
|
||||
|
@ -55,7 +55,7 @@ pub enum Component<'tcx> {
|
||||
EscapingProjection(Vec<Component<'tcx>>),
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> InferCtxt<'a, 'tcx, 'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
/// Returns all the things that must outlive `'a` for the condition
|
||||
/// `ty0: 'a` to hold.
|
||||
pub fn outlives_components(&self, ty0: Ty<'tcx>)
|
||||
|
@ -28,8 +28,8 @@ pub enum Cause {
|
||||
ExistentialRegionBound, // relating an existential region bound
|
||||
}
|
||||
|
||||
pub trait TypeRelation<'a,'tcx> : Sized {
|
||||
fn tcx(&self) -> TyCtxt<'a, 'tcx, 'tcx>;
|
||||
pub trait TypeRelation<'a, 'gcx: 'a+'tcx, 'tcx: 'a> : Sized {
|
||||
fn tcx(&self) -> TyCtxt<'a, 'gcx, 'tcx>;
|
||||
|
||||
/// Returns a static string we can use for printouts.
|
||||
fn tag(&self) -> &'static str;
|
||||
@ -45,22 +45,22 @@ pub trait TypeRelation<'a,'tcx> : Sized {
|
||||
}
|
||||
|
||||
/// Generic relation routine suitable for most anything.
|
||||
fn relate<T:Relate<'a,'tcx>>(&mut self, a: &T, b: &T) -> RelateResult<'tcx, T> {
|
||||
fn relate<T: Relate<'tcx>>(&mut self, a: &T, b: &T) -> RelateResult<'tcx, T> {
|
||||
Relate::relate(self, a, b)
|
||||
}
|
||||
|
||||
/// Relete elements of two slices pairwise.
|
||||
fn relate_zip<T:Relate<'a,'tcx>>(&mut self, a: &[T], b: &[T]) -> RelateResult<'tcx, Vec<T>> {
|
||||
fn relate_zip<T: Relate<'tcx>>(&mut self, a: &[T], b: &[T]) -> RelateResult<'tcx, Vec<T>> {
|
||||
assert_eq!(a.len(), b.len());
|
||||
a.iter().zip(b).map(|(a, b)| self.relate(a, b)).collect()
|
||||
}
|
||||
|
||||
/// Switch variance for the purpose of relating `a` and `b`.
|
||||
fn relate_with_variance<T:Relate<'a,'tcx>>(&mut self,
|
||||
variance: ty::Variance,
|
||||
a: &T,
|
||||
b: &T)
|
||||
-> RelateResult<'tcx, T>;
|
||||
fn relate_with_variance<T: Relate<'tcx>>(&mut self,
|
||||
variance: ty::Variance,
|
||||
a: &T,
|
||||
b: &T)
|
||||
-> RelateResult<'tcx, T>;
|
||||
|
||||
// Overrideable relations. You shouldn't typically call these
|
||||
// directly, instead call `relate()`, which in turn calls
|
||||
@ -76,25 +76,24 @@ pub trait TypeRelation<'a,'tcx> : Sized {
|
||||
|
||||
fn binders<T>(&mut self, a: &ty::Binder<T>, b: &ty::Binder<T>)
|
||||
-> RelateResult<'tcx, ty::Binder<T>>
|
||||
where T: Relate<'a,'tcx>;
|
||||
where T: Relate<'tcx>;
|
||||
}
|
||||
|
||||
pub trait Relate<'a,'tcx>: TypeFoldable<'tcx> {
|
||||
fn relate<R:TypeRelation<'a,'tcx>>(relation: &mut R,
|
||||
a: &Self,
|
||||
b: &Self)
|
||||
-> RelateResult<'tcx, Self>;
|
||||
pub trait Relate<'tcx>: TypeFoldable<'tcx> {
|
||||
fn relate<'a, 'gcx, R>(relation: &mut R, a: &Self, b: &Self)
|
||||
-> RelateResult<'tcx, Self>
|
||||
where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Relate impls
|
||||
|
||||
impl<'a,'tcx:'a> Relate<'a,'tcx> for ty::TypeAndMut<'tcx> {
|
||||
fn relate<R>(relation: &mut R,
|
||||
a: &ty::TypeAndMut<'tcx>,
|
||||
b: &ty::TypeAndMut<'tcx>)
|
||||
-> RelateResult<'tcx, ty::TypeAndMut<'tcx>>
|
||||
where R: TypeRelation<'a,'tcx>
|
||||
impl<'tcx> Relate<'tcx> for ty::TypeAndMut<'tcx> {
|
||||
fn relate<'a, 'gcx, R>(relation: &mut R,
|
||||
a: &ty::TypeAndMut<'tcx>,
|
||||
b: &ty::TypeAndMut<'tcx>)
|
||||
-> RelateResult<'tcx, ty::TypeAndMut<'tcx>>
|
||||
where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
|
||||
{
|
||||
debug!("{}.mts({:?}, {:?})",
|
||||
relation.tag(),
|
||||
@ -117,12 +116,12 @@ impl<'a,'tcx:'a> Relate<'a,'tcx> for ty::TypeAndMut<'tcx> {
|
||||
// substitutions are not themselves relatable without more context,
|
||||
// but they is an important subroutine for things that ARE relatable,
|
||||
// like traits etc.
|
||||
fn relate_item_substs<'a,'tcx:'a,R>(relation: &mut R,
|
||||
item_def_id: DefId,
|
||||
a_subst: &Substs<'tcx>,
|
||||
b_subst: &Substs<'tcx>)
|
||||
-> RelateResult<'tcx, Substs<'tcx>>
|
||||
where R: TypeRelation<'a,'tcx>
|
||||
fn relate_item_substs<'a, 'gcx, 'tcx, R>(relation: &mut R,
|
||||
item_def_id: DefId,
|
||||
a_subst: &Substs<'tcx>,
|
||||
b_subst: &Substs<'tcx>)
|
||||
-> RelateResult<'tcx, Substs<'tcx>>
|
||||
where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
|
||||
{
|
||||
debug!("substs: item_def_id={:?} a_subst={:?} b_subst={:?}",
|
||||
item_def_id,
|
||||
@ -139,12 +138,12 @@ fn relate_item_substs<'a,'tcx:'a,R>(relation: &mut R,
|
||||
relate_substs(relation, opt_variances, a_subst, b_subst)
|
||||
}
|
||||
|
||||
pub fn relate_substs<'a,'tcx:'a,R>(relation: &mut R,
|
||||
variances: Option<&ty::ItemVariances>,
|
||||
a_subst: &Substs<'tcx>,
|
||||
b_subst: &Substs<'tcx>)
|
||||
-> RelateResult<'tcx, Substs<'tcx>>
|
||||
where R: TypeRelation<'a,'tcx>
|
||||
pub fn relate_substs<'a, 'gcx, 'tcx, R>(relation: &mut R,
|
||||
variances: Option<&ty::ItemVariances>,
|
||||
a_subst: &Substs<'tcx>,
|
||||
b_subst: &Substs<'tcx>)
|
||||
-> RelateResult<'tcx, Substs<'tcx>>
|
||||
where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
|
||||
{
|
||||
let mut substs = Substs::empty();
|
||||
|
||||
@ -170,12 +169,12 @@ pub fn relate_substs<'a,'tcx:'a,R>(relation: &mut R,
|
||||
Ok(substs)
|
||||
}
|
||||
|
||||
fn relate_type_params<'a,'tcx:'a,R>(relation: &mut R,
|
||||
variances: Option<&[ty::Variance]>,
|
||||
a_tys: &[Ty<'tcx>],
|
||||
b_tys: &[Ty<'tcx>])
|
||||
-> RelateResult<'tcx, Vec<Ty<'tcx>>>
|
||||
where R: TypeRelation<'a,'tcx>
|
||||
fn relate_type_params<'a, 'gcx, 'tcx, R>(relation: &mut R,
|
||||
variances: Option<&[ty::Variance]>,
|
||||
a_tys: &[Ty<'tcx>],
|
||||
b_tys: &[Ty<'tcx>])
|
||||
-> RelateResult<'tcx, Vec<Ty<'tcx>>>
|
||||
where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
|
||||
{
|
||||
if a_tys.len() != b_tys.len() {
|
||||
return Err(TypeError::TyParamSize(expected_found(relation,
|
||||
@ -193,12 +192,12 @@ fn relate_type_params<'a,'tcx:'a,R>(relation: &mut R,
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn relate_region_params<'a,'tcx:'a,R>(relation: &mut R,
|
||||
variances: Option<&[ty::Variance]>,
|
||||
a_rs: &[ty::Region],
|
||||
b_rs: &[ty::Region])
|
||||
-> RelateResult<'tcx, Vec<ty::Region>>
|
||||
where R: TypeRelation<'a,'tcx>
|
||||
fn relate_region_params<'a, 'gcx, 'tcx, R>(relation: &mut R,
|
||||
variances: Option<&[ty::Variance]>,
|
||||
a_rs: &[ty::Region],
|
||||
b_rs: &[ty::Region])
|
||||
-> RelateResult<'tcx, Vec<ty::Region>>
|
||||
where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
|
||||
{
|
||||
let num_region_params = a_rs.len();
|
||||
|
||||
@ -224,12 +223,12 @@ fn relate_region_params<'a,'tcx:'a,R>(relation: &mut R,
|
||||
.collect()
|
||||
}
|
||||
|
||||
impl<'a,'tcx:'a> Relate<'a,'tcx> for ty::BareFnTy<'tcx> {
|
||||
fn relate<R>(relation: &mut R,
|
||||
a: &ty::BareFnTy<'tcx>,
|
||||
b: &ty::BareFnTy<'tcx>)
|
||||
-> RelateResult<'tcx, ty::BareFnTy<'tcx>>
|
||||
where R: TypeRelation<'a,'tcx>
|
||||
impl<'tcx> Relate<'tcx> for ty::BareFnTy<'tcx> {
|
||||
fn relate<'a, 'gcx, R>(relation: &mut R,
|
||||
a: &ty::BareFnTy<'tcx>,
|
||||
b: &ty::BareFnTy<'tcx>)
|
||||
-> RelateResult<'tcx, ty::BareFnTy<'tcx>>
|
||||
where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
|
||||
{
|
||||
let unsafety = relation.relate(&a.unsafety, &b.unsafety)?;
|
||||
let abi = relation.relate(&a.abi, &b.abi)?;
|
||||
@ -240,12 +239,12 @@ impl<'a,'tcx:'a> Relate<'a,'tcx> for ty::BareFnTy<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a,'tcx:'a> Relate<'a,'tcx> for ty::FnSig<'tcx> {
|
||||
fn relate<R>(relation: &mut R,
|
||||
a: &ty::FnSig<'tcx>,
|
||||
b: &ty::FnSig<'tcx>)
|
||||
-> RelateResult<'tcx, ty::FnSig<'tcx>>
|
||||
where R: TypeRelation<'a,'tcx>
|
||||
impl<'tcx> Relate<'tcx> for ty::FnSig<'tcx> {
|
||||
fn relate<'a, 'gcx, R>(relation: &mut R,
|
||||
a: &ty::FnSig<'tcx>,
|
||||
b: &ty::FnSig<'tcx>)
|
||||
-> RelateResult<'tcx, ty::FnSig<'tcx>>
|
||||
where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
|
||||
{
|
||||
if a.variadic != b.variadic {
|
||||
return Err(TypeError::VariadicMismatch(
|
||||
@ -272,11 +271,11 @@ impl<'a,'tcx:'a> Relate<'a,'tcx> for ty::FnSig<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn relate_arg_vecs<'a,'tcx:'a,R>(relation: &mut R,
|
||||
a_args: &[Ty<'tcx>],
|
||||
b_args: &[Ty<'tcx>])
|
||||
-> RelateResult<'tcx, Vec<Ty<'tcx>>>
|
||||
where R: TypeRelation<'a,'tcx>
|
||||
fn relate_arg_vecs<'a, 'gcx, 'tcx, R>(relation: &mut R,
|
||||
a_args: &[Ty<'tcx>],
|
||||
b_args: &[Ty<'tcx>])
|
||||
-> RelateResult<'tcx, Vec<Ty<'tcx>>>
|
||||
where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
|
||||
{
|
||||
if a_args.len() != b_args.len() {
|
||||
return Err(TypeError::ArgCount);
|
||||
@ -287,12 +286,12 @@ fn relate_arg_vecs<'a,'tcx:'a,R>(relation: &mut R,
|
||||
.collect()
|
||||
}
|
||||
|
||||
impl<'a,'tcx:'a> Relate<'a,'tcx> for ast::Unsafety {
|
||||
fn relate<R>(relation: &mut R,
|
||||
a: &ast::Unsafety,
|
||||
b: &ast::Unsafety)
|
||||
-> RelateResult<'tcx, ast::Unsafety>
|
||||
where R: TypeRelation<'a,'tcx>
|
||||
impl<'tcx> Relate<'tcx> for ast::Unsafety {
|
||||
fn relate<'a, 'gcx, R>(relation: &mut R,
|
||||
a: &ast::Unsafety,
|
||||
b: &ast::Unsafety)
|
||||
-> RelateResult<'tcx, ast::Unsafety>
|
||||
where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
|
||||
{
|
||||
if a != b {
|
||||
Err(TypeError::UnsafetyMismatch(expected_found(relation, a, b)))
|
||||
@ -302,12 +301,12 @@ impl<'a,'tcx:'a> Relate<'a,'tcx> for ast::Unsafety {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a,'tcx:'a> Relate<'a,'tcx> for abi::Abi {
|
||||
fn relate<R>(relation: &mut R,
|
||||
a: &abi::Abi,
|
||||
b: &abi::Abi)
|
||||
-> RelateResult<'tcx, abi::Abi>
|
||||
where R: TypeRelation<'a,'tcx>
|
||||
impl<'tcx> Relate<'tcx> for abi::Abi {
|
||||
fn relate<'a, 'gcx, R>(relation: &mut R,
|
||||
a: &abi::Abi,
|
||||
b: &abi::Abi)
|
||||
-> RelateResult<'tcx, abi::Abi>
|
||||
where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
|
||||
{
|
||||
if a == b {
|
||||
Ok(*a)
|
||||
@ -317,12 +316,12 @@ impl<'a,'tcx:'a> Relate<'a,'tcx> for abi::Abi {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a,'tcx:'a> Relate<'a,'tcx> for ty::ProjectionTy<'tcx> {
|
||||
fn relate<R>(relation: &mut R,
|
||||
a: &ty::ProjectionTy<'tcx>,
|
||||
b: &ty::ProjectionTy<'tcx>)
|
||||
-> RelateResult<'tcx, ty::ProjectionTy<'tcx>>
|
||||
where R: TypeRelation<'a,'tcx>
|
||||
impl<'tcx> Relate<'tcx> for ty::ProjectionTy<'tcx> {
|
||||
fn relate<'a, 'gcx, R>(relation: &mut R,
|
||||
a: &ty::ProjectionTy<'tcx>,
|
||||
b: &ty::ProjectionTy<'tcx>)
|
||||
-> RelateResult<'tcx, ty::ProjectionTy<'tcx>>
|
||||
where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
|
||||
{
|
||||
if a.item_name != b.item_name {
|
||||
Err(TypeError::ProjectionNameMismatched(
|
||||
@ -334,12 +333,12 @@ impl<'a,'tcx:'a> Relate<'a,'tcx> for ty::ProjectionTy<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a,'tcx:'a> Relate<'a,'tcx> for ty::ProjectionPredicate<'tcx> {
|
||||
fn relate<R>(relation: &mut R,
|
||||
a: &ty::ProjectionPredicate<'tcx>,
|
||||
b: &ty::ProjectionPredicate<'tcx>)
|
||||
-> RelateResult<'tcx, ty::ProjectionPredicate<'tcx>>
|
||||
where R: TypeRelation<'a,'tcx>
|
||||
impl<'tcx> Relate<'tcx> for ty::ProjectionPredicate<'tcx> {
|
||||
fn relate<'a, 'gcx, R>(relation: &mut R,
|
||||
a: &ty::ProjectionPredicate<'tcx>,
|
||||
b: &ty::ProjectionPredicate<'tcx>)
|
||||
-> RelateResult<'tcx, ty::ProjectionPredicate<'tcx>>
|
||||
where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
|
||||
{
|
||||
let projection_ty = relation.relate(&a.projection_ty, &b.projection_ty)?;
|
||||
let ty = relation.relate(&a.ty, &b.ty)?;
|
||||
@ -347,12 +346,12 @@ impl<'a,'tcx:'a> Relate<'a,'tcx> for ty::ProjectionPredicate<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a,'tcx:'a> Relate<'a,'tcx> for Vec<ty::PolyProjectionPredicate<'tcx>> {
|
||||
fn relate<R>(relation: &mut R,
|
||||
a: &Vec<ty::PolyProjectionPredicate<'tcx>>,
|
||||
b: &Vec<ty::PolyProjectionPredicate<'tcx>>)
|
||||
-> RelateResult<'tcx, Vec<ty::PolyProjectionPredicate<'tcx>>>
|
||||
where R: TypeRelation<'a,'tcx>
|
||||
impl<'tcx> Relate<'tcx> for Vec<ty::PolyProjectionPredicate<'tcx>> {
|
||||
fn relate<'a, 'gcx, R>(relation: &mut R,
|
||||
a: &Vec<ty::PolyProjectionPredicate<'tcx>>,
|
||||
b: &Vec<ty::PolyProjectionPredicate<'tcx>>)
|
||||
-> RelateResult<'tcx, Vec<ty::PolyProjectionPredicate<'tcx>>>
|
||||
where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
|
||||
{
|
||||
// To be compatible, `a` and `b` must be for precisely the
|
||||
// same set of traits and item names. We always require that
|
||||
@ -369,12 +368,12 @@ impl<'a,'tcx:'a> Relate<'a,'tcx> for Vec<ty::PolyProjectionPredicate<'tcx>> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a,'tcx:'a> Relate<'a,'tcx> for ty::ExistentialBounds<'tcx> {
|
||||
fn relate<R>(relation: &mut R,
|
||||
a: &ty::ExistentialBounds<'tcx>,
|
||||
b: &ty::ExistentialBounds<'tcx>)
|
||||
-> RelateResult<'tcx, ty::ExistentialBounds<'tcx>>
|
||||
where R: TypeRelation<'a,'tcx>
|
||||
impl<'tcx> Relate<'tcx> for ty::ExistentialBounds<'tcx> {
|
||||
fn relate<'a, 'gcx, R>(relation: &mut R,
|
||||
a: &ty::ExistentialBounds<'tcx>,
|
||||
b: &ty::ExistentialBounds<'tcx>)
|
||||
-> RelateResult<'tcx, ty::ExistentialBounds<'tcx>>
|
||||
where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
|
||||
{
|
||||
let r =
|
||||
relation.with_cause(
|
||||
@ -390,12 +389,12 @@ impl<'a,'tcx:'a> Relate<'a,'tcx> for ty::ExistentialBounds<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a,'tcx:'a> Relate<'a,'tcx> for ty::BuiltinBounds {
|
||||
fn relate<R>(relation: &mut R,
|
||||
a: &ty::BuiltinBounds,
|
||||
b: &ty::BuiltinBounds)
|
||||
-> RelateResult<'tcx, ty::BuiltinBounds>
|
||||
where R: TypeRelation<'a,'tcx>
|
||||
impl<'tcx> Relate<'tcx> for ty::BuiltinBounds {
|
||||
fn relate<'a, 'gcx, R>(relation: &mut R,
|
||||
a: &ty::BuiltinBounds,
|
||||
b: &ty::BuiltinBounds)
|
||||
-> RelateResult<'tcx, ty::BuiltinBounds>
|
||||
where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
|
||||
{
|
||||
// Two sets of builtin bounds are only relatable if they are
|
||||
// precisely the same (but see the coercion code).
|
||||
@ -407,12 +406,12 @@ impl<'a,'tcx:'a> Relate<'a,'tcx> for ty::BuiltinBounds {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a,'tcx:'a> Relate<'a,'tcx> for ty::TraitRef<'tcx> {
|
||||
fn relate<R>(relation: &mut R,
|
||||
a: &ty::TraitRef<'tcx>,
|
||||
b: &ty::TraitRef<'tcx>)
|
||||
-> RelateResult<'tcx, ty::TraitRef<'tcx>>
|
||||
where R: TypeRelation<'a,'tcx>
|
||||
impl<'tcx> Relate<'tcx> for ty::TraitRef<'tcx> {
|
||||
fn relate<'a, 'gcx, R>(relation: &mut R,
|
||||
a: &ty::TraitRef<'tcx>,
|
||||
b: &ty::TraitRef<'tcx>)
|
||||
-> RelateResult<'tcx, ty::TraitRef<'tcx>>
|
||||
where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
|
||||
{
|
||||
// Different traits cannot be related
|
||||
if a.def_id != b.def_id {
|
||||
@ -424,12 +423,12 @@ impl<'a,'tcx:'a> Relate<'a,'tcx> for ty::TraitRef<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a,'tcx:'a> Relate<'a,'tcx> for Ty<'tcx> {
|
||||
fn relate<R>(relation: &mut R,
|
||||
a: &Ty<'tcx>,
|
||||
b: &Ty<'tcx>)
|
||||
-> RelateResult<'tcx, Ty<'tcx>>
|
||||
where R: TypeRelation<'a,'tcx>
|
||||
impl<'tcx> Relate<'tcx> for Ty<'tcx> {
|
||||
fn relate<'a, 'gcx, R>(relation: &mut R,
|
||||
a: &Ty<'tcx>,
|
||||
b: &Ty<'tcx>)
|
||||
-> RelateResult<'tcx, Ty<'tcx>>
|
||||
where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
|
||||
{
|
||||
relation.tys(a, b)
|
||||
}
|
||||
@ -438,11 +437,11 @@ impl<'a,'tcx:'a> Relate<'a,'tcx> for Ty<'tcx> {
|
||||
/// The main "type relation" routine. Note that this does not handle
|
||||
/// inference artifacts, so you should filter those out before calling
|
||||
/// it.
|
||||
pub fn super_relate_tys<'a,'tcx:'a,R>(relation: &mut R,
|
||||
a: Ty<'tcx>,
|
||||
b: Ty<'tcx>)
|
||||
-> RelateResult<'tcx, Ty<'tcx>>
|
||||
where R: TypeRelation<'a,'tcx>
|
||||
pub fn super_relate_tys<'a, 'gcx, 'tcx, R>(relation: &mut R,
|
||||
a: Ty<'tcx>,
|
||||
b: Ty<'tcx>)
|
||||
-> RelateResult<'tcx, Ty<'tcx>>
|
||||
where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
|
||||
{
|
||||
let tcx = relation.tcx();
|
||||
let a_sty = &a.sty;
|
||||
@ -588,12 +587,12 @@ pub fn super_relate_tys<'a,'tcx:'a,R>(relation: &mut R,
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a,'tcx:'a> Relate<'a,'tcx> for ty::ClosureSubsts<'tcx> {
|
||||
fn relate<R>(relation: &mut R,
|
||||
a: &ty::ClosureSubsts<'tcx>,
|
||||
b: &ty::ClosureSubsts<'tcx>)
|
||||
-> RelateResult<'tcx, ty::ClosureSubsts<'tcx>>
|
||||
where R: TypeRelation<'a,'tcx>
|
||||
impl<'tcx> Relate<'tcx> for ty::ClosureSubsts<'tcx> {
|
||||
fn relate<'a, 'gcx, R>(relation: &mut R,
|
||||
a: &ty::ClosureSubsts<'tcx>,
|
||||
b: &ty::ClosureSubsts<'tcx>)
|
||||
-> RelateResult<'tcx, ty::ClosureSubsts<'tcx>>
|
||||
where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
|
||||
{
|
||||
let func_substs = relate_substs(relation, None, a.func_substs, b.func_substs)?;
|
||||
let upvar_tys = relation.relate_zip(&a.upvar_tys, &b.upvar_tys)?;
|
||||
@ -602,49 +601,45 @@ impl<'a,'tcx:'a> Relate<'a,'tcx> for ty::ClosureSubsts<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a,'tcx:'a> Relate<'a,'tcx> for Substs<'tcx> {
|
||||
fn relate<R>(relation: &mut R,
|
||||
a: &Substs<'tcx>,
|
||||
b: &Substs<'tcx>)
|
||||
-> RelateResult<'tcx, Substs<'tcx>>
|
||||
where R: TypeRelation<'a,'tcx>
|
||||
impl<'tcx> Relate<'tcx> for Substs<'tcx> {
|
||||
fn relate<'a, 'gcx, R>(relation: &mut R,
|
||||
a: &Substs<'tcx>,
|
||||
b: &Substs<'tcx>)
|
||||
-> RelateResult<'tcx, Substs<'tcx>>
|
||||
where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
|
||||
{
|
||||
relate_substs(relation, None, a, b)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a,'tcx:'a> Relate<'a,'tcx> for ty::Region {
|
||||
fn relate<R>(relation: &mut R,
|
||||
a: &ty::Region,
|
||||
b: &ty::Region)
|
||||
-> RelateResult<'tcx, ty::Region>
|
||||
where R: TypeRelation<'a,'tcx>
|
||||
impl<'tcx> Relate<'tcx> for ty::Region {
|
||||
fn relate<'a, 'gcx, R>(relation: &mut R,
|
||||
a: &ty::Region,
|
||||
b: &ty::Region)
|
||||
-> RelateResult<'tcx, ty::Region>
|
||||
where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
|
||||
{
|
||||
relation.regions(*a, *b)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a,'tcx:'a,T> Relate<'a,'tcx> for ty::Binder<T>
|
||||
where T: Relate<'a,'tcx>
|
||||
{
|
||||
fn relate<R>(relation: &mut R,
|
||||
a: &ty::Binder<T>,
|
||||
b: &ty::Binder<T>)
|
||||
-> RelateResult<'tcx, ty::Binder<T>>
|
||||
where R: TypeRelation<'a,'tcx>
|
||||
impl<'tcx, T: Relate<'tcx>> Relate<'tcx> for ty::Binder<T> {
|
||||
fn relate<'a, 'gcx, R>(relation: &mut R,
|
||||
a: &ty::Binder<T>,
|
||||
b: &ty::Binder<T>)
|
||||
-> RelateResult<'tcx, ty::Binder<T>>
|
||||
where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
|
||||
{
|
||||
relation.binders(a, b)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a,'tcx:'a,T> Relate<'a,'tcx> for Rc<T>
|
||||
where T: Relate<'a,'tcx>
|
||||
{
|
||||
fn relate<R>(relation: &mut R,
|
||||
a: &Rc<T>,
|
||||
b: &Rc<T>)
|
||||
-> RelateResult<'tcx, Rc<T>>
|
||||
where R: TypeRelation<'a,'tcx>
|
||||
impl<'tcx, T: Relate<'tcx>> Relate<'tcx> for Rc<T> {
|
||||
fn relate<'a, 'gcx, R>(relation: &mut R,
|
||||
a: &Rc<T>,
|
||||
b: &Rc<T>)
|
||||
-> RelateResult<'tcx, Rc<T>>
|
||||
where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
|
||||
{
|
||||
let a: &T = a;
|
||||
let b: &T = b;
|
||||
@ -652,14 +647,12 @@ impl<'a,'tcx:'a,T> Relate<'a,'tcx> for Rc<T>
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a,'tcx:'a,T> Relate<'a,'tcx> for Box<T>
|
||||
where T: Relate<'a,'tcx>
|
||||
{
|
||||
fn relate<R>(relation: &mut R,
|
||||
a: &Box<T>,
|
||||
b: &Box<T>)
|
||||
-> RelateResult<'tcx, Box<T>>
|
||||
where R: TypeRelation<'a,'tcx>
|
||||
impl<'tcx, T: Relate<'tcx>> Relate<'tcx> for Box<T> {
|
||||
fn relate<'a, 'gcx, R>(relation: &mut R,
|
||||
a: &Box<T>,
|
||||
b: &Box<T>)
|
||||
-> RelateResult<'tcx, Box<T>>
|
||||
where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a
|
||||
{
|
||||
let a: &T = a;
|
||||
let b: &T = b;
|
||||
@ -670,11 +663,11 @@ impl<'a,'tcx:'a,T> Relate<'a,'tcx> for Box<T>
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Error handling
|
||||
|
||||
pub fn expected_found<'a,'tcx:'a,R,T>(relation: &mut R,
|
||||
a: &T,
|
||||
b: &T)
|
||||
-> ExpectedFound<T>
|
||||
where R: TypeRelation<'a,'tcx>, T: Clone
|
||||
pub fn expected_found<'a, 'gcx, 'tcx, R, T>(relation: &mut R,
|
||||
a: &T,
|
||||
b: &T)
|
||||
-> ExpectedFound<T>
|
||||
where R: TypeRelation<'a, 'gcx, 'tcx>, T: Clone, 'gcx: 'a+'tcx, 'tcx: 'a
|
||||
{
|
||||
expected_found_bool(relation.a_is_expected(), a, b)
|
||||
}
|
||||
|
@ -8,8 +8,8 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use infer::type_variable;
|
||||
use ty::subst::{self, VecPerParamSpace};
|
||||
use traits;
|
||||
use ty::{self, Lift, TraitRef, Ty, TyCtxt};
|
||||
use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
|
||||
|
||||
@ -24,14 +24,31 @@ use hir;
|
||||
|
||||
impl<'tcx, A: Lift<'tcx>, B: Lift<'tcx>> Lift<'tcx> for (A, B) {
|
||||
type Lifted = (A::Lifted, B::Lifted);
|
||||
fn lift_to_tcx<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Option<Self::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).map(|b| (a, b)))
|
||||
}
|
||||
}
|
||||
|
||||
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> {
|
||||
self.as_ref().map(|x| tcx.lift(x))
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for [T] {
|
||||
type Lifted = Vec<T::Lifted>;
|
||||
fn lift_to_tcx<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Option<Self::Lifted> {
|
||||
fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, '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());
|
||||
@ -55,7 +72,7 @@ impl<'tcx> Lift<'tcx> for ty::Region {
|
||||
|
||||
impl<'a, 'tcx> Lift<'tcx> for TraitRef<'a> {
|
||||
type Lifted = TraitRef<'tcx>;
|
||||
fn lift_to_tcx<'b>(&self, tcx: TyCtxt<'b, 'tcx, 'tcx>) -> Option<TraitRef<'tcx>> {
|
||||
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<TraitRef<'tcx>> {
|
||||
tcx.lift(&self.substs).map(|substs| TraitRef {
|
||||
def_id: self.def_id,
|
||||
substs: substs
|
||||
@ -65,7 +82,8 @@ impl<'a, 'tcx> Lift<'tcx> for TraitRef<'a> {
|
||||
|
||||
impl<'a, 'tcx> Lift<'tcx> for ty::TraitPredicate<'a> {
|
||||
type Lifted = ty::TraitPredicate<'tcx>;
|
||||
fn lift_to_tcx<'b>(&self, tcx: TyCtxt<'b, 'tcx, 'tcx>) -> Option<ty::TraitPredicate<'tcx>> {
|
||||
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>)
|
||||
-> Option<ty::TraitPredicate<'tcx>> {
|
||||
tcx.lift(&self.trait_ref).map(|trait_ref| ty::TraitPredicate {
|
||||
trait_ref: trait_ref
|
||||
})
|
||||
@ -74,22 +92,23 @@ impl<'a, 'tcx> Lift<'tcx> for ty::TraitPredicate<'a> {
|
||||
|
||||
impl<'a, 'tcx> Lift<'tcx> for ty::EquatePredicate<'a> {
|
||||
type Lifted = ty::EquatePredicate<'tcx>;
|
||||
fn lift_to_tcx<'b>(&self, tcx: TyCtxt<'b, 'tcx, 'tcx>) -> Option<ty::EquatePredicate<'tcx>> {
|
||||
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>)
|
||||
-> Option<ty::EquatePredicate<'tcx>> {
|
||||
tcx.lift(&(self.0, self.1)).map(|(a, b)| ty::EquatePredicate(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>;
|
||||
fn lift_to_tcx<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Option<Self::Lifted> {
|
||||
fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
||||
tcx.lift(&(self.0, self.1)).map(|(a, b)| ty::OutlivesPredicate(a, b))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Lift<'tcx> for ty::ProjectionPredicate<'a> {
|
||||
type Lifted = ty::ProjectionPredicate<'tcx>;
|
||||
fn lift_to_tcx<'b>(&self, tcx: TyCtxt<'b, 'tcx, 'tcx>)
|
||||
-> Option<ty::ProjectionPredicate<'tcx>> {
|
||||
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>)
|
||||
-> Option<ty::ProjectionPredicate<'tcx>> {
|
||||
tcx.lift(&(self.projection_ty.trait_ref, self.ty)).map(|(trait_ref, ty)| {
|
||||
ty::ProjectionPredicate {
|
||||
projection_ty: ty::ProjectionTy {
|
||||
@ -104,11 +123,82 @@ impl<'a, 'tcx> Lift<'tcx> for ty::ProjectionPredicate<'a> {
|
||||
|
||||
impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for ty::Binder<T> {
|
||||
type Lifted = ty::Binder<T::Lifted>;
|
||||
fn lift_to_tcx<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Option<Self::Lifted> {
|
||||
fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
||||
tcx.lift(&self.0).map(|x| ty::Binder(x))
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
expected: expected,
|
||||
found: found
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Lift<'tcx> for type_variable::Default<'a> {
|
||||
type Lifted = type_variable::Default<'tcx>;
|
||||
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
||||
tcx.lift(&self.ty).map(|ty| {
|
||||
type_variable::Default {
|
||||
ty: ty,
|
||||
origin_span: self.origin_span,
|
||||
def_id: self.def_id
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
BoxMutability => BoxMutability,
|
||||
PtrMutability => PtrMutability,
|
||||
RefMutability => RefMutability,
|
||||
VecMutability => VecMutability,
|
||||
TupleSize(x) => TupleSize(x),
|
||||
FixedArraySize(x) => FixedArraySize(x),
|
||||
TyParamSize(x) => TyParamSize(x),
|
||||
ArgCount => ArgCount,
|
||||
RegionsDoesNotOutlive(a, b) => RegionsDoesNotOutlive(a, b),
|
||||
RegionsNotSame(a, b) => RegionsNotSame(a, b),
|
||||
RegionsNoOverlap(a, b) => RegionsNoOverlap(a, b),
|
||||
RegionsInsufficientlyPolymorphic(a, b) => {
|
||||
RegionsInsufficientlyPolymorphic(a, b)
|
||||
}
|
||||
RegionsOverlyPolymorphic(a, b) => RegionsOverlyPolymorphic(a, b),
|
||||
IntegerAsChar => IntegerAsChar,
|
||||
IntMismatch(x) => IntMismatch(x),
|
||||
FloatMismatch(x) => FloatMismatch(x),
|
||||
Traits(x) => Traits(x),
|
||||
BuiltinBoundsMismatch(x) => BuiltinBoundsMismatch(x),
|
||||
VariadicMismatch(x) => VariadicMismatch(x),
|
||||
CyclicTy => CyclicTy,
|
||||
ConvergenceMismatch(x) => ConvergenceMismatch(x),
|
||||
ProjectionNameMismatched(x) => ProjectionNameMismatched(x),
|
||||
ProjectionBoundsLength(x) => ProjectionBoundsLength(x),
|
||||
|
||||
Sorts(ref x) => return tcx.lift(x).map(Sorts),
|
||||
TyParamDefaultMismatch(ref x) => {
|
||||
return tcx.lift(x).map(TyParamDefaultMismatch)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// TypeFoldable implementations.
|
||||
//
|
||||
@ -124,7 +214,7 @@ macro_rules! CopyImpls {
|
||||
($($ty:ty),+) => {
|
||||
$(
|
||||
impl<'tcx> TypeFoldable<'tcx> for $ty {
|
||||
fn super_fold_with<F:TypeFolder<'tcx>>(&self, _: &mut F) -> $ty {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, _: &mut F) -> $ty {
|
||||
*self
|
||||
}
|
||||
|
||||
@ -139,7 +229,7 @@ macro_rules! CopyImpls {
|
||||
CopyImpls! { (), hir::Unsafety, abi::Abi }
|
||||
|
||||
impl<'tcx, T:TypeFoldable<'tcx>, U:TypeFoldable<'tcx>> TypeFoldable<'tcx> for (T, U) {
|
||||
fn super_fold_with<F:TypeFolder<'tcx>>(&self, folder: &mut F) -> (T, U) {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> (T, U) {
|
||||
(self.0.fold_with(folder), self.1.fold_with(folder))
|
||||
}
|
||||
|
||||
@ -149,7 +239,7 @@ impl<'tcx, T:TypeFoldable<'tcx>, U:TypeFoldable<'tcx>> TypeFoldable<'tcx> for (T
|
||||
}
|
||||
|
||||
impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Option<T> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
self.as_ref().map(|t| t.fold_with(folder))
|
||||
}
|
||||
|
||||
@ -159,7 +249,7 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Option<T> {
|
||||
}
|
||||
|
||||
impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Rc<T> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
Rc::new((**self).fold_with(folder))
|
||||
}
|
||||
|
||||
@ -169,7 +259,7 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Rc<T> {
|
||||
}
|
||||
|
||||
impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Box<T> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
let content: T = (**self).fold_with(folder);
|
||||
box content
|
||||
}
|
||||
@ -180,7 +270,7 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Box<T> {
|
||||
}
|
||||
|
||||
impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Vec<T> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
self.iter().map(|t| t.fold_with(folder)).collect()
|
||||
}
|
||||
|
||||
@ -190,11 +280,11 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Vec<T> {
|
||||
}
|
||||
|
||||
impl<'tcx, T:TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::Binder<T> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
ty::Binder(self.0.fold_with(folder))
|
||||
}
|
||||
|
||||
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
folder.fold_binder(self)
|
||||
}
|
||||
|
||||
@ -208,7 +298,7 @@ impl<'tcx, T:TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::Binder<T> {
|
||||
}
|
||||
|
||||
impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for P<[T]> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
self.iter().map(|t| t.fold_with(folder)).collect()
|
||||
}
|
||||
|
||||
@ -218,7 +308,7 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for P<[T]> {
|
||||
}
|
||||
|
||||
impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for VecPerParamSpace<T> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
self.map(|elem| elem.fold_with(folder))
|
||||
}
|
||||
|
||||
@ -228,7 +318,7 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for VecPerParamSpace<T> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for ty::TraitTy<'tcx> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
ty::TraitTy {
|
||||
principal: self.principal.fold_with(folder),
|
||||
bounds: self.bounds.fold_with(folder),
|
||||
@ -241,7 +331,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::TraitTy<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
let sty = match self.sty {
|
||||
ty::TyBox(typ) => ty::TyBox(typ.fold_with(folder)),
|
||||
ty::TyRawPtr(ref tm) => ty::TyRawPtr(tm.fold_with(folder)),
|
||||
@ -283,7 +373,7 @@ impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
|
||||
folder.tcx().mk_ty(sty)
|
||||
}
|
||||
|
||||
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
folder.fold_ty(*self)
|
||||
}
|
||||
|
||||
@ -316,13 +406,13 @@ impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for ty::BareFnTy<'tcx> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
ty::BareFnTy { sig: self.sig.fold_with(folder),
|
||||
abi: self.abi,
|
||||
unsafety: self.unsafety }
|
||||
}
|
||||
|
||||
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
folder.fold_bare_fn_ty(self)
|
||||
}
|
||||
|
||||
@ -332,7 +422,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::BareFnTy<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for ty::ClosureTy<'tcx> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
ty::ClosureTy {
|
||||
sig: self.sig.fold_with(folder),
|
||||
unsafety: self.unsafety,
|
||||
@ -340,7 +430,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::ClosureTy<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
folder.fold_closure_ty(self)
|
||||
}
|
||||
|
||||
@ -350,11 +440,11 @@ impl<'tcx> TypeFoldable<'tcx> for ty::ClosureTy<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for ty::TypeAndMut<'tcx> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
ty::TypeAndMut { ty: self.ty.fold_with(folder), mutbl: self.mutbl }
|
||||
}
|
||||
|
||||
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
folder.fold_mt(self)
|
||||
}
|
||||
|
||||
@ -364,14 +454,14 @@ impl<'tcx> TypeFoldable<'tcx> for ty::TypeAndMut<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for ty::FnOutput<'tcx> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
match *self {
|
||||
ty::FnConverging(ref ty) => ty::FnConverging(ty.fold_with(folder)),
|
||||
ty::FnDiverging => ty::FnDiverging
|
||||
}
|
||||
}
|
||||
|
||||
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
folder.fold_output(self)
|
||||
}
|
||||
|
||||
@ -384,13 +474,13 @@ impl<'tcx> TypeFoldable<'tcx> for ty::FnOutput<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for ty::FnSig<'tcx> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
ty::FnSig { inputs: self.inputs.fold_with(folder),
|
||||
output: self.output.fold_with(folder),
|
||||
variadic: self.variadic }
|
||||
}
|
||||
|
||||
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
folder.fold_fn_sig(self)
|
||||
}
|
||||
|
||||
@ -400,7 +490,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::FnSig<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for ty::TraitRef<'tcx> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
let substs = self.substs.fold_with(folder);
|
||||
ty::TraitRef {
|
||||
def_id: self.def_id,
|
||||
@ -408,7 +498,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::TraitRef<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
folder.fold_trait_ref(self)
|
||||
}
|
||||
|
||||
@ -418,7 +508,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::TraitRef<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for ty::ImplHeader<'tcx> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
ty::ImplHeader {
|
||||
impl_def_id: self.impl_def_id,
|
||||
self_ty: self.self_ty.fold_with(folder),
|
||||
@ -427,7 +517,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::ImplHeader<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
folder.fold_impl_header(self)
|
||||
}
|
||||
|
||||
@ -439,11 +529,11 @@ impl<'tcx> TypeFoldable<'tcx> for ty::ImplHeader<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for ty::Region {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, _folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, _folder: &mut F) -> Self {
|
||||
*self
|
||||
}
|
||||
|
||||
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
folder.fold_region(*self)
|
||||
}
|
||||
|
||||
@ -457,12 +547,12 @@ impl<'tcx> TypeFoldable<'tcx> for ty::Region {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for subst::Substs<'tcx> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
subst::Substs { regions: self.regions.fold_with(folder),
|
||||
types: self.types.fold_with(folder) }
|
||||
}
|
||||
|
||||
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
folder.fold_substs(self)
|
||||
}
|
||||
|
||||
@ -472,7 +562,7 @@ impl<'tcx> TypeFoldable<'tcx> for subst::Substs<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for ty::ClosureSubsts<'tcx> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
let func_substs = self.func_substs.fold_with(folder);
|
||||
ty::ClosureSubsts {
|
||||
func_substs: folder.tcx().mk_substs(func_substs),
|
||||
@ -486,7 +576,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::ClosureSubsts<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for ty::ItemSubsts<'tcx> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
ty::ItemSubsts {
|
||||
substs: self.substs.fold_with(folder),
|
||||
}
|
||||
@ -498,7 +588,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::ItemSubsts<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for ty::adjustment::AutoRef<'tcx> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
match *self {
|
||||
ty::adjustment::AutoPtr(r, m) => {
|
||||
let r = r.fold_with(folder);
|
||||
@ -508,7 +598,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::adjustment::AutoRef<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
folder.fold_autoref(self)
|
||||
}
|
||||
|
||||
@ -521,7 +611,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::adjustment::AutoRef<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for ty::BuiltinBounds {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, _folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, _folder: &mut F) -> Self {
|
||||
*self
|
||||
}
|
||||
|
||||
@ -531,7 +621,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::BuiltinBounds {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for ty::ExistentialBounds<'tcx> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
ty::ExistentialBounds {
|
||||
region_bound: self.region_bound.fold_with(folder),
|
||||
builtin_bounds: self.builtin_bounds,
|
||||
@ -539,7 +629,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::ExistentialBounds<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
folder.fold_existential_bounds(self)
|
||||
}
|
||||
|
||||
@ -549,7 +639,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::ExistentialBounds<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for ty::TypeParameterDef<'tcx> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
ty::TypeParameterDef {
|
||||
name: self.name,
|
||||
def_id: self.def_id,
|
||||
@ -568,7 +658,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::TypeParameterDef<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for ty::ObjectLifetimeDefault {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
match *self {
|
||||
ty::ObjectLifetimeDefault::Ambiguous =>
|
||||
ty::ObjectLifetimeDefault::Ambiguous,
|
||||
@ -590,7 +680,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::ObjectLifetimeDefault {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for ty::RegionParameterDef {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
ty::RegionParameterDef {
|
||||
name: self.name,
|
||||
def_id: self.def_id,
|
||||
@ -606,7 +696,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::RegionParameterDef {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for ty::Generics<'tcx> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
ty::Generics {
|
||||
types: self.types.fold_with(folder),
|
||||
regions: self.regions.fold_with(folder),
|
||||
@ -619,7 +709,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::Generics<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for ty::GenericPredicates<'tcx> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
ty::GenericPredicates {
|
||||
predicates: self.predicates.fold_with(folder),
|
||||
}
|
||||
@ -631,7 +721,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::GenericPredicates<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
match *self {
|
||||
ty::Predicate::Trait(ref a) =>
|
||||
ty::Predicate::Trait(a.fold_with(folder)),
|
||||
@ -670,7 +760,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for ty::ProjectionPredicate<'tcx> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
ty::ProjectionPredicate {
|
||||
projection_ty: self.projection_ty.fold_with(folder),
|
||||
ty: self.ty.fold_with(folder),
|
||||
@ -683,7 +773,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::ProjectionPredicate<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for ty::ProjectionTy<'tcx> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
ty::ProjectionTy {
|
||||
trait_ref: self.trait_ref.fold_with(folder),
|
||||
item_name: self.item_name,
|
||||
@ -696,7 +786,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::ProjectionTy<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for ty::InstantiatedPredicates<'tcx> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
ty::InstantiatedPredicates {
|
||||
predicates: self.predicates.fold_with(folder),
|
||||
}
|
||||
@ -708,7 +798,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::InstantiatedPredicates<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for ty::EquatePredicate<'tcx> {
|
||||
fn super_fold_with<F:TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
ty::EquatePredicate(self.0.fold_with(folder),
|
||||
self.1.fold_with(folder))
|
||||
}
|
||||
@ -719,7 +809,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::EquatePredicate<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for ty::TraitPredicate<'tcx> {
|
||||
fn super_fold_with<F:TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
ty::TraitPredicate {
|
||||
trait_ref: self.trait_ref.fold_with(folder)
|
||||
}
|
||||
@ -734,7 +824,7 @@ impl<'tcx,T,U> TypeFoldable<'tcx> for ty::OutlivesPredicate<T,U>
|
||||
where T : TypeFoldable<'tcx>,
|
||||
U : TypeFoldable<'tcx>,
|
||||
{
|
||||
fn super_fold_with<F:TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
ty::OutlivesPredicate(self.0.fold_with(folder),
|
||||
self.1.fold_with(folder))
|
||||
}
|
||||
@ -745,7 +835,7 @@ impl<'tcx,T,U> TypeFoldable<'tcx> for ty::OutlivesPredicate<T,U>
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for ty::ClosureUpvar<'tcx> {
|
||||
fn super_fold_with<F:TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
ty::ClosureUpvar {
|
||||
def: self.def,
|
||||
span: self.span,
|
||||
@ -759,13 +849,11 @@ impl<'tcx> TypeFoldable<'tcx> for ty::ClosureUpvar<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for ty::ParameterEnvironment<'tcx> {
|
||||
fn super_fold_with<F:TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
ty::ParameterEnvironment {
|
||||
free_substs: self.free_substs.fold_with(folder),
|
||||
implicit_region_bound: self.implicit_region_bound.fold_with(folder),
|
||||
caller_bounds: self.caller_bounds.fold_with(folder),
|
||||
selection_cache: traits::SelectionCache::new(),
|
||||
evaluation_cache: traits::EvaluationCache::new(),
|
||||
free_id_outlive: self.free_id_outlive,
|
||||
}
|
||||
}
|
||||
@ -778,7 +866,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::ParameterEnvironment<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for ty::TypeScheme<'tcx> {
|
||||
fn super_fold_with<F:TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
ty::TypeScheme {
|
||||
generics: self.generics.fold_with(folder),
|
||||
ty: self.ty.fold_with(folder),
|
||||
|
@ -270,7 +270,7 @@ pub struct TraitTy<'tcx> {
|
||||
pub bounds: ExistentialBounds<'tcx>,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> TraitTy<'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> TraitTy<'tcx> {
|
||||
pub fn principal_def_id(&self) -> DefId {
|
||||
self.principal.0.def_id
|
||||
}
|
||||
@ -279,7 +279,7 @@ impl<'a, 'tcx> TraitTy<'tcx> {
|
||||
/// we convert the principal trait-ref into a normal trait-ref,
|
||||
/// you must give *some* self-type. A common choice is `mk_err()`
|
||||
/// or some skolemized type.
|
||||
pub fn principal_trait_ref_with_self_ty(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
pub fn principal_trait_ref_with_self_ty(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
self_ty: Ty<'tcx>)
|
||||
-> ty::PolyTraitRef<'tcx>
|
||||
{
|
||||
@ -292,7 +292,7 @@ impl<'a, 'tcx> TraitTy<'tcx> {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn projection_bounds_with_self_ty(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
pub fn projection_bounds_with_self_ty(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
self_ty: Ty<'tcx>)
|
||||
-> Vec<ty::PolyProjectionPredicate<'tcx>>
|
||||
{
|
||||
@ -521,7 +521,7 @@ pub struct ParamTy {
|
||||
pub name: Name,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> ParamTy {
|
||||
impl<'a, 'gcx, 'tcx> ParamTy {
|
||||
pub fn new(space: subst::ParamSpace,
|
||||
index: u32,
|
||||
name: Name)
|
||||
@ -537,7 +537,7 @@ impl<'a, 'tcx> ParamTy {
|
||||
ParamTy::new(def.space, def.index, def.name)
|
||||
}
|
||||
|
||||
pub fn to_ty(self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Ty<'tcx> {
|
||||
pub fn to_ty(self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> {
|
||||
tcx.mk_param(self.space, self.idx, self.name)
|
||||
}
|
||||
|
||||
@ -762,7 +762,7 @@ impl<'tcx> ExistentialBounds<'tcx> {
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
|
||||
pub struct BuiltinBounds(EnumSet<BuiltinBound>);
|
||||
|
||||
impl<'a, 'tcx> BuiltinBounds {
|
||||
impl<'a, 'gcx, 'tcx> BuiltinBounds {
|
||||
pub fn empty() -> BuiltinBounds {
|
||||
BuiltinBounds(EnumSet::new())
|
||||
}
|
||||
@ -771,7 +771,7 @@ impl<'a, 'tcx> BuiltinBounds {
|
||||
self.into_iter()
|
||||
}
|
||||
|
||||
pub fn to_predicates(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
pub fn to_predicates(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
self_ty: Ty<'tcx>)
|
||||
-> Vec<ty::Predicate<'tcx>> {
|
||||
self.iter().filter_map(|builtin_bound|
|
||||
@ -819,7 +819,7 @@ impl CLike for BuiltinBound {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
pub fn try_add_builtin_trait(self,
|
||||
trait_def_id: DefId,
|
||||
builtin_bounds: &mut EnumSet<BuiltinBound>)
|
||||
@ -884,7 +884,7 @@ impl Region {
|
||||
}
|
||||
|
||||
// Type utilities
|
||||
impl<'a, 'tcx> TyS<'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> TyS<'tcx> {
|
||||
pub fn as_opt_param_ty(&self) -> Option<ty::ParamTy> {
|
||||
match self.sty {
|
||||
ty::TyParam(ref d) => Some(d.clone()),
|
||||
@ -971,7 +971,7 @@ impl<'a, 'tcx> TyS<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn sequence_element_type(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Ty<'tcx> {
|
||||
pub fn sequence_element_type(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> {
|
||||
match self.sty {
|
||||
TyArray(ty, _) | TySlice(ty) => ty,
|
||||
TyStr => tcx.mk_mach_uint(ast::UintTy::U8),
|
||||
@ -979,7 +979,7 @@ impl<'a, 'tcx> TyS<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn simd_type(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Ty<'tcx> {
|
||||
pub fn simd_type(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> {
|
||||
match self.sty {
|
||||
TyStruct(def, substs) => {
|
||||
def.struct_variant().fields[0].ty(tcx, substs)
|
||||
|
@ -36,7 +36,7 @@ pub struct Substs<'tcx> {
|
||||
pub regions: VecPerParamSpace<ty::Region>,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Substs<'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> Substs<'tcx> {
|
||||
pub fn new(t: VecPerParamSpace<Ty<'tcx>>,
|
||||
r: VecPerParamSpace<ty::Region>)
|
||||
-> Substs<'tcx>
|
||||
@ -122,7 +122,7 @@ impl<'a, 'tcx> Substs<'tcx> {
|
||||
}
|
||||
|
||||
/// Creates a trait-ref out of this substs, ignoring the FnSpace substs
|
||||
pub fn to_trait_ref(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, trait_id: DefId)
|
||||
pub fn to_trait_ref(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, trait_id: DefId)
|
||||
-> ty::TraitRef<'tcx> {
|
||||
let Substs { mut types, mut regions } = self.clone();
|
||||
types.truncate(FnSpace, 0);
|
||||
@ -532,21 +532,22 @@ impl<'a,T> IntoIterator for &'a VecPerParamSpace<T> {
|
||||
// there is more information available (for better errors).
|
||||
|
||||
pub trait Subst<'tcx> : Sized {
|
||||
fn subst<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, substs: &Substs<'tcx>) -> Self {
|
||||
fn subst<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
substs: &Substs<'tcx>) -> Self {
|
||||
self.subst_spanned(tcx, substs, None)
|
||||
}
|
||||
|
||||
fn subst_spanned<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
substs: &Substs<'tcx>,
|
||||
span: Option<Span>)
|
||||
-> Self;
|
||||
fn subst_spanned<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
substs: &Substs<'tcx>,
|
||||
span: Option<Span>)
|
||||
-> Self;
|
||||
}
|
||||
|
||||
impl<'tcx, T:TypeFoldable<'tcx>> Subst<'tcx> for T {
|
||||
fn subst_spanned<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
substs: &Substs<'tcx>,
|
||||
span: Option<Span>)
|
||||
-> T
|
||||
fn subst_spanned<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
substs: &Substs<'tcx>,
|
||||
span: Option<Span>)
|
||||
-> T
|
||||
{
|
||||
let mut folder = SubstFolder { tcx: tcx,
|
||||
substs: substs,
|
||||
@ -561,8 +562,8 @@ impl<'tcx, T:TypeFoldable<'tcx>> Subst<'tcx> for T {
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// The actual substitution engine itself is a type folder.
|
||||
|
||||
struct SubstFolder<'a, 'tcx: 'a> {
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
struct SubstFolder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
|
||||
tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
substs: &'a Substs<'tcx>,
|
||||
|
||||
// The location for which the substitution is performed, if available.
|
||||
@ -578,8 +579,8 @@ struct SubstFolder<'a, 'tcx: 'a> {
|
||||
region_binders_passed: u32,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> TypeFolder<'tcx> for SubstFolder<'a, 'tcx> {
|
||||
fn tcx<'b>(&'b self) -> TyCtxt<'b, 'tcx, 'tcx> { self.tcx }
|
||||
impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for SubstFolder<'a, 'gcx, 'tcx> {
|
||||
fn tcx<'b>(&'b self) -> TyCtxt<'b, 'gcx, 'tcx> { self.tcx }
|
||||
|
||||
fn fold_binder<T: TypeFoldable<'tcx>>(&mut self, t: &ty::Binder<T>) -> ty::Binder<T> {
|
||||
self.region_binders_passed += 1;
|
||||
@ -649,7 +650,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for SubstFolder<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a,'tcx> SubstFolder<'a,'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> SubstFolder<'a, 'gcx, 'tcx> {
|
||||
fn ty_for_param(&self, p: ty::ParamTy, source_ty: Ty<'tcx>) -> Ty<'tcx> {
|
||||
// Look up the type in the substitutions. It really should be in there.
|
||||
let opt_ty = self.substs.types.opt_get(p.space, p.idx as usize);
|
||||
|
@ -73,7 +73,7 @@ pub struct TraitDef<'tcx> {
|
||||
pub flags: Cell<TraitFlags>
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> TraitDef<'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> TraitDef<'tcx> {
|
||||
pub fn new(unsafety: hir::Unsafety,
|
||||
paren_sugar: bool,
|
||||
generics: ty::Generics<'tcx>,
|
||||
@ -117,18 +117,18 @@ impl<'a, 'tcx> TraitDef<'tcx> {
|
||||
);
|
||||
}
|
||||
|
||||
fn write_trait_impls(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) {
|
||||
fn write_trait_impls(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) {
|
||||
tcx.dep_graph.write(DepNode::TraitImpls(self.trait_ref.def_id));
|
||||
}
|
||||
|
||||
fn read_trait_impls(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) {
|
||||
fn read_trait_impls(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) {
|
||||
tcx.dep_graph.read(DepNode::TraitImpls(self.trait_ref.def_id));
|
||||
}
|
||||
|
||||
/// Records a basic trait-to-implementation mapping.
|
||||
///
|
||||
/// Returns `true` iff the impl has not previously been recorded.
|
||||
fn record_impl(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
fn record_impl(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
impl_def_id: DefId,
|
||||
impl_trait_ref: TraitRef<'tcx>)
|
||||
-> bool {
|
||||
@ -163,7 +163,7 @@ impl<'a, 'tcx> TraitDef<'tcx> {
|
||||
}
|
||||
|
||||
/// Records a trait-to-implementation mapping for a crate-local impl.
|
||||
pub fn record_local_impl(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
pub fn record_local_impl(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
impl_def_id: DefId,
|
||||
impl_trait_ref: TraitRef<'tcx>) {
|
||||
assert!(impl_def_id.is_local());
|
||||
@ -176,7 +176,7 @@ impl<'a, 'tcx> TraitDef<'tcx> {
|
||||
/// The `parent_impl` is the immediately-less-specialized impl, or the
|
||||
/// trait's def ID if the impl is not a specialization -- information that
|
||||
/// should be pulled from the metadata.
|
||||
pub fn record_remote_impl(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
pub fn record_remote_impl(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
impl_def_id: DefId,
|
||||
impl_trait_ref: TraitRef<'tcx>,
|
||||
parent_impl: DefId) {
|
||||
@ -195,7 +195,7 @@ impl<'a, 'tcx> TraitDef<'tcx> {
|
||||
/// overlap information if the impl overlaps but does not specialize an
|
||||
/// existing impl.
|
||||
pub fn add_impl_for_specialization(&self,
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
impl_def_id: DefId)
|
||||
-> Result<(), traits::OverlapError> {
|
||||
assert!(impl_def_id.is_local());
|
||||
@ -208,7 +208,7 @@ impl<'a, 'tcx> TraitDef<'tcx> {
|
||||
specialization_graph::ancestors(self, of_impl)
|
||||
}
|
||||
|
||||
pub fn for_each_impl<F: FnMut(DefId)>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, mut f: F) {
|
||||
pub fn for_each_impl<F: FnMut(DefId)>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, mut f: F) {
|
||||
self.read_trait_impls(tcx);
|
||||
tcx.populate_implementations_for_trait_if_necessary(self.trait_ref.def_id);
|
||||
|
||||
@ -226,7 +226,7 @@ impl<'a, 'tcx> TraitDef<'tcx> {
|
||||
/// Iterate over every impl that could possibly match the
|
||||
/// self-type `self_ty`.
|
||||
pub fn for_each_relevant_impl<F: FnMut(DefId)>(&self,
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
self_ty: Ty<'tcx>,
|
||||
mut f: F)
|
||||
{
|
||||
|
@ -171,7 +171,7 @@ impl<'tcx> ParameterEnvironment<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
pub fn pat_contains_ref_binding(self, pat: &hir::Pat) -> Option<hir::Mutability> {
|
||||
pat_util::pat_contains_ref_binding(&self.def_map, pat)
|
||||
}
|
||||
@ -338,8 +338,9 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
helper(self, ty, svh, &mut state);
|
||||
return state.finish();
|
||||
|
||||
fn helper<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>, svh: &Svh,
|
||||
state: &mut SipHasher) {
|
||||
fn helper<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
ty: Ty<'tcx>, svh: &Svh,
|
||||
state: &mut SipHasher) {
|
||||
macro_rules! byte { ($b:expr) => { ($b as u8).hash(state) } }
|
||||
macro_rules! hash { ($e:expr) => { $e.hash(state) } }
|
||||
|
||||
|
@ -25,11 +25,11 @@ use util::common::ErrorReported;
|
||||
/// inference variable, returns `None`, because we are not able to
|
||||
/// make any progress at all. This is to prevent "livelock" where we
|
||||
/// say "$0 is WF if $0 is WF".
|
||||
pub fn obligations<'a,'tcx>(infcx: &InferCtxt<'a, 'tcx, 'tcx>,
|
||||
body_id: ast::NodeId,
|
||||
ty: Ty<'tcx>,
|
||||
span: Span)
|
||||
-> Option<Vec<traits::PredicateObligation<'tcx>>>
|
||||
pub fn obligations<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
|
||||
body_id: ast::NodeId,
|
||||
ty: Ty<'tcx>,
|
||||
span: Span)
|
||||
-> Option<Vec<traits::PredicateObligation<'tcx>>>
|
||||
{
|
||||
let mut wf = WfPredicates { infcx: infcx,
|
||||
body_id: body_id,
|
||||
@ -49,22 +49,22 @@ pub fn obligations<'a,'tcx>(infcx: &InferCtxt<'a, 'tcx, 'tcx>,
|
||||
/// well-formed. For example, if there is a trait `Set` defined like
|
||||
/// `trait Set<K:Eq>`, then the trait reference `Foo: Set<Bar>` is WF
|
||||
/// if `Bar: Eq`.
|
||||
pub fn trait_obligations<'a,'tcx>(infcx: &InferCtxt<'a, 'tcx, 'tcx>,
|
||||
body_id: ast::NodeId,
|
||||
trait_ref: &ty::TraitRef<'tcx>,
|
||||
span: Span)
|
||||
-> Vec<traits::PredicateObligation<'tcx>>
|
||||
pub fn trait_obligations<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
|
||||
body_id: ast::NodeId,
|
||||
trait_ref: &ty::TraitRef<'tcx>,
|
||||
span: Span)
|
||||
-> Vec<traits::PredicateObligation<'tcx>>
|
||||
{
|
||||
let mut wf = WfPredicates { infcx: infcx, body_id: body_id, span: span, out: vec![] };
|
||||
wf.compute_trait_ref(trait_ref);
|
||||
wf.normalize()
|
||||
}
|
||||
|
||||
pub fn predicate_obligations<'a,'tcx>(infcx: &InferCtxt<'a, 'tcx, 'tcx>,
|
||||
body_id: ast::NodeId,
|
||||
predicate: &ty::Predicate<'tcx>,
|
||||
span: Span)
|
||||
-> Vec<traits::PredicateObligation<'tcx>>
|
||||
pub fn predicate_obligations<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
|
||||
body_id: ast::NodeId,
|
||||
predicate: &ty::Predicate<'tcx>,
|
||||
span: Span)
|
||||
-> Vec<traits::PredicateObligation<'tcx>>
|
||||
{
|
||||
let mut wf = WfPredicates { infcx: infcx, body_id: body_id, span: span, out: vec![] };
|
||||
|
||||
@ -123,8 +123,8 @@ pub enum ImpliedBound<'tcx> {
|
||||
/// Compute the implied bounds that a callee/impl can assume based on
|
||||
/// the fact that caller/projector has ensured that `ty` is WF. See
|
||||
/// the `ImpliedBound` type for more details.
|
||||
pub fn implied_bounds<'a, 'tcx>(
|
||||
infcx: &'a InferCtxt<'a, 'tcx, 'tcx>,
|
||||
pub fn implied_bounds<'a, 'gcx, 'tcx>(
|
||||
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
|
||||
body_id: ast::NodeId,
|
||||
ty: Ty<'tcx>,
|
||||
span: Span)
|
||||
@ -227,14 +227,14 @@ fn implied_bounds_from_components<'tcx>(sub_region: ty::Region,
|
||||
.collect()
|
||||
}
|
||||
|
||||
struct WfPredicates<'a,'tcx:'a> {
|
||||
infcx: &'a InferCtxt<'a, 'tcx, 'tcx>,
|
||||
struct WfPredicates<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
|
||||
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
|
||||
body_id: ast::NodeId,
|
||||
span: Span,
|
||||
out: Vec<traits::PredicateObligation<'tcx>>,
|
||||
}
|
||||
|
||||
impl<'a,'tcx> WfPredicates<'a,'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> WfPredicates<'a, 'gcx, 'tcx> {
|
||||
fn cause(&mut self, code: traits::ObligationCauseCode<'tcx>) -> traits::ObligationCause<'tcx> {
|
||||
traits::ObligationCause::new(self.span, self.body_id, code)
|
||||
}
|
||||
@ -525,8 +525,8 @@ impl<'a,'tcx> WfPredicates<'a,'tcx> {
|
||||
/// they declare `trait SomeTrait : 'static`, for example, then
|
||||
/// `'static` would appear in the list. The hard work is done by
|
||||
/// `ty::required_region_bounds`, see that for more information.
|
||||
pub fn object_region_bounds<'a, 'tcx>(
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
pub fn object_region_bounds<'a, 'gcx, 'tcx>(
|
||||
tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
principal: &ty::PolyTraitRef<'tcx>,
|
||||
others: ty::BuiltinBounds)
|
||||
-> Vec<ty::Region>
|
||||
|
@ -18,6 +18,7 @@ use ty::{TyParam, TyRawPtr, TyRef, TyTuple};
|
||||
use ty::TyClosure;
|
||||
use ty::{TyBox, TyTrait, TyInt, TyUint, TyInfer};
|
||||
use ty::{self, Ty, TyCtxt, TypeFoldable};
|
||||
use ty::fold::{TypeFolder, TypeVisitor};
|
||||
|
||||
use std::cell::Cell;
|
||||
use std::fmt;
|
||||
@ -293,11 +294,11 @@ fn in_binder<'a, 'tcx, T, U>(f: &mut fmt::Formatter,
|
||||
struct TraitAndProjections<'tcx>(ty::TraitRef<'tcx>, Vec<ty::ProjectionPredicate<'tcx>>);
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for TraitAndProjections<'tcx> {
|
||||
fn super_fold_with<F:ty::fold::TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
TraitAndProjections(self.0.fold_with(folder), self.1.fold_with(folder))
|
||||
}
|
||||
|
||||
fn super_visit_with<V: ty::fold::TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
||||
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
||||
self.0.visit_with(visitor) || self.1.visit_with(visitor)
|
||||
}
|
||||
}
|
||||
|
@ -480,7 +480,7 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'cx, 'tcx> TypeFolder<'tcx> for Resolver<'cx, 'tcx, 'tcx> {
|
||||
impl<'cx, 'tcx> TypeFolder<'tcx, 'tcx> for Resolver<'cx, 'tcx, 'tcx> {
|
||||
fn tcx<'a>(&'a self) -> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
self.tcx
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user