]> git.lizzy.rs Git - rust.git/commitdiff
move `liberate_late_bound_regions` to a method on the tcx
authorNiko Matsakis <niko@alum.mit.edu>
Tue, 21 Nov 2017 16:17:48 +0000 (11:17 -0500)
committerNiko Matsakis <niko@alum.mit.edu>
Mon, 4 Dec 2017 14:14:37 +0000 (09:14 -0500)
No reason for it to live on `Inherited`.

src/librustc/ty/fold.rs
src/librustc_typeck/check/closure.rs
src/librustc_typeck/check/compare_method.rs
src/librustc_typeck/check/mod.rs
src/librustc_typeck/check/wfcheck.rs

index 658596031832e1cabed4683377c811f9688ffb1e..fbbc0e92bcdba2d17c094f7fe94361db9865d219 100644 (file)
@@ -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 @@ pub fn replace_late_bound_regions<T,F>(self,
         (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>>)
index 5b5d697bcf4351b2d386cff8b8610289ac17bd8d..147347a75abe8264f04a1f140240ae809fb7189d 100644 (file)
@@ -562,7 +562,7 @@ fn closure_sigs(
         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,
index 24efb79170427b0ee0912525e371666d0a4bd588..70607bf4842a55e1c3c5dbb25863d7d0638f0267 100644 (file)
@@ -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 =
index 09dd334a62d8adabba72faa4d93a2f056e41b532..27a0e4f6dfe6330e36a760aa30eb3a688bf68658 100644 (file)
@@ -698,22 +698,6 @@ fn normalize_associated_types_in<T>(&self,
         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,
index 0ca259fd44d78020baf2fc30a883e3365b55ff2f..d4625bb58c33878efa04a2a885d4d57b16098025 100644 (file)
@@ -451,7 +451,7 @@ fn check_fn_or_method<'fcx, 'tcx>(&mut self,
                                       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 @@ fn check_method_receiver<'fcx, 'tcx>(&mut self,
 
         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 @@ fn check_method_receiver<'fcx, 'tcx>(&mut self,
 
         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)
         );