Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 22 additions & 38 deletions compiler/rustc_infer/src/infer/at.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl<'tcx> InferCtxt<'tcx> {
/// If possible, prefer the wrapper methods on `ObligationCtxt`,
/// `FnCtxt`, or `TypeChecker`.
pub fn sub_raw<T>(
self,
&self,
cause: &ObligationCause<'tcx>,
param_env: ParamEnv<'tcx>,
define_opaque_types: DefineOpaqueTypes,
Expand All @@ -181,7 +181,20 @@ impl<'tcx> InferCtxt<'tcx> {
where
T: ToTrace<'tcx>,
{
self.at(cause, param_env).sub(define_opaque_types, expected, actual)
if self.next_trait_solver {
NextSolverRelate::relate(self, param_env, expected, ty::Covariant, actual, cause.span)
.map(|goals| self.goals_to_obligations(cause, goals))
} else {
let mut op = TypeRelating::new(
self,
ToTrace::to_trace(cause, expected, actual),
param_env,
define_opaque_types,
ty::Covariant,
);
op.relate(expected, actual)?;
Ok(InferOk { value: (), obligations: op.into_obligations() })
}
}

/// Makes `expected == actual`.
Expand Down Expand Up @@ -288,41 +301,6 @@ pub trait ToTrace<'tcx>: Relate<TyCtxt<'tcx>> + Copy {
}

impl<'a, 'tcx> At<'a, 'tcx> {
/// Makes `expected <: actual`.
///
/// FIXME: To be removed in favor of the [`InferCtxt::sub_raw`] method instead.
pub fn sub<T>(
self,
define_opaque_types: DefineOpaqueTypes,
expected: T,
actual: T,
) -> InferResult<'tcx, ()>
where
T: ToTrace<'tcx>,
{
if self.infcx.next_trait_solver {
NextSolverRelate::relate(
self.infcx,
self.param_env,
expected,
ty::Covariant,
actual,
self.cause.span,
)
.map(|goals| self.goals_to_obligations(goals))
} else {
let mut op = TypeRelating::new(
self.infcx,
ToTrace::to_trace(self.cause, expected, actual),
self.param_env,
define_opaque_types,
ty::Covariant,
);
op.relate(expected, actual)?;
Ok(InferOk { value: (), obligations: op.into_obligations() })
}
}

/// Makes `expected == actual`.
///
/// FIXME: To be removed in favor of the [`InferCtxt::eq_raw`] method instead.
Expand Down Expand Up @@ -391,7 +369,13 @@ impl<'a, 'tcx> At<'a, 'tcx> {
T: ToTrace<'tcx>,
{
match variance {
ty::Covariant => self.sub(define_opaque_types, expected, actual),
ty::Covariant => self.infcx.sub_raw(
self.cause,
self.param_env,
define_opaque_types,
expected,
actual,
),
ty::Invariant => self.eq(define_opaque_types, expected, actual),
ty::Contravariant => self.infcx.sup_raw(
self.cause,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ impl<'tcx> InferCtxt<'tcx> {

self.enter_forall(predicate, |ty::SubtypePredicate { a_is_expected, a, b }| {
if a_is_expected {
Ok(self.at(cause, param_env).sub(DefineOpaqueTypes::Yes, a, b))
Ok(self.sub_raw(cause, param_env, DefineOpaqueTypes::Yes, a, b))
} else {
Ok(self.sup_raw(cause, param_env, DefineOpaqueTypes::Yes, b, a))
}
Expand Down
25 changes: 20 additions & 5 deletions compiler/rustc_infer/src/infer/relate/lattice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,30 @@ impl<'infcx, 'tcx> LatticeOp<'infcx, 'tcx> {
// relates `v` to `a` first, which may help us to avoid unnecessary
// type variable obligations. See caller for details.
fn relate_bound(&mut self, v: Ty<'tcx>, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, ()> {
let at = self.infcx.at(&self.trace.cause, self.param_env);
match self.kind {
LatticeOpKind::Glb => {
self.obligations.extend(at.sub(DefineOpaqueTypes::Yes, v, a)?.into_obligations());
self.obligations.extend(at.sub(DefineOpaqueTypes::Yes, v, b)?.into_obligations());
self.obligations.extend(
self.infcx
.sub_raw(&self.trace.cause, self.param_env, DefineOpaqueTypes::Yes, v, a)?
.into_obligations(),
);
self.obligations.extend(
self.infcx
.sub_raw(&self.trace.cause, self.param_env, DefineOpaqueTypes::Yes, v, b)?
.into_obligations(),
);
}
LatticeOpKind::Lub => {
self.obligations.extend(at.sub(DefineOpaqueTypes::Yes, a, v)?.into_obligations());
self.obligations.extend(at.sub(DefineOpaqueTypes::Yes, b, v)?.into_obligations());
self.obligations.extend(
self.infcx
.sub_raw(&self.trace.cause, self.param_env, DefineOpaqueTypes::Yes, a, v)?
.into_obligations(),
);
self.obligations.extend(
self.infcx
.sub_raw(&self.trace.cause, self.param_env, DefineOpaqueTypes::Yes, b, v)?
.into_obligations(),
);
}
}
Ok(())
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_trait_selection/src/traits/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,7 @@ where
actual: T,
) -> Result<(), TypeError<'tcx>> {
self.infcx
.at(cause, param_env)
.sub(DefineOpaqueTypes::Yes, expected, actual)
.sub_raw(cause, param_env, DefineOpaqueTypes::Yes, expected, actual)
.map(|infer_ok| self.register_infer_ok_obligations(infer_ok))
}

Expand Down
Loading