about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2022-05-16 14:23:52 +0000
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2022-05-16 14:23:52 +0000
commit14da30e3e68999021a42bab470865b044409fb68 (patch)
treeba7ae21ecd0531e26d166aa2149f7169c003d2d2
parent340e708634e7cc560c04e27b91297ff04f897683 (diff)
downloadrust-14da30e3e68999021a42bab470865b044409fb68.tar.gz
rust-14da30e3e68999021a42bab470865b044409fb68.zip
Split some logic from a loop into a separate function
-rw-r--r--compiler/rustc_infer/src/infer/canonical/query_response.rs43
1 files changed, 26 insertions, 17 deletions
diff --git a/compiler/rustc_infer/src/infer/canonical/query_response.rs b/compiler/rustc_infer/src/infer/canonical/query_response.rs
index 5671711397a..ec468f42852 100644
--- a/compiler/rustc_infer/src/infer/canonical/query_response.rs
+++ b/compiler/rustc_infer/src/infer/canonical/query_response.rs
@@ -547,25 +547,34 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
     ) -> impl Iterator<Item = PredicateObligation<'tcx>> + 'a + Captures<'tcx> {
         unsubstituted_region_constraints.iter().map(move |&constraint| {
             let predicate = substitute_value(self.tcx, result_subst, constraint);
-            let ty::OutlivesPredicate(k1, r2) = predicate.skip_binder();
+            self.query_outlives_constraint_to_obligation(predicate, cause.clone(), param_env)
+        })
+    }
 
-            let atom = match k1.unpack() {
-                GenericArgKind::Lifetime(r1) => {
-                    ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(r1, r2))
-                }
-                GenericArgKind::Type(t1) => {
-                    ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(t1, r2))
-                }
-                GenericArgKind::Const(..) => {
-                    // Consts cannot outlive one another, so we don't expect to
-                    // encounter this branch.
-                    span_bug!(cause.span, "unexpected const outlives {:?}", constraint);
-                }
-            };
-            let predicate = predicate.rebind(atom).to_predicate(self.tcx);
+    pub fn query_outlives_constraint_to_obligation(
+        &self,
+        predicate: QueryOutlivesConstraint<'tcx>,
+        cause: ObligationCause<'tcx>,
+        param_env: ty::ParamEnv<'tcx>,
+    ) -> Obligation<'tcx, ty::Predicate<'tcx>> {
+        let ty::OutlivesPredicate(k1, r2) = predicate.skip_binder();
 
-            Obligation::new(cause.clone(), param_env, predicate)
-        })
+        let atom = match k1.unpack() {
+            GenericArgKind::Lifetime(r1) => {
+                ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(r1, r2))
+            }
+            GenericArgKind::Type(t1) => {
+                ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(t1, r2))
+            }
+            GenericArgKind::Const(..) => {
+                // Consts cannot outlive one another, so we don't expect to
+                // encounter this branch.
+                span_bug!(cause.span, "unexpected const outlives {:?}", predicate);
+            }
+        };
+        let predicate = predicate.rebind(atom).to_predicate(self.tcx);
+
+        Obligation::new(cause, param_env, predicate)
     }
 
     /// Given two sets of values for the same set of canonical variables, unify them.