about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2017-11-21 11:17:48 -0500
committerNiko Matsakis <niko@alum.mit.edu>2017-12-04 09:14:37 -0500
commit7f247add4144df0e1fd3951a1d5aa6451c8a8eb2 (patch)
tree21978dedb46c4edc7698263658403f7089892d5e /src
parente9067bd5cc5804edf75bb9d9e56956e0670c3ed1 (diff)
downloadrust-7f247add4144df0e1fd3951a1d5aa6451c8a8eb2.tar.gz
rust-7f247add4144df0e1fd3951a1d5aa6451c8a8eb2.zip
move `liberate_late_bound_regions` to a method on the tcx
No reason for it to live on `Inherited`.
Diffstat (limited to 'src')
-rw-r--r--src/librustc/ty/fold.rs25
-rw-r--r--src/librustc_typeck/check/closure.rs2
-rw-r--r--src/librustc_typeck/check/compare_method.rs2
-rw-r--r--src/librustc_typeck/check/mod.rs18
-rw-r--r--src/librustc_typeck/check/wfcheck.rs8
5 files changed, 32 insertions, 23 deletions
diff --git a/src/librustc/ty/fold.rs b/src/librustc/ty/fold.rs
index 65859603183..fbbc0e92bcd 100644
--- a/src/librustc/ty/fold.rs
+++ b/src/librustc/ty/fold.rs
@@ -40,6 +40,7 @@
 //! and does not need to visit anything else.
 
 use middle::const_val::ConstVal;
+use hir::def_id::DefId;
 use ty::{self, Binder, Ty, TyCtxt, TypeFlags};
 
 use std::fmt;
@@ -329,6 +330,14 @@ struct RegionReplacer<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
 }
 
 impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
+    /// Replace all regions bound by the given `Binder` with the
+    /// results returned by the closure; the closure is expected to
+    /// return a free region (relative to this binder), and hence the
+    /// binder is removed in the return type. The closure is invoked
+    /// once for each unique `BoundRegion`; multiple references to the
+    /// same `BoundRegion` will reuse the previous result.  A map is
+    /// returned at the end with each bound region and the free region
+    /// that replaced it.
     pub fn replace_late_bound_regions<T,F>(self,
         value: &Binder<T>,
         mut f: F)
@@ -341,6 +350,22 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
         (result, replacer.map)
     }
 
+    /// Replace any late-bound regions bound in `value` with
+    /// free variants attached to `all_outlive_scope`.
+    pub fn liberate_late_bound_regions<T>(
+        &self,
+        all_outlive_scope: DefId,
+        value: &ty::Binder<T>
+    ) -> T
+    where T: TypeFoldable<'tcx> {
+        self.replace_late_bound_regions(value, |br| {
+            self.mk_region(ty::ReFree(ty::FreeRegion {
+                scope: all_outlive_scope,
+                bound_region: br
+            }))
+        }).0
+    }
+
     /// Flattens two binding levels into one. So `for<'a> for<'b> Foo`
     /// becomes `for<'a,'b> Foo`.
     pub fn flatten_late_bound_regions<T>(self, bound2_value: &Binder<Binder<T>>)
diff --git a/src/librustc_typeck/check/closure.rs b/src/librustc_typeck/check/closure.rs
index 5b5d697bcf4..147347a75ab 100644
--- a/src/librustc_typeck/check/closure.rs
+++ b/src/librustc_typeck/check/closure.rs
@@ -562,7 +562,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
         body: &hir::Body,
         bound_sig: ty::PolyFnSig<'tcx>,
     ) -> ClosureSignatures<'tcx> {
