From d0447550dabc1b5fee1bde2a2663ebe15d6bbf2a Mon Sep 17 00:00:00 2001 From: scalexm Date: Mon, 22 Oct 2018 22:38:51 +0200 Subject: [PATCH] Shift both late bound regions and bound types --- src/librustc/infer/outlives/obligations.rs | 2 +- src/librustc/infer/sub.rs | 4 +- src/librustc/traits/fulfill.rs | 2 +- src/librustc/traits/project.rs | 4 +- src/librustc/traits/query/normalize.rs | 4 +- src/librustc/traits/select.rs | 16 +-- src/librustc/ty/flags.rs | 7 +- src/librustc/ty/fold.rs | 134 ++++++++++++------ src/librustc/ty/instance.rs | 2 +- src/librustc/ty/outlives.rs | 2 +- src/librustc/ty/sty.rs | 11 +- src/librustc/ty/subst.rs | 26 ++-- src/librustc/ty/util.rs | 4 +- src/librustc/ty/wf.rs | 14 +- src/librustc_codegen_llvm/callee.rs | 2 +- src/librustc_codegen_llvm/type_of.rs | 2 +- src/librustc_driver/test.rs | 12 +- .../borrow_check/nll/type_check/mod.rs | 2 +- src/librustc_mir/monomorphize/collector.rs | 6 +- .../implied_outlives_bounds.rs | 2 +- src/librustc_typeck/check/closure.rs | 2 +- src/librustc_typeck/check/method/mod.rs | 2 +- src/librustc_typeck/check/method/probe.rs | 2 +- src/librustc_typeck/check/mod.rs | 12 +- src/librustc_typeck/coherence/builtin.rs | 6 +- 25 files changed, 164 insertions(+), 118 deletions(-) diff --git a/src/librustc/infer/outlives/obligations.rs b/src/librustc/infer/outlives/obligations.rs index 5db850f1588..523f03c2cfc 100644 --- a/src/librustc/infer/outlives/obligations.rs +++ b/src/librustc/infer/outlives/obligations.rs @@ -305,7 +305,7 @@ pub fn type_must_outlive( ty, region, origin ); - assert!(!ty.has_escaping_regions()); + assert!(!ty.has_escaping_bound_vars()); let components = self.tcx.outlives_components(ty); self.components_must_outlive(origin, components, region); diff --git a/src/librustc/infer/sub.rs b/src/librustc/infer/sub.rs index 048810c0427..3b0f9a5e545 100644 --- a/src/librustc/infer/sub.rs +++ b/src/librustc/infer/sub.rs @@ -84,8 +84,8 @@ fn tys(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> { // Shouldn't have any LBR here, so we can safely put // this under a binder below without fear of accidental // capture. - assert!(!a.has_escaping_regions()); - assert!(!b.has_escaping_regions()); + assert!(!a.has_escaping_bound_vars()); + assert!(!b.has_escaping_bound_vars()); // can't make progress on `A <: B` if both A and B are // type variables, so record an obligation. We also diff --git a/src/librustc/traits/fulfill.rs b/src/librustc/traits/fulfill.rs index cfa77b210e8..afe23e47bbf 100644 --- a/src/librustc/traits/fulfill.rs +++ b/src/librustc/traits/fulfill.rs @@ -143,7 +143,7 @@ fn normalize_projection_type<'a, 'gcx>(&mut self, debug!("normalize_projection_type(projection_ty={:?})", projection_ty); - debug_assert!(!projection_ty.has_escaping_regions()); + debug_assert!(!projection_ty.has_escaping_bound_vars()); // FIXME(#20304) -- cache diff --git a/src/librustc/traits/project.rs b/src/librustc/traits/project.rs index 4eda47d31eb..c0bc214fe7a 100644 --- a/src/librustc/traits/project.rs +++ b/src/librustc/traits/project.rs @@ -366,7 +366,7 @@ fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { let ty = ty.super_fold_with(self); match ty.sty { - ty::Opaque(def_id, substs) if !substs.has_escaping_regions() => { // (*) + ty::Opaque(def_id, substs) if !substs.has_escaping_bound_vars() => { // (*) // Only normalize `impl Trait` after type-checking, usually in codegen. match self.param_env.reveal { Reveal::UserFacing => ty, @@ -393,7 +393,7 @@ fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { } } - ty::Projection(ref data) if !data.has_escaping_regions() => { // (*) + ty::Projection(ref data) if !data.has_escaping_bound_vars() => { // (*) // (*) This is kind of hacky -- we need to be able to // handle normalization within binders because diff --git a/src/librustc/traits/query/normalize.rs b/src/librustc/traits/query/normalize.rs index 4adb65dc58d..59b086e35de 100644 --- a/src/librustc/traits/query/normalize.rs +++ b/src/librustc/traits/query/normalize.rs @@ -100,7 +100,7 @@ fn tcx<'c>(&'c self) -> TyCtxt<'c, 'gcx, 'tcx> { fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { let ty = ty.super_fold_with(self); match ty.sty { - ty::Opaque(def_id, substs) if !substs.has_escaping_regions() => { + ty::Opaque(def_id, substs) if !substs.has_escaping_bound_vars() => { // (*) // Only normalize `impl Trait` after type-checking, usually in codegen. match self.param_env.reveal { @@ -138,7 +138,7 @@ fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { } } - ty::Projection(ref data) if !data.has_escaping_regions() => { + ty::Projection(ref data) if !data.has_escaping_bound_vars() => { // (*) // (*) This is kind of hacky -- we need to be able to // handle normalization within binders because diff --git a/src/librustc/traits/select.rs b/src/librustc/traits/select.rs index 691c9d9da49..6670b83bdf8 100644 --- a/src/librustc/traits/select.rs +++ b/src/librustc/traits/select.rs @@ -587,7 +587,7 @@ pub fn select( obligation: &TraitObligation<'tcx>, ) -> SelectionResult<'tcx, Selection<'tcx>> { debug!("select({:?})", obligation); - debug_assert!(!obligation.predicate.has_escaping_regions()); + debug_assert!(!obligation.predicate.has_escaping_bound_vars()); let stack = self.push_stack(TraitObligationStackList::empty(), obligation); @@ -690,7 +690,7 @@ fn evaluate_predicate_recursively<'o>( match obligation.predicate { ty::Predicate::Trait(ref t) => { - debug_assert!(!t.has_escaping_regions()); + debug_assert!(!t.has_escaping_bound_vars()); let obligation = obligation.with(t.clone()); self.evaluate_trait_predicate_recursively(previous_stack, obligation) } @@ -722,9 +722,9 @@ fn evaluate_predicate_recursively<'o>( }, ty::Predicate::TypeOutlives(ref binder) => { - assert!(!binder.has_escaping_regions()); - // Check if the type has higher-ranked regions. - if binder.skip_binder().0.has_escaping_regions() { + assert!(!binder.has_escaping_bound_vars()); + // Check if the type has higher-ranked vars. + if binder.skip_binder().0.has_escaping_bound_vars() { // If so, this obligation is an error (for now). Eventually we should be // able to support additional cases here, like `for<'a> &'a str: 'a`. @@ -740,7 +740,7 @@ fn evaluate_predicate_recursively<'o>( Ok(EvaluatedToErr) } } else { - // If the type has no late bound regions, then if we assign all + // If the type has no late bound vars, then if we assign all // the inference variables in it to be 'static, then the type // will be 'static itself. // @@ -1199,7 +1199,7 @@ fn candidate_from_obligation<'o>( "candidate_from_obligation(cache_fresh_trait_pred={:?}, obligation={:?})", cache_fresh_trait_pred, stack ); - debug_assert!(!stack.obligation.predicate.has_escaping_regions()); + debug_assert!(!stack.obligation.predicate.has_escaping_bound_vars()); if let Some(c) = self.check_candidate_cache(stack.obligation.param_env, &cache_fresh_trait_pred) @@ -1801,7 +1801,7 @@ fn match_projection( placeholder_map: &infer::PlaceholderMap<'tcx>, snapshot: &infer::CombinedSnapshot<'cx, 'tcx>, ) -> bool { - debug_assert!(!skol_trait_ref.has_escaping_regions()); + debug_assert!(!skol_trait_ref.has_escaping_bound_vars()); if self.infcx .at(&obligation.cause, obligation.param_env) .sup(ty::Binder::dummy(skol_trait_ref), trait_bound) diff --git a/src/librustc/ty/flags.rs b/src/librustc/ty/flags.rs index 92e08878708..d0ea7f653d1 100644 --- a/src/librustc/ty/flags.rs +++ b/src/librustc/ty/flags.rs @@ -115,7 +115,10 @@ fn add_sty(&mut self, st: &ty::TyKind<'_>) { self.add_substs(&substs.substs); } - &ty::Bound(_) => self.add_flags(TypeFlags::HAS_CANONICAL_VARS), + &ty::Bound(bound_ty) => { + self.add_flags(TypeFlags::HAS_CANONICAL_VARS); + self.add_binder(bound_ty.level); + } &ty::Infer(infer) => { self.add_flags(TypeFlags::HAS_FREE_LOCAL_NAMES); // it might, right? @@ -142,7 +145,7 @@ fn add_sty(&mut self, st: &ty::TyKind<'_>) { &ty::Projection(ref data) => { // currently we can't normalize projections that // include bound regions, so track those separately. - if !data.has_escaping_regions() { + if !data.has_escaping_bound_vars() { self.add_flags(TypeFlags::HAS_NORMALIZABLE_PROJECTION); } self.add_flags(TypeFlags::HAS_PROJECTION); diff --git a/src/librustc/ty/fold.rs b/src/librustc/ty/fold.rs index 80dfd263af9..cb94d7d1083 100644 --- a/src/librustc/ty/fold.rs +++ b/src/librustc/ty/fold.rs @@ -67,18 +67,18 @@ fn visit_with>(&self, visitor: &mut V) -> bool { /// bound by `binder` or bound by some binder outside of `binder`. /// If `binder` is `ty::INNERMOST`, this indicates whether /// there are any late-bound regions that appear free. - fn has_regions_bound_at_or_above(&self, binder: ty::DebruijnIndex) -> bool { - self.visit_with(&mut HasEscapingRegionsVisitor { outer_index: binder }) + fn has_vars_bound_at_or_above(&self, binder: ty::DebruijnIndex) -> bool { + self.visit_with(&mut HasEscapingVarsVisitor { outer_index: binder }) } /// True if this `self` has any regions that escape `binder` (and /// hence are not bound by it). - fn has_regions_bound_above(&self, binder: ty::DebruijnIndex) -> bool { - self.has_regions_bound_at_or_above(binder.shifted_in(1)) + fn has_vars_bound_above(&self, binder: ty::DebruijnIndex) -> bool { + self.has_vars_bound_at_or_above(binder.shifted_in(1)) } - fn has_escaping_regions(&self) -> bool { - self.has_regions_bound_at_or_above(ty::INNERMOST) + fn has_escaping_bound_vars(&self) -> bool { + self.has_vars_bound_at_or_above(ty::INNERMOST) } fn has_type_flags(&self, flags: TypeFlags) -> bool { @@ -574,7 +574,7 @@ fn fold_binder>(&mut self, t: &ty::Binder) -> ty::Binde } fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { - if !t.has_regions_bound_at_or_above(self.current_index) { + if !t.has_vars_bound_at_or_above(self.current_index) { return t; } @@ -603,34 +603,79 @@ fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> { } /////////////////////////////////////////////////////////////////////////// -// Region shifter +// Shifter // -// Shifts the De Bruijn indices on all escaping bound regions by a +// Shifts the De Bruijn indices on all escaping bound vars by a // fixed amount. Useful in substitution or when otherwise introducing // a binding level that is not intended to capture the existing bound -// regions. See comment on `shift_regions_through_binders` method in +// vars. See comment on `shift_vars_through_binders` method in // `subst.rs` for more details. -pub fn shift_region(region: ty::RegionKind, amount: u32) -> ty::RegionKind { - match region { - ty::ReLateBound(debruijn, br) => { - ty::ReLateBound(debruijn.shifted_in(amount), br) +struct Shifter<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { + tcx: TyCtxt<'a, 'gcx, 'tcx>, + + current_index: ty::DebruijnIndex, + amount: u32, +} + +impl Shifter<'a, 'gcx, 'tcx> { + pub fn new(tcx: TyCtxt<'a, 'gcx, 'tcx>, amount: u32) -> Self { + Shifter { + tcx, + current_index: ty::INNERMOST, + amount, } - _ => { - region + } +} + +impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for Shifter<'a, 'gcx, 'tcx> { + fn tcx<'b>(&'b self) -> TyCtxt<'b, 'gcx, 'tcx> { self.tcx } + + fn fold_binder>(&mut self, t: &ty::Binder) -> ty::Binder { + self.current_index.shift_in(1); + let t = t.super_fold_with(self); + self.current_index.shift_out(1); + t + } + + fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> { + match *r { + ty::ReLateBound(debruijn, br) => { + if self.amount == 0 || debruijn < self.current_index { + r + } else { + let shifted = ty::ReLateBound(debruijn.shifted_in(self.amount), br); + self.tcx.mk_region(shifted) + } + } + _ => r + } + } + + fn fold_ty(&mut self, ty: ty::Ty<'tcx>) -> ty::Ty<'tcx> { + match ty.sty { + ty::Bound(bound_ty) => { + if self.amount == 0 || bound_ty.level < self.current_index { + ty + } else { + let shifted = ty::BoundTy { + level: bound_ty.level.shifted_in(self.amount), + var: bound_ty.var, + kind: bound_ty.kind, + }; + self.tcx.mk_ty(ty::Bound(shifted)) + } + } + + _ => ty.super_fold_with(self), } } } -pub fn shift_region_ref<'a, 'gcx, 'tcx>( - tcx: TyCtxt<'a, 'gcx, 'tcx>, - region: ty::Region<'tcx>, - amount: u32) - -> ty::Region<'tcx> -{ +pub fn shift_region(region: ty::RegionKind, amount: u32) -> ty::RegionKind { match region { - &ty::ReLateBound(debruijn, br) if amount > 0 => { - tcx.mk_region(ty::ReLateBound(debruijn.shifted_in(amount), br)) + ty::ReLateBound(debruijn, br) => { + ty::ReLateBound(debruijn.shifted_in(amount), br) } _ => { region @@ -638,20 +683,19 @@ pub fn shift_region_ref<'a, 'gcx, 'tcx>( } } -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={})", +pub fn shift_vars<'a, 'gcx, 'tcx, T>( + tcx: TyCtxt<'a, 'gcx, 'tcx>, + amount: u32, + value: &T +) -> T where T: TypeFoldable<'tcx> { + debug!("shift_vars(value={:?}, amount={})", value, amount); - value.fold_with(&mut RegionFolder::new(tcx, &mut false, &mut |region, _current_depth| { - shift_region_ref(tcx, region, amount) - })) + value.fold_with(&mut Shifter::new(tcx, amount)) } -/// An "escaping region" is a bound region whose binder is not part of `t`. +/// An "escaping var" is a bound var whose binder is not part of `t`. A bound var can be a +/// bound region or a bound type. /// /// So, for example, consider a type like the following, which has two binders: /// @@ -663,24 +707,24 @@ pub fn shift_regions<'a, 'gcx, 'tcx, T>(tcx: TyCtxt<'a, 'gcx, 'tcx>, /// binders of both `'a` and `'b` are part of the type itself. However, if we consider the *inner /// fn type*, that type has an escaping region: `'a`. /// -/// Note that what I'm calling an "escaping region" is often just called a "free region". However, -/// we already use the term "free region". It refers to the regions that we use to represent bound -/// regions on a fn definition while we are typechecking its body. +/// Note that what I'm calling an "escaping var" is often just called a "free var". However, +/// we already use the term "free var". It refers to the regions or types that we use to represent +/// bound regions or type params on a fn definition while we are typechecking its body. /// /// To clarify, conceptually there is no particular difference between -/// an "escaping" region and a "free" region. However, there is a big +/// an "escaping" var and a "free" var. However, there is a big /// difference in practice. Basically, when "entering" a binding /// level, one is generally required to do some sort of processing to -/// a bound region, such as replacing it with a fresh/placeholder -/// region, or making an entry in the environment to represent the -/// scope to which it is attached, etc. An escaping region represents -/// a bound region for which this processing has not yet been done. -struct HasEscapingRegionsVisitor { +/// a bound var, such as replacing it with a fresh/placeholder +/// var, or making an entry in the environment to represent the +/// scope to which it is attached, etc. An escaping var represents +/// a bound var for which this processing has not yet been done. +struct HasEscapingVarsVisitor { /// Anything bound by `outer_index` or "above" is escaping outer_index: ty::DebruijnIndex, } -impl<'tcx> TypeVisitor<'tcx> for HasEscapingRegionsVisitor { +impl<'tcx> TypeVisitor<'tcx> for HasEscapingVarsVisitor { fn visit_binder>(&mut self, t: &Binder) -> bool { self.outer_index.shift_in(1); let result = t.super_visit_with(self); @@ -693,7 +737,7 @@ fn visit_ty(&mut self, t: Ty<'tcx>) -> bool { // `outer_index`, that means that `t` contains some content // bound at `outer_index` or above (because // `outer_exclusive_binder` is always 1 higher than the - // content in `t`). Therefore, `t` has some escaping regions. + // content in `t`). Therefore, `t` has some escaping vars. t.outer_exclusive_binder > self.outer_index } diff --git a/src/librustc/ty/instance.rs b/src/librustc/ty/instance.rs index 041565c8b5a..2fc8ef548fa 100644 --- a/src/librustc/ty/instance.rs +++ b/src/librustc/ty/instance.rs @@ -213,7 +213,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { impl<'a, 'b, 'tcx> Instance<'tcx> { pub fn new(def_id: DefId, substs: &'tcx Substs<'tcx>) -> Instance<'tcx> { - assert!(!substs.has_escaping_regions(), + assert!(!substs.has_escaping_bound_vars(), "substs of instance {:?} not normalized for codegen: {:?}", def_id, substs); Instance { def: InstanceDef::Item(def_id), substs: substs } diff --git a/src/librustc/ty/outlives.rs b/src/librustc/ty/outlives.rs index 4c820447be2..449730c9d06 100644 --- a/src/librustc/ty/outlives.rs +++ b/src/librustc/ty/outlives.rs @@ -106,7 +106,7 @@ fn compute_components(&self, ty: Ty<'tcx>, out: &mut Vec>) { // we simply fallback to the most restrictive rule, which // requires that `Pi: 'a` for all `i`. ty::Projection(ref data) => { - if !data.has_escaping_regions() { + if !data.has_escaping_bound_vars() { // best case: no escaping regions, so push the // projection and skip the subtree (thus generating no // constraints for Pi). This defers the choice between diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index 25f7496e893..e812486d1f8 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -730,8 +730,8 @@ pub fn erase_self_ty(tcx: TyCtxt<'a, 'gcx, 'tcx>, /// or some placeholder type. pub fn with_self_ty(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, self_ty: Ty<'tcx>) -> ty::TraitRef<'tcx> { - // otherwise the escaping regions would be captured by the binder - // debug_assert!(!self_ty.has_escaping_regions()); + // otherwise the escaping vars would be captured by the binder + // debug_assert!(!self_ty.has_escaping_bound_vars()); ty::TraitRef { def_id: self.def_id, @@ -776,7 +776,7 @@ impl Binder { pub fn dummy<'tcx>(value: T) -> Binder where T: TypeFoldable<'tcx> { - debug_assert!(!value.has_escaping_regions()); + debug_assert!(!value.has_escaping_bound_vars()); Binder(value) } @@ -835,7 +835,7 @@ pub fn map_bound(self, f: F) -> Binder pub fn no_late_bound_regions<'tcx>(self) -> Option where T : TypeFoldable<'tcx> { - if self.skip_binder().has_escaping_regions() { + if self.skip_binder().has_escaping_bound_vars() { None } else { Some(self.skip_binder().clone()) @@ -1246,7 +1246,6 @@ pub enum BoundTyKind { impl BoundTy { pub fn new(level: DebruijnIndex, var: BoundTyIndex) -> Self { - debug_assert_eq!(ty::INNERMOST, level); BoundTy { level, var, @@ -1283,7 +1282,7 @@ pub fn with_self_ty(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, -> ty::ProjectionPredicate<'tcx> { // otherwise the escaping regions would be captured by the binders - debug_assert!(!self_ty.has_escaping_regions()); + debug_assert!(!self_ty.has_escaping_bound_vars()); ty::ProjectionPredicate { projection_ty: ty::ProjectionTy { diff --git a/src/librustc/ty/subst.rs b/src/librustc/ty/subst.rs index 87c2c9b6005..9e85cfe7a12 100644 --- a/src/librustc/ty/subst.rs +++ b/src/librustc/ty/subst.rs @@ -355,7 +355,7 @@ fn subst_spanned<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, span, root_ty: None, ty_stack_depth: 0, - region_binders_passed: 0 }; + binders_passed: 0 }; (*self).fold_with(&mut folder) } } @@ -377,16 +377,16 @@ struct SubstFolder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { ty_stack_depth: usize, // Number of region binders we have passed through while doing the substitution - region_binders_passed: u32, + binders_passed: u32, } 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>(&mut self, t: &ty::Binder) -> ty::Binder { - self.region_binders_passed += 1; + self.binders_passed += 1; let t = t.super_fold_with(self); - self.region_binders_passed -= 1; + self.binders_passed -= 1; t } @@ -471,7 +471,7 @@ fn ty_for_param(&self, p: ty::ParamTy, source_ty: Ty<'tcx>) -> Ty<'tcx> { } }; - self.shift_regions_through_binders(ty) + self.shift_vars_through_binders(ty) } /// It is sometimes necessary to adjust the debruijn indices during substitution. This occurs @@ -516,25 +516,25 @@ fn ty_for_param(&self, p: ty::ParamTy, source_ty: Ty<'tcx>) -> Ty<'tcx> { /// As indicated in the diagram, here the same type `&'a int` is substituted once, but in the /// first case we do not increase the Debruijn index and in the second case we do. The reason /// is that only in the second case have we passed through a fn binder. - fn shift_regions_through_binders(&self, ty: Ty<'tcx>) -> Ty<'tcx> { - debug!("shift_regions(ty={:?}, region_binders_passed={:?}, has_escaping_regions={:?})", - ty, self.region_binders_passed, ty.has_escaping_regions()); + fn shift_vars_through_binders(&self, ty: Ty<'tcx>) -> Ty<'tcx> { + debug!("shift_vars(ty={:?}, binders_passed={:?}, has_escaping_bound_vars={:?})", + ty, self.binders_passed, ty.has_escaping_bound_vars()); - if self.region_binders_passed == 0 || !ty.has_escaping_regions() { + if self.binders_passed == 0 || !ty.has_escaping_bound_vars() { return ty; } - let result = ty::fold::shift_regions(self.tcx(), self.region_binders_passed, &ty); - debug!("shift_regions: shifted result = {:?}", result); + let result = ty::fold::shift_vars(self.tcx(), self.binders_passed, &ty); + debug!("shift_vars: shifted result = {:?}", result); result } fn shift_region_through_binders(&self, region: ty::Region<'tcx>) -> ty::Region<'tcx> { - if self.region_binders_passed == 0 || !region.has_escaping_regions() { + if self.binders_passed == 0 || !region.has_escaping_bound_vars() { return region; } - self.tcx().mk_region(ty::fold::shift_region(*region, self.region_binders_passed)) + self.tcx().mk_region(ty::fold::shift_region(*region, self.binders_passed)) } } diff --git a/src/librustc/ty/util.rs b/src/librustc/ty/util.rs index 0a758285a29..1b1bbfd4deb 100644 --- a/src/librustc/ty/util.rs +++ b/src/librustc/ty/util.rs @@ -363,7 +363,7 @@ pub fn required_region_bounds(self, erased_self_ty, predicates); - assert!(!erased_self_ty.has_escaping_regions()); + assert!(!erased_self_ty.has_escaping_bound_vars()); traits::elaborate_predicates(self, predicates) .filter_map(|predicate| { @@ -389,7 +389,7 @@ pub fn required_region_bounds(self, // construct such an object, but this seems // correct even if that code changes). let ty::OutlivesPredicate(ref t, ref r) = predicate.skip_binder(); - if t == &erased_self_ty && !r.has_escaping_regions() { + if t == &erased_self_ty && !r.has_escaping_bound_vars() { Some(*r) } else { None diff --git a/src/librustc/ty/wf.rs b/src/librustc/ty/wf.rs index eb97f1177af..1336eac63f8 100644 --- a/src/librustc/ty/wf.rs +++ b/src/librustc/ty/wf.rs @@ -158,7 +158,7 @@ fn normalize(&mut self) -> Vec> { let infcx = &mut self.infcx; let param_env = self.param_env; self.out.iter() - .inspect(|pred| assert!(!pred.has_escaping_regions())) + .inspect(|pred| assert!(!pred.has_escaping_bound_vars())) .flat_map(|pred| { let mut selcx = traits::SelectionContext::new(infcx); let pred = traits::normalize(&mut selcx, param_env, cause.clone(), pred); @@ -190,7 +190,7 @@ fn compute_trait_ref(&mut self, trait_ref: &ty::TraitRef<'tcx>, elaborate: Elabo self.out.extend( trait_ref.substs.types() - .filter(|ty| !ty.has_escaping_regions()) + .filter(|ty| !ty.has_escaping_bound_vars()) .map(|ty| traits::Obligation::new(cause.clone(), param_env, ty::Predicate::WellFormed(ty)))); @@ -205,7 +205,7 @@ fn compute_projection(&mut self, data: ty::ProjectionTy<'tcx>) { let trait_ref = data.trait_ref(self.infcx.tcx); self.compute_trait_ref(&trait_ref, Elaborate::None); - if !data.has_escaping_regions() { + if !data.has_escaping_bound_vars() { let predicate = trait_ref.to_predicate(); let cause = self.cause(traits::ProjectionWf(data)); self.out.push(traits::Obligation::new(cause, self.param_env, predicate)); @@ -229,7 +229,7 @@ fn compute_const(&mut self, constant: &'tcx ty::Const<'tcx>) { } fn require_sized(&mut self, subty: Ty<'tcx>, cause: traits::ObligationCauseCode<'tcx>) { - if !subty.has_escaping_regions() { + if !subty.has_escaping_bound_vars() { let cause = self.cause(cause); let trait_ref = ty::TraitRef { def_id: self.infcx.tcx.require_lang_item(lang_items::SizedTraitLangItem), @@ -300,7 +300,7 @@ fn compute(&mut self, ty0: Ty<'tcx>) -> bool { ty::Ref(r, rty, _) => { // WfReference - if !r.has_escaping_regions() && !rty.has_escaping_regions() { + if !r.has_escaping_bound_vars() && !rty.has_escaping_bound_vars() { let cause = self.cause(traits::ReferenceOutlivesReferent(ty)); self.out.push( traits::Obligation::new( @@ -451,7 +451,7 @@ fn nominal_obligations(&mut self, .map(|pred| traits::Obligation::new(cause.clone(), self.param_env, pred)) - .filter(|pred| !pred.has_escaping_regions()) + .filter(|pred| !pred.has_escaping_bound_vars()) .collect() } @@ -490,7 +490,7 @@ fn from_object_ty(&mut self, ty: Ty<'tcx>, // Note: in fact we only permit builtin traits, not `Bar<'d>`, I // am looking forward to the future here. - if !data.has_escaping_regions() { + if !data.has_escaping_bound_vars() { let implicit_bounds = object_region_bounds(self.infcx.tcx, data); diff --git a/src/librustc_codegen_llvm/callee.rs b/src/librustc_codegen_llvm/callee.rs index 7300bac9618..c8c693257d5 100644 --- a/src/librustc_codegen_llvm/callee.rs +++ b/src/librustc_codegen_llvm/callee.rs @@ -44,7 +44,7 @@ pub fn get_fn( debug!("get_fn(instance={:?})", instance); assert!(!instance.substs.needs_infer()); - assert!(!instance.substs.has_escaping_regions()); + assert!(!instance.substs.has_escaping_bound_vars()); assert!(!instance.substs.has_param_types()); let sig = instance.fn_sig(cx.tcx); diff --git a/src/librustc_codegen_llvm/type_of.rs b/src/librustc_codegen_llvm/type_of.rs index 03ded64e642..b01d7e3a776 100644 --- a/src/librustc_codegen_llvm/type_of.rs +++ b/src/librustc_codegen_llvm/type_of.rs @@ -285,7 +285,7 @@ fn llvm_type<'a>(&self, cx: &CodegenCx<'a, 'tcx>) -> &'a Type { debug!("llvm_type({:#?})", self); - assert!(!self.ty.has_escaping_regions(), "{:?} has escaping regions", self.ty); + assert!(!self.ty.has_escaping_bound_vars(), "{:?} has escaping bound vars", self.ty); // Make sure lifetimes are erased, to avoid generating distinct LLVM // types for Rust types that only differ in the choice of lifetimes. diff --git a/src/librustc_driver/test.rs b/src/librustc_driver/test.rs index f18f40bf7a1..28b7c610a91 100644 --- a/src/librustc_driver/test.rs +++ b/src/librustc_driver/test.rs @@ -616,22 +616,22 @@ fn escaping() { // Theta = [A -> &'a foo] env.create_simple_region_hierarchy(); - assert!(!env.t_nil().has_escaping_regions()); + assert!(!env.t_nil().has_escaping_bound_vars()); let t_rptr_free1 = env.t_rptr_free(1); - assert!(!t_rptr_free1.has_escaping_regions()); + assert!(!t_rptr_free1.has_escaping_bound_vars()); let t_rptr_bound1 = env.t_rptr_late_bound_with_debruijn(1, d1()); - assert!(t_rptr_bound1.has_escaping_regions()); + assert!(t_rptr_bound1.has_escaping_bound_vars()); let t_rptr_bound2 = env.t_rptr_late_bound_with_debruijn(1, d2()); - assert!(t_rptr_bound2.has_escaping_regions()); + assert!(t_rptr_bound2.has_escaping_bound_vars()); // t_fn = fn(A) let t_param = env.t_param(0); - assert!(!t_param.has_escaping_regions()); + assert!(!t_param.has_escaping_bound_vars()); let t_fn = env.t_fn(&[t_param], env.t_nil()); - assert!(!t_fn.has_escaping_regions()); + assert!(!t_fn.has_escaping_bound_vars()); }) } diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs index aa9564bdcaf..91c2035838d 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs @@ -359,7 +359,7 @@ fn tcx(&self) -> TyCtxt<'a, 'gcx, 'tcx> { } fn sanitize_type(&mut self, parent: &dyn fmt::Debug, ty: Ty<'tcx>) -> Ty<'tcx> { - if ty.has_escaping_regions() || ty.references_error() { + if ty.has_escaping_bound_vars() || ty.references_error() { span_mirbug_and_err!(self, parent, "bad type {:?}", ty) } else { ty diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index 8c696669132..6b39060d6fc 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -905,12 +905,12 @@ fn create_mono_items_for_vtable_methods<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, trait_ty: Ty<'tcx>, impl_ty: Ty<'tcx>, output: &mut Vec>) { - assert!(!trait_ty.needs_subst() && !trait_ty.has_escaping_regions() && - !impl_ty.needs_subst() && !impl_ty.has_escaping_regions()); + assert!(!trait_ty.needs_subst() && !trait_ty.has_escaping_bound_vars() && + !impl_ty.needs_subst() && !impl_ty.has_escaping_bound_vars()); if let ty::Dynamic(ref trait_ty, ..) = trait_ty.sty { let poly_trait_ref = trait_ty.principal().with_self_ty(tcx, impl_ty); - assert!(!poly_trait_ref.has_escaping_regions()); + assert!(!poly_trait_ref.has_escaping_bound_vars()); // Walk all methods of the trait, including those of its supertraits let methods = tcx.vtable_methods(poly_trait_ref); diff --git a/src/librustc_traits/implied_outlives_bounds.rs b/src/librustc_traits/implied_outlives_bounds.rs index cde08f6832a..b97450f9662 100644 --- a/src/librustc_traits/implied_outlives_bounds.rs +++ b/src/librustc_traits/implied_outlives_bounds.rs @@ -108,7 +108,7 @@ fn compute_implied_outlives_bounds<'tcx>( // From the full set of obligations, just filter down to the // region relationships. implied_bounds.extend(obligations.into_iter().flat_map(|obligation| { - assert!(!obligation.has_escaping_regions()); + assert!(!obligation.has_escaping_bound_vars()); match obligation.predicate { ty::Predicate::Trait(..) | ty::Predicate::Subtype(..) | diff --git a/src/librustc_typeck/check/closure.rs b/src/librustc_typeck/check/closure.rs index fb7c237a536..010561d1001 100644 --- a/src/librustc_typeck/check/closure.rs +++ b/src/librustc_typeck/check/closure.rs @@ -460,7 +460,7 @@ fn sig_of_closure_with_expectation( // Create a `PolyFnSig`. Note the oddity that late bound // regions appearing free in `expected_sig` are now bound up // in this binder we are creating. - assert!(!expected_sig.sig.has_regions_bound_above(ty::INNERMOST)); + assert!(!expected_sig.sig.has_vars_bound_above(ty::INNERMOST)); let bound_sig = ty::Binder::bind(self.tcx.mk_fn_sig( expected_sig.sig.inputs().iter().cloned(), expected_sig.sig.output(), diff --git a/src/librustc_typeck/check/method/mod.rs b/src/librustc_typeck/check/method/mod.rs index 04c32fa8827..11448750618 100644 --- a/src/librustc_typeck/check/method/mod.rs +++ b/src/librustc_typeck/check/method/mod.rs @@ -331,7 +331,7 @@ pub fn lookup_method_in_trait(&self, value } }; - assert!(!bounds.has_escaping_regions()); + assert!(!bounds.has_escaping_bound_vars()); let cause = traits::ObligationCause::misc(span, self.body_id); obligations.extend(traits::predicates_for_generics(cause.clone(), diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index 5a8a9632350..305efd0d75a 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -1374,7 +1374,7 @@ fn xform_method_sig(&self, fn_sig, substs); - assert!(!substs.has_escaping_regions()); + assert!(!substs.has_escaping_bound_vars()); // It is possible for type parameters or early-bound lifetimes // to appear in the signature of `self`. The substitutions we diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 9ac733b159b..791b5a0bdd9 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -653,8 +653,8 @@ fn new(infcx: InferCtxt<'a, 'gcx, 'tcx>, def_id: DefId) -> Self { fn register_predicate(&self, obligation: traits::PredicateObligation<'tcx>) { debug!("register_predicate({:?})", obligation); - if obligation.has_escaping_regions() { - span_bug!(obligation.cause.span, "escaping regions in predicate {:?}", + if obligation.has_escaping_bound_vars() { + span_bug!(obligation.cause.span, "escaping bound vars in predicate {:?}", obligation); } self.fulfillment_cx @@ -1928,7 +1928,7 @@ fn projected_ty_from_poly_trait_ref(&self, } fn normalize_ty(&self, span: Span, ty: Ty<'tcx>) -> Ty<'tcx> { - if ty.has_escaping_regions() { + if ty.has_escaping_bound_vars() { ty // FIXME: normalization and escaping regions } else { self.normalize_associated_types_in(span, &ty) @@ -2431,7 +2431,7 @@ pub fn add_obligations_for_parameters(&self, cause: traits::ObligationCause<'tcx>, predicates: &ty::InstantiatedPredicates<'tcx>) { - assert!(!predicates.has_escaping_regions()); + assert!(!predicates.has_escaping_bound_vars()); debug!("add_obligations_for_parameters(predicates={:?})", predicates); @@ -5188,8 +5188,8 @@ pub fn instantiate_value_path(&self, } }, ); - assert!(!substs.has_escaping_regions()); - assert!(!ty.has_escaping_regions()); + assert!(!substs.has_escaping_bound_vars()); + assert!(!ty.has_escaping_bound_vars()); // Write the "user substs" down first thing for later. let hir_id = self.tcx.hir.node_to_hir_id(node_id); diff --git a/src/librustc_typeck/coherence/builtin.rs b/src/librustc_typeck/coherence/builtin.rs index 99c6ba457fa..a5ad31e0b6b 100644 --- a/src/librustc_typeck/coherence/builtin.rs +++ b/src/librustc_typeck/coherence/builtin.rs @@ -99,7 +99,7 @@ fn visit_implementation_of_copy<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_did: let span = tcx.hir.span(impl_node_id); let param_env = tcx.param_env(impl_did); - assert!(!self_type.has_escaping_regions()); + assert!(!self_type.has_escaping_bound_vars()); debug!("visit_implementation_of_copy: self_type={:?} (free)", self_type); @@ -176,7 +176,7 @@ fn visit_implementation_of_dispatch_from_dyn<'a, 'tcx>( let span = tcx.hir.span(impl_node_id); let source = tcx.type_of(impl_did); - assert!(!source.has_escaping_regions()); + assert!(!source.has_escaping_bound_vars()); let target = { let trait_ref = tcx.impl_trait_ref(impl_did).unwrap(); assert_eq!(trait_ref.def_id, dispatch_from_dyn_trait); @@ -356,7 +356,7 @@ pub fn coerce_unsized_info<'a, 'gcx>(gcx: TyCtxt<'a, 'gcx, 'gcx>, let span = gcx.hir.span(impl_node_id); let param_env = gcx.param_env(impl_did); - assert!(!source.has_escaping_regions()); + assert!(!source.has_escaping_bound_vars()); let err_info = CoerceUnsizedInfo { custom_kind: None }; -- 2.44.0