about summary refs log tree commit diff
path: root/compiler/rustc_borrowck
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2024-02-02 18:31:35 +0000
committerMichael Goulet <michael@errs.io>2024-02-02 18:31:35 +0000
commite951bcff96ac606aad3b7870c7fa64a4a48aa04b (patch)
treee16a077ac20f80211efed34d7afdc8082f971fb3 /compiler/rustc_borrowck
parenta371059933c11c79f9583ec149d56774e87b940f (diff)
downloadrust-e951bcff96ac606aad3b7870c7fa64a4a48aa04b.tar.gz
rust-e951bcff96ac606aad3b7870c7fa64a4a48aa04b.zip
Normalize the whole PolyTypeOutlivesPredicate, more simplifications
Diffstat (limited to 'compiler/rustc_borrowck')
-rw-r--r--compiler/rustc_borrowck/src/type_check/constraint_conversion.rs84
-rw-r--r--compiler/rustc_borrowck/src/type_check/free_region_relations.rs17
2 files changed, 49 insertions, 52 deletions
diff --git a/compiler/rustc_borrowck/src/type_check/constraint_conversion.rs b/compiler/rustc_borrowck/src/type_check/constraint_conversion.rs
index 4c224248945..c97e3170166 100644
--- a/compiler/rustc_borrowck/src/type_check/constraint_conversion.rs
+++ b/compiler/rustc_borrowck/src/type_check/constraint_conversion.rs
@@ -5,13 +5,11 @@ use rustc_infer::infer::outlives::obligations::{TypeOutlives, TypeOutlivesDelega
 use rustc_infer::infer::region_constraints::{GenericKind, VerifyBound};
 use rustc_infer::infer::{self, InferCtxt, SubregionOrigin};
 use rustc_middle::mir::{ClosureOutlivesSubject, ClosureRegionRequirements, ConstraintCategory};
+use rustc_middle::traits::query::NoSolution;
 use rustc_middle::traits::ObligationCause;
-use rustc_middle::ty::GenericArgKind;
-use rustc_middle::ty::{self, TyCtxt};
-use rustc_middle::ty::{TypeFoldable, TypeVisitableExt};
+use rustc_middle::ty::{self, GenericArgKind, Ty, TyCtxt, TypeFoldable, TypeVisitableExt};
 use rustc_span::{Span, DUMMY_SP};
 use rustc_trait_selection::solve::deeply_normalize;
-use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt;
 use rustc_trait_selection::traits::query::type_op::custom::CustomTypeOp;
 use rustc_trait_selection::traits::query::type_op::{TypeOp, TypeOpOutput};
 
@@ -146,7 +144,6 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
         let ConstraintConversion {
             tcx,
             infcx,
-            param_env,
             region_bound_pairs,
             implicit_region_bound,
             known_type_outlives_obligations,
@@ -178,43 +175,10 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
                         // Normalize the type we receive from a `TypeOutlives` obligation
                         // in the new trait solver.
                         if infcx.next_trait_solver() {
-                            let result = CustomTypeOp::new(
-                                |ocx| {
-                                    match deeply_normalize(
-                                        ocx.infcx.at(
-                                            &ObligationCause::dummy_with_span(self.span),
-                                            param_env,
-                                        ),
-                                        t1,
-                                    ) {
-                                        Ok(normalized_ty) => {
-                                            t1 = normalized_ty;
-                                        }
-                                        Err(e) => {
-                                            infcx.err_ctxt().report_fulfillment_errors(e);
-                                        }
-                                    }
-
-                                    Ok(())
-                                },
-                                "normalize type outlives obligation",
-                            )
-                            .fully_perform(infcx, self.span);
-
-                            match result {
-                                Ok(TypeOpOutput { output: (), constraints, .. }) => {
-                                    if let Some(constraints) = constraints {
-                                        assert!(
-                                            constraints.member_constraints.is_empty(),
-                                            "no member constraints expected from normalizing: {:#?}",
-                                            constraints.member_constraints
-                                        );
-                                        next_outlives_predicates
-                                            .extend(constraints.outlives.iter().copied());
-                                    }
-                                }
-                                Err(_) => {}
-                            }
+                            t1 = self.normalize_and_add_type_outlives_constraints(
+                                t1,
+                                &mut next_outlives_predicates,
+                            );
                         }
 
                         // we don't actually use this for anything, but
@@ -306,6 +270,42 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
         debug!("add_type_test(type_test={:?})", type_test);
         self.constraints.type_tests.push(type_test);
     }
+
+    fn normalize_and_add_type_outlives_constraints(
+        &self,
+        ty: Ty<'tcx>,
+        next_outlives_predicates: &mut Vec<(
+            ty::OutlivesPredicate<ty::GenericArg<'tcx>, ty::Region<'tcx>>,
+            ConstraintCategory<'tcx>,
+        )>,
+    ) -> Ty<'tcx> {
+        let result = CustomTypeOp::new(
+            |ocx| {
+                deeply_normalize(
+                    ocx.infcx.at(&ObligationCause::dummy_with_span(self.span), self.param_env),
+                    ty,
+                )
+                .map_err(|_| NoSolution)
+            },
+            "normalize type outlives obligation",
+        )
+        .fully_perform(self.infcx, self.span);
+
+        match result {
+            Ok(TypeOpOutput { output: ty, constraints, .. }) => {
+                if let Some(constraints) = constraints {
+                    assert!(
+                        constraints.member_constraints.is_empty(),
+                        "no member constraints expected from normalizing: {:#?}",
+                        constraints.member_constraints
+                    );
+                    next_outlives_predicates.extend(constraints.outlives.iter().copied());
+                }
+                ty
+            }
+            Err(_) => ty,
+        }
+    }
 }
 
 impl<'a, 'b, 'tcx> TypeOutlivesDelegate<'tcx> for &'a mut ConstraintConversion<'b, 'tcx> {