-        let liberated_sig = self.liberate_late_bound_regions(expr_def_id, &bound_sig);
+        let liberated_sig = self.tcx().liberate_late_bound_regions(expr_def_id, &bound_sig);
         let liberated_sig = self.inh.normalize_associated_types_in(
             body.value.span,
             body.value.id,
diff --git a/src/librustc_typeck/check/compare_method.rs b/src/librustc_typeck/check/compare_method.rs
index 24efb791704..70607bf4842 100644
--- a/src/librustc_typeck/check/compare_method.rs
+++ b/src/librustc_typeck/check/compare_method.rs
@@ -270,7 +270,7 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
         let impl_fty = tcx.mk_fn_ptr(ty::Binder(impl_sig));
         debug!("compare_impl_method: impl_fty={:?}", impl_fty);
 
-        let trait_sig = inh.liberate_late_bound_regions(
+        let trait_sig = tcx.liberate_late_bound_regions(
             impl_m.def_id,
             &tcx.fn_sig(trait_m.def_id));
         let trait_sig =
diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs
index 09dd334a62d..27a0e4f6dfe 100644
--- a/src/librustc_typeck/check/mod.rs
+++ b/src/librustc_typeck/check/mod.rs
@@ -698,22 +698,6 @@ impl<'a, 'gcx, 'tcx> Inherited<'a, 'gcx, 'tcx> {
         let ok = self.partially_normalize_associated_types_in(span, body_id, param_env, value);
         self.register_infer_ok_obligations(ok)
     }
-
-    /// Replace any late-bound regions bound in `value` with
-    /// free variants attached to `all_outlive_scope`.
-    fn liberate_late_bound_regions<T>(&self,
-        all_outlive_scope: DefId,
-        value: &ty::Binder<T>)
-        -> T
-        where T: TypeFoldable<'tcx>
-    {
-        self.tcx.replace_late_bound_regions(value, |br| {
-            self.tcx.mk_region(ty::ReFree(ty::FreeRegion {
-                scope: all_outlive_scope,
-                bound_region: br
-            }))
-        }).0
-    }
 }
 
 struct CheckItemTypesVisitor<'a, 'tcx: 'a> { tcx: TyCtxt<'a, 'tcx, 'tcx> }
@@ -882,7 +866,7 @@ fn typeck_tables_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
 
             // Compute the fty from point of view of inside fn.
             let fn_sig =
-                inh.liberate_late_bound_regions(def_id, &fn_sig);
+                tcx.liberate_late_bound_regions(def_id, &fn_sig);
             let fn_sig =
                 inh.normalize_associated_types_in(body.value.span,
                                                   body_id.node_id,
diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs
index 0ca259fd44d..d4625bb58c3 100644
--- a/src/librustc_typeck/check/wfcheck.rs
+++ b/src/librustc_typeck/check/wfcheck.rs
@@ -451,7 +451,7 @@ impl<'a, 'gcx> CheckTypeWellFormedVisitor<'a, 'gcx> {
                                       implied_bounds: &mut Vec<Ty<'tcx>>)
     {
         let sig = fcx.normalize_associated_types_in(span, &sig);
-        let sig = fcx.liberate_late_bound_regions(def_id, &sig);
+        let sig = fcx.tcx.liberate_late_bound_regions(def_id, &sig);
 
         for input_ty in sig.inputs() {
             fcx.register_wf_obligation(&input_ty, span, self.code.clone());
@@ -484,12 +484,12 @@ impl<'a, 'gcx> CheckTypeWellFormedVisitor<'a, 'gcx> {
 
         let sig = fcx.tcx.fn_sig(method.def_id);
         let sig = fcx.normalize_associated_types_in(span, &sig);
-        let sig = fcx.liberate_late_bound_regions(method.def_id, &sig);
+        let sig = fcx.tcx.liberate_late_bound_regions(method.def_id, &sig);
 
         debug!("check_method_receiver: sig={:?}", sig);
 
         let self_ty = fcx.normalize_associated_types_in(span, &self_ty);
-        let self_ty = fcx.liberate_late_bound_regions(
+        let self_ty = fcx.tcx.liberate_late_bound_regions(
             method.def_id,
             &ty::Binder(self_ty)
         );
@@ -498,7 +498,7 @@ impl<'a, 'gcx> CheckTypeWellFormedVisitor<'a, 'gcx> {
 
         let cause = fcx.cause(span, ObligationCauseCode::MethodReceiver);
         let self_arg_ty = fcx.normalize_associated_types_in(span, &self_arg_ty);
-        let self_arg_ty = fcx.liberate_late_bound_regions(
+        let self_arg_ty = fcx.tcx.liberate_late_bound_regions(
             method.def_id,
             &ty::Binder(self_arg_ty)
         );