no subtyping in the new trait solver

This commit is contained in:
Michael Goulet 2023-01-18 14:40:16 +00:00
parent 685c32fd85
commit 34127c5080
3 changed files with 23 additions and 34 deletions

View File

@ -1,10 +1,10 @@
use rustc_infer::infer::at::ToTrace; use rustc_infer::infer::at::ToTrace;
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; 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::query::NoSolution;
use rustc_infer::traits::ObligationCause; use rustc_infer::traits::ObligationCause;
use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind}; 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 rustc_span::DUMMY_SP;
use super::Goal; use super::Goal;
@ -26,12 +26,10 @@ pub(super) trait InferCtxtExt<'tcx> {
rhs: T, rhs: T,
) -> Result<Vec<Goal<'tcx, ty::Predicate<'tcx>>>, NoSolution>; ) -> Result<Vec<Goal<'tcx, ty::Predicate<'tcx>>>, NoSolution>;
fn sup<T: ToTrace<'tcx>>( fn instantiate_bound_vars_with_infer<T: TypeFoldable<'tcx> + Copy>(
&self, &self,
param_env: ty::ParamEnv<'tcx>, value: ty::Binder<'tcx, T>,
lhs: T, ) -> T;
rhs: T,
) -> Result<Vec<Goal<'tcx, ty::Predicate<'tcx>>>, NoSolution>;
} }
impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> { impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
@ -67,22 +65,14 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
}) })
} }
#[instrument(level = "debug", skip(self, param_env), ret)] fn instantiate_bound_vars_with_infer<T: TypeFoldable<'tcx> + Copy>(
fn sup<T: ToTrace<'tcx>>(
&self, &self,
param_env: ty::ParamEnv<'tcx>, value: ty::Binder<'tcx, T>,
lhs: T, ) -> T {
rhs: T, self.replace_bound_vars_with_fresh_vars(
) -> Result<Vec<Goal<'tcx, ty::Predicate<'tcx>>>, NoSolution> { DUMMY_SP,
self.at(&ObligationCause::dummy(), param_env) LateBoundRegionConversionTime::HigherRankedType,
.define_opaque_types(false) value,
.sup(lhs, rhs) )
.map(|InferOk { value: (), obligations }| {
obligations.into_iter().map(|o| o.into()).collect()
})
.map_err(|e| {
debug!(?e, "failed to sup");
NoSolution
})
} }
} }

View File

@ -6,7 +6,7 @@ use super::{Certainty, EvalCtxt, Goal, MaybeCause, QueryResult};
use rustc_errors::ErrorGuaranteed; use rustc_errors::ErrorGuaranteed;
use rustc_hir::def::DefKind; use rustc_hir::def::DefKind;
use rustc_hir::def_id::DefId; 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::query::NoSolution;
use rustc_infer::traits::specialization_graph::LeafDef; use rustc_infer::traits::specialization_graph::LeafDef;
use rustc_infer::traits::Reveal; use rustc_infer::traits::Reveal;
@ -297,12 +297,9 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
) -> QueryResult<'tcx> { ) -> QueryResult<'tcx> {
if let Some(poly_projection_pred) = assumption.to_opt_poly_projection_pred() { if let Some(poly_projection_pred) = assumption.to_opt_poly_projection_pred() {
ecx.infcx.probe(|_| { ecx.infcx.probe(|_| {
let assumption_projection_pred = ecx.infcx.replace_bound_vars_with_fresh_vars( let assumption_projection_pred =
DUMMY_SP, ecx.infcx.instantiate_bound_vars_with_infer(poly_projection_pred);
LateBoundRegionConversionTime::HigherRankedType, let nested_goals = ecx.infcx.eq(
poly_projection_pred,
);
let nested_goals = ecx.infcx.sup(
goal.param_env, goal.param_env,
goal.predicate.projection_ty, goal.predicate.projection_ty,
assumption_projection_pred.projection_ty, assumption_projection_pred.projection_ty,

View File

@ -10,8 +10,8 @@ use rustc_hir::{Movability, Mutability};
use rustc_infer::infer::InferCtxt; use rustc_infer::infer::InferCtxt;
use rustc_infer::traits::query::NoSolution; use rustc_infer::traits::query::NoSolution;
use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams}; use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams};
use rustc_middle::ty::TraitPredicate;
use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_middle::ty::{ToPolyTraitRef, TraitPredicate};
use rustc_span::DUMMY_SP; use rustc_span::DUMMY_SP;
impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> { impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
@ -67,10 +67,12 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
if let Some(poly_trait_pred) = assumption.to_opt_poly_trait_pred() { if let Some(poly_trait_pred) = assumption.to_opt_poly_trait_pred() {
// FIXME: Constness and polarity // FIXME: Constness and polarity
ecx.infcx.probe(|_| { 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, goal.param_env,
ty::Binder::dummy(goal.predicate.trait_ref), goal.predicate.trait_ref,
poly_trait_pred.to_poly_trait_ref(), assumption_trait_pred.trait_ref,
)?; )?;
ecx.evaluate_all_and_make_canonical_response(nested_goals) ecx.evaluate_all_and_make_canonical_response(nested_goals)
}) })