diff --git a/compiler/rustc_borrowck/src/type_check/free_region_relations.rs b/compiler/rustc_borrowck/src/type_check/free_region_relations.rs
index 4d53a53ee19..2e0caf44819 100644
--- a/compiler/rustc_borrowck/src/type_check/free_region_relations.rs
+++ b/compiler/rustc_borrowck/src/type_check/free_region_relations.rs
@@ -11,7 +11,7 @@ use rustc_middle::traits::query::OutlivesBound;
 use rustc_middle::traits::ObligationCause;
 use rustc_middle::ty::{self, RegionVid, Ty, TypeVisitableExt};
 use rustc_span::{ErrorGuaranteed, DUMMY_SP};
-use rustc_trait_selection::solve::deeply_normalize_with_skipped_universes;
+use rustc_trait_selection::solve::deeply_normalize;
 use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt;
 use rustc_trait_selection::traits::query::type_op::{self, TypeOp};
 use std::rc::Rc;
@@ -226,18 +226,16 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
         let mut constraints = vec![];
         let mut known_type_outlives_obligations = vec![];
         for bound in param_env.caller_bounds() {
-            let Some(outlives) = bound.as_type_outlives_clause() else { continue };
-            let ty::OutlivesPredicate(mut ty, region) = outlives.skip_binder();
+            let Some(mut outlives) = bound.as_type_outlives_clause() else { continue };
 
             // In the new solver, normalize the type-outlives obligation assumptions.
             if self.infcx.next_trait_solver() {
-                match deeply_normalize_with_skipped_universes(
+                match deeply_normalize(
                     self.infcx.at(&ObligationCause::misc(span, defining_ty_def_id), self.param_env),
-                    ty,
-                    vec![None; ty.outer_exclusive_binder().as_usize()],
+                    outlives,
                 ) {
-                    Ok(normalized_ty) => {
-                        ty = normalized_ty;
+                    Ok(normalized_outlives) => {
+                        outlives = normalized_outlives;
                     }
                     Err(e) => {
                         self.infcx.err_ctxt().report_fulfillment_errors(e);
@@ -245,8 +243,7 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
                 }
             }
 
-            known_type_outlives_obligations
-                .push(outlives.rebind(ty::OutlivesPredicate(ty, region)));
+            known_type_outlives_obligations.push(outlives);
         }
         let known_type_outlives_obligations =
             self.infcx.tcx.arena.alloc_slice(&known_type_outlives_obligations);