]> git.lizzy.rs Git - rust.git/commitdiff
no subtyping in the new trait solver
authorMichael Goulet <michael@errs.io>
Wed, 18 Jan 2023 14:40:16 +0000 (14:40 +0000)
committerMichael Goulet <michael@errs.io>
Wed, 18 Jan 2023 14:59:15 +0000 (14:59 +0000)
compiler/rustc_trait_selection/src/solve/infcx_ext.rs
compiler/rustc_trait_selection/src/solve/project_goals.rs
compiler/rustc_trait_selection/src/solve/trait_goals.rs

index 47e6c93016a0e053e1b2f581e82849e479709ffa..42f597c781d257e0f97506d931d5121b5d5a83fd 100644 (file)
@@ -1,10 +1,10 @@
 use rustc_infer::infer::at::ToTrace;
 use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
-use rustc_infer::infer::{InferCtxt, InferOk};
+use rustc_infer::infer::{InferCtxt, InferOk, LateBoundRegionConversionTime};
 use rustc_infer::traits::query::NoSolution;
 use rustc_infer::traits::ObligationCause;
 use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind};
-use rustc_middle::ty::{self, Ty};
+use rustc_middle::ty::{self, Ty, TypeFoldable};
 use rustc_span::DUMMY_SP;
 
 use super::Goal;
@@ -26,12 +26,10 @@ fn eq<T: ToTrace<'tcx>>(
         rhs: T,
     ) -> Result<Vec<Goal<'tcx, ty::Predicate<'tcx>>>, NoSolution>;
 
-    fn sup<T: ToTrace<'tcx>>(
+    fn instantiate_bound_vars_with_infer<T: TypeFoldable<'tcx> + Copy>(
         &self,
-        param_env: ty::ParamEnv<'tcx>,
-        lhs: T,
-        rhs: T,
-    ) -> Result<Vec<Goal<'tcx, ty::Predicate<'tcx>>>, NoSolution>;
+        value: ty::Binder<'tcx, T>,
+    ) -> T;
 }
 
 impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
@@ -67,22 +65,14 @@ fn eq<T: ToTrace<'tcx>>(
             })
     }
 
-    #[instrument(level = "debug", skip(self, param_env), ret)]
-    fn sup<T: ToTrace<'tcx>>(
+    fn instantiate_bound_vars_with_infer<T: TypeFoldable<'tcx> + Copy>(
         &self,
-        param_env: ty::ParamEnv<'tcx>,
-        lhs: T,
-        rhs: T,
-    ) -> Result<Vec<Goal<'tcx, ty::Predicate<'tcx>>>, NoSolution> {
-        self.at(&ObligationCause::dummy(), param_env)
-            .define_opaque_types(false)
-            .sup(lhs, rhs)
-            .map(|InferOk { value: (), obligations }| {
-                obligations.into_iter().map(|o| o.into()).collect()
-            })
-            .map_err(|e| {
-                debug!(?e, "failed to sup");
-                NoSolution
-            })
+        value: ty::Binder<'tcx, T>,
+    ) -> T {
+        self.replace_bound_vars_with_fresh_vars(
+            DUMMY_SP,
+            LateBoundRegionConversionTime::HigherRankedType,
+            value,
+        )
     }
 }
index 5c1f3f02e93a84b19a431ec981163c7f79c53c35..00c7edf0ef8a354d6a038725c9aadf7e62b0830d 100644 (file)
@@ -6,7 +6,7 @@
 use rustc_errors::ErrorGuaranteed;
 use rustc_hir::def::DefKind;
 use rustc_hir::def_id::DefId;
-use rustc_infer::infer::{InferCtxt, LateBoundRegionConversionTime};
+use rustc_infer::infer::InferCtxt;
 use rustc_infer::traits::query::NoSolution;
 use rustc_infer::traits::specialization_graph::LeafDef;
 use rustc_infer::traits::Reveal;
@@ -297,12 +297,9 @@ fn consider_assumption(
     ) -> QueryResult<'tcx> {
         if let Some(poly_projection_pred) = assumption.to_opt_poly_projection_pred() {
             ecx.infcx.probe(|_| {
-                let assumption_projection_pred = ecx.infcx.replace_bound_vars_with_fresh_vars(
-                    DUMMY_SP,
-                    LateBoundRegionConversionTime::HigherRankedType,
-                    poly_projection_pred,
-                );
-                let nested_goals = ecx.infcx.sup(
+                let assumption_projection_pred =
+                    ecx.infcx.instantiate_bound_vars_with_infer(poly_projection_pred);
+                let nested_goals = ecx.infcx.eq(
                     goal.param_env,
                     goal.predicate.projection_ty,
                     assumption_projection_pred.projection_ty,
index 4d94265dc07f5cc5b638c484bced6d40c4cb2437..d89759f4dd4877d0e71292f1e5af91035bac22ed 100644 (file)
@@ -10,8 +10,8 @@
 use rustc_infer::infer::InferCtxt;
 use rustc_infer::traits::query::NoSolution;
 use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams};
+use rustc_middle::ty::TraitPredicate;
 use rustc_middle::ty::{self, Ty, TyCtxt};
-use rustc_middle::ty::{ToPolyTraitRef, TraitPredicate};
 use rustc_span::DUMMY_SP;
 
 impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
@@ -67,10 +67,12 @@ fn consider_assumption(
         if let Some(poly_trait_pred) = assumption.to_opt_poly_trait_pred() {
             // FIXME: Constness and polarity
             ecx.infcx.probe(|_| {
-                let nested_goals = ecx.infcx.sup(
+                let assumption_trait_pred =
+                    ecx.infcx.instantiate_bound_vars_with_infer(poly_trait_pred);
+                let nested_goals = ecx.infcx.eq(
                     goal.param_env,
-                    ty::Binder::dummy(goal.predicate.trait_ref),
-                    poly_trait_pred.to_poly_trait_ref(),
+                    goal.predicate.trait_ref,
+                    assumption_trait_pred.trait_ref,
                 )?;
                 ecx.evaluate_all_and_make_canonical_response(nested_goals)
             })