Skip to content

Commit 34127c5

Browse files
no subtyping in the new trait solver
1 parent 685c32f commit 34127c5

File tree

3 files changed

+23
-34
lines changed

3 files changed

+23
-34
lines changed

compiler/rustc_trait_selection/src/solve/infcx_ext.rs

+13-23
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use rustc_infer::infer::at::ToTrace;
22
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
3-
use rustc_infer::infer::{InferCtxt, InferOk};
3+
use rustc_infer::infer::{InferCtxt, InferOk, LateBoundRegionConversionTime};
44
use rustc_infer::traits::query::NoSolution;
55
use rustc_infer::traits::ObligationCause;
66
use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind};
7-
use rustc_middle::ty::{self, Ty};
7+
use rustc_middle::ty::{self, Ty, TypeFoldable};
88
use rustc_span::DUMMY_SP;
99

1010
use super::Goal;
@@ -26,12 +26,10 @@ pub(super) trait InferCtxtExt<'tcx> {
2626
rhs: T,
2727
) -> Result<Vec<Goal<'tcx, ty::Predicate<'tcx>>>, NoSolution>;
2828

29-
fn sup<T: ToTrace<'tcx>>(
29+
fn instantiate_bound_vars_with_infer<T: TypeFoldable<'tcx> + Copy>(
3030
&self,
31-
param_env: ty::ParamEnv<'tcx>,
32-
lhs: T,
33-
rhs: T,
34-
) -> Result<Vec<Goal<'tcx, ty::Predicate<'tcx>>>, NoSolution>;
31+
value: ty::Binder<'tcx, T>,
32+
) -> T;
3533
}
3634

3735
impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
@@ -67,22 +65,14 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
6765
})
6866
}
6967

70-
#[instrument(level = "debug", skip(self, param_env), ret)]
71-
fn sup<T: ToTrace<'tcx>>(
68+
fn instantiate_bound_vars_with_infer<T: TypeFoldable<'tcx> + Copy>(
7269
&self,
73-
param_env: ty::ParamEnv<'tcx>,
74-
lhs: T,
75-
rhs: T,
76-
) -> Result<Vec<Goal<'tcx, ty::Predicate<'tcx>>>, NoSolution> {
77-
self.at(&ObligationCause::dummy(), param_env)
78-
.define_opaque_types(false)
79-
.sup(lhs, rhs)
80-
.map(|InferOk { value: (), obligations }| {
81-
obligations.into_iter().map(|o| o.into()).collect()
82-
})
83-
.map_err(|e| {
84-
debug!(?e, "failed to sup");
85-
NoSolution
86-
})
70+
value: ty::Binder<'tcx, T>,
71+
) -> T {
72+
self.replace_bound_vars_with_fresh_vars(
73+
DUMMY_SP,
74+
LateBoundRegionConversionTime::HigherRankedType,
75+
value,
76+
)
8777
}
8878
}

compiler/rustc_trait_selection/src/solve/project_goals.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use super::{Certainty, EvalCtxt, Goal, MaybeCause, QueryResult};
66
use rustc_errors::ErrorGuaranteed;
77
use rustc_hir::def::DefKind;
88
use rustc_hir::def_id::DefId;
9-
use rustc_infer::infer::{InferCtxt, LateBoundRegionConversionTime};
9+
use rustc_infer::infer::InferCtxt;
1010
use rustc_infer::traits::query::NoSolution;
1111
use rustc_infer::traits::specialization_graph::LeafDef;
1212
use rustc_infer::traits::Reveal;
@@ -297,12 +297,9 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
297297
) -> QueryResult<'tcx> {
298298
if let Some(poly_projection_pred) = assumption.to_opt_poly_projection_pred() {
299299
ecx.infcx.probe(|_| {
300-
let assumption_projection_pred = ecx.infcx.replace_bound_vars_with_fresh_vars(
301-
DUMMY_SP,
302-
LateBoundRegionConversionTime::HigherRankedType,
303-
poly_projection_pred,
304-
);
305-
let nested_goals = ecx.infcx.sup(
300+
let assumption_projection_pred =
301+
ecx.infcx.instantiate_bound_vars_with_infer(poly_projection_pred);
302+
let nested_goals = ecx.infcx.eq(
306303
goal.param_env,
307304
goal.predicate.projection_ty,
308305
assumption_projection_pred.projection_ty,

compiler/rustc_trait_selection/src/solve/trait_goals.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use rustc_hir::{Movability, Mutability};
1010
use rustc_infer::infer::InferCtxt;
1111
use rustc_infer::traits::query::NoSolution;
1212
use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams};
13+
use rustc_middle::ty::TraitPredicate;
1314
use rustc_middle::ty::{self, Ty, TyCtxt};
14-
use rustc_middle::ty::{ToPolyTraitRef, TraitPredicate};
1515
use rustc_span::DUMMY_SP;
1616

1717
impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
@@ -67,10 +67,12 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
6767
if let Some(poly_trait_pred) = assumption.to_opt_poly_trait_pred() {
6868
// FIXME: Constness and polarity
6969
ecx.infcx.probe(|_| {
70-
let nested_goals = ecx.infcx.sup(
70+
let assumption_trait_pred =
71+
ecx.infcx.instantiate_bound_vars_with_infer(poly_trait_pred);
72+
let nested_goals = ecx.infcx.eq(
7173
goal.param_env,
72-
ty::Binder::dummy(goal.predicate.trait_ref),
73-
poly_trait_pred.to_poly_trait_ref(),
74+
goal.predicate.trait_ref,
75+
assumption_trait_pred.trait_ref,
7476
)?;
7577
ecx.evaluate_all_and_make_canonical_response(nested_goals)
7678
})

0 commit comments

Comments
 (0)