]> git.lizzy.rs Git - rust.git/commitdiff
make `no_late_bound_regions` a method on `Binder<T>`
authorNiko Matsakis <niko@alum.mit.edu>
Sun, 12 Nov 2017 10:04:26 +0000 (05:04 -0500)
committerNiko Matsakis <niko@alum.mit.edu>
Mon, 4 Dec 2017 13:51:12 +0000 (08:51 -0500)
12 files changed:
src/librustc/infer/outlives/implied_bounds.rs
src/librustc/infer/outlives/obligations.rs
src/librustc/traits/fulfill.rs
src/librustc/traits/project.rs
src/librustc/traits/select.rs
src/librustc/ty/fold.rs
src/librustc/ty/sty.rs
src/librustc_mir/shim.rs
src/librustc_mir/transform/lower_128bit.rs
src/librustc_typeck/check/_match.rs
src/librustc_typeck/check/intrinsic.rs
src/librustc_typeck/collect.rs

index ae6961a071393348366384fecb3442ff42aa73c6..452ceddd7d6e9d1295c740b88c3d4a44f239dff0 100644 (file)
@@ -126,7 +126,7 @@ pub fn implied_bounds(
                     }
 
                     ty::Predicate::RegionOutlives(ref data) => {
-                        match tcx.no_late_bound_regions(data) {
+                        match data.no_late_bound_regions() {
                             None => vec![],
                             Some(ty::OutlivesPredicate(r_a, r_b)) => {
                                 vec![ImpliedBound::RegionSubRegion(r_b, r_a)]
@@ -135,7 +135,7 @@ pub fn implied_bounds(
                     }
 
                     ty::Predicate::TypeOutlives(ref data) => {
-                        match tcx.no_late_bound_regions(data) {
+                        match data.no_late_bound_regions() {
                             None => vec![],
                             Some(ty::OutlivesPredicate(ty_a, r_b)) => {
                                 let ty_a = self.resolve_type_vars_if_possible(&ty_a);
index 3c3aba372fbd0132a9e3d56ba16023ce0b0dde72..07eacde0aab883239308208e7ace5b3c790e9ddc 100644 (file)
@@ -604,7 +604,7 @@ fn collect_outlives_from_predicate_list<I, P>(
         predicates
             .into_iter()
             .filter_map(|p| p.as_ref().to_opt_type_outlives())
-            .filter_map(|p| self.tcx().no_late_bound_regions(&p))
+            .filter_map(|p| p.no_late_bound_regions())
             .filter(|p| p.0 == ty)
             .map(|p| p.1)
             .collect()
index f56c3853de0ab67966ffc2a6eb8a82f6f40e1e64..93e33836818ce9d9f75559694b9fe7a6175db078 100644 (file)
@@ -400,14 +400,14 @@ fn process_predicate<'a, 'gcx, 'tcx>(
 
         ty::Predicate::TypeOutlives(ref binder) => {
             // Check if there are higher-ranked regions.
-            match selcx.tcx().no_late_bound_regions(binder) {
+            match binder.no_late_bound_regions() {
                 // If there are, inspect the underlying type further.
                 None => {
                     // Convert from `Binder<OutlivesPredicate<Ty, Region>>` to `Binder<Ty>`.
                     let binder = binder.map_bound_ref(|pred| pred.0);
 
                     // Check if the type has any bound regions.
-                    match selcx.tcx().no_late_bound_regions(&binder) {
+                    match binder.no_late_bound_regions() {
                         // 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`.
                         None => {
index 0cc755dc4272767be390cd7afd9455e4813cd08f..429771cca9844c831f787868ee0e9a1618f2ad7e 100644 (file)
@@ -1559,7 +1559,7 @@ pub fn from_poly_projection_predicate(selcx: &mut SelectionContext<'cx, 'gcx, 't
         let infcx = selcx.infcx();
         // We don't do cross-snapshot caching of obligations with escaping regions,
         // so there's no cache key to use
-        infcx.tcx.no_late_bound_regions(&predicate)
+        predicate.no_late_bound_regions()
             .map(|predicate| ProjectionCacheKey {
                 // We don't attempt to match up with a specific type-variable state
                 // from a specific call to `opt_normalize_projection_type` - if
index 4bc3e2dd4d8d40e40096c2399ef707bea3a9827f..91e6c4270b32a24b0b504d4060b0bc68a4d51424 100644 (file)
@@ -1834,7 +1834,7 @@ fn assemble_candidates_for_unsizing(&mut self,
         //     T: Trait
         // so it seems ok if we (conservatively) fail to accept that `Unsize`
         // obligation above. Should be possible to extend this in the future.
-        let source = match self.tcx().no_late_bound_regions(&obligation.self_ty()) {
+        let source = match obligation.self_ty().no_late_bound_regions() {
             Some(t) => t,
             None => {
                 // Don't add any candidates if there are bound regions.
@@ -2784,7 +2784,7 @@ fn confirm_builtin_unsize_candidate(&mut self,
         // assemble_candidates_for_unsizing should ensure there are no late bound
         // regions here. See the comment there for more details.
         let source = self.infcx.shallow_resolve(
-            tcx.no_late_bound_regions(&obligation.self_ty()).unwrap());
+            obligation.self_ty().no_late_bound_regions().unwrap());
         let target = obligation.predicate.skip_binder().trait_ref.substs.type_at(1);
         let target = self.infcx.shallow_resolve(target);
 
index bee119992230f379446c257149ce823e1b8f5f93..658596031832e1cabed4683377c811f9688ffb1e 100644 (file)
@@ -364,16 +364,6 @@ pub fn flatten_late_bound_regions<T>(self, bound2_value: &Binder<Binder<T>>)
         Binder(value)
     }
 
-    pub fn no_late_bound_regions<T>(self, value: &Binder<T>) -> Option<T>
-        where T : TypeFoldable<'tcx>
-    {
-        if value.0.has_escaping_regions() {
-            None
-        } else {
-            Some(value.0.clone())
-        }
-    }
-
     /// Returns a set of all late-bound regions that are constrained
     /// by `value`, meaning that if we instantiate those LBR with
     /// variables and equate `value` with something else, those
index caf78309cc2389721deaa871dddf354e39770adb..c115b573a1c062390edfd224421bf9990f6261ab 100644 (file)
@@ -680,6 +680,26 @@ pub fn map_bound<F, U>(self, f: F) -> Binder<U>
     {
         ty::Binder(f(self.0))
     }
+
+    /// Unwraps and returns the value within, but only if it contains
+    /// no bound regions at all. (In other words, if this binder --
+    /// and indeed any enclosing binder -- doesn't bind anything at
+    /// all.) Otherwise, returns `None`.
+    ///
+    /// (One could imagine having a method that just unwraps a single
+    /// binder, but permits late-bound regions bound by enclosing
+    /// binders, but that would require adjusting the debruijn
+    /// indices, and given the shallow binding structure we often use,
+    /// would not be that useful.)
+    pub fn no_late_bound_regions<'tcx>(self) -> Option<T>
+        where T : TypeFoldable<'tcx>
+    {
+        if self.skip_binder().has_escaping_regions() {
+            None
+        } else {
+            Some(self.skip_binder().clone())
+        }
+    }
 }
 
 /// Represents the projection of an associated type. In explicit UFCS
index 9ca044b764806f6a3a2e952e73d13bad28e38798..46193dedf8968055b62a2e7ac04b4929f5eb1e6c 100644 (file)
@@ -833,7 +833,7 @@ pub fn build_adt_ctor<'a, 'gcx, 'tcx>(infcx: &infer::InferCtxt<'a, 'gcx, 'tcx>,
     let tcx = infcx.tcx;
     let gcx = tcx.global_tcx();
     let def_id = tcx.hir.local_def_id(ctor_id);
-    let sig = gcx.no_late_bound_regions(&gcx.fn_sig(def_id))
+    let sig = gcx.fn_sig(def_id).no_late_bound_regions()
         .expect("LBR in ADT constructor signature");
     let sig = gcx.erase_regions(&sig);
     let param_env = gcx.param_env(def_id);
index 7027d827c84f5caf1404c53a3b620dc098f0ffb4..f8c45dd3d2570942843b6233ef0fccfa5b8a5636 100644 (file)
@@ -144,7 +144,7 @@ fn check_lang_item_type<'a, 'tcx, D>(
 {
     let did = tcx.require_lang_item(lang_item);
     let poly_sig = tcx.fn_sig(did);
-    let sig = tcx.no_late_bound_regions(&poly_sig).unwrap();
+    let sig = poly_sig.no_late_bound_regions().unwrap();
     let lhs_ty = lhs.ty(local_decls, tcx);
     let rhs_ty = rhs.ty(local_decls, tcx);
     let place_ty = place.ty(local_decls, tcx).to_ty(tcx);
index f03f782ebb45238cea8a967c82d23c4f4b8a199e..d5e4aa69c5b4e54d1bc60d7fea73ccbc761558f4 100644 (file)
@@ -800,7 +800,7 @@ fn check_pat_tuple_struct(&self,
         let pat_ty = self.instantiate_value_path(segments, opt_ty, def, pat.span, pat.id);
         // Replace constructor type with constructed type for tuple struct patterns.
         let pat_ty = pat_ty.fn_sig(tcx).output();
-        let pat_ty = tcx.no_late_bound_regions(&pat_ty).expect("expected fn type");
+        let pat_ty = pat_ty.no_late_bound_regions().expect("expected fn type");
 
         self.demand_eqtype(pat.span, expected, pat_ty);
 
index c1adb0e65a4da926ef09f76ce52e8311a3649485..23243c3ad66c0e49422b242e732bdcb33e37132e 100644 (file)
@@ -389,7 +389,7 @@ pub fn check_platform_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
                     let mut structural_to_nomimal = FxHashMap();
 
                     let sig = tcx.fn_sig(def_id);
-                    let sig = tcx.no_late_bound_regions(&sig).unwrap();
+                    let sig = sig.no_late_bound_regions().unwrap();
                     if intr.inputs.len() != sig.inputs().len() {
                         span_err!(tcx.sess, it.span, E0444,
                                   "platform-specific intrinsic has invalid number of \
index 7de29868d4341afb630b979c2df226b55ba03233..b754c981b2101ce8b96be5da95901e98df99b700 100644 (file)
@@ -202,7 +202,7 @@ fn projected_ty_from_poly_trait_ref(&self,
                                         poly_trait_ref: ty::PolyTraitRef<'tcx>)
                                         -> Ty<'tcx>
     {
-        if let Some(trait_ref) = self.tcx().no_late_bound_regions(&poly_trait_ref) {
+        if let Some(trait_ref) = poly_trait_ref.no_late_bound_regions() {
             self.tcx().mk_projection(item_def_id, trait_ref.substs)
         } else {
             // no late-bound regions, we can just ignore the binder