diff --git a/compiler/rustc_infer/src/infer/at.rs b/compiler/rustc_infer/src/infer/at.rs index 8eabbc0dcb06f..0dfadda1f3958 100644 --- a/compiler/rustc_infer/src/infer/at.rs +++ b/compiler/rustc_infer/src/infer/at.rs @@ -171,7 +171,7 @@ impl<'tcx> InferCtxt<'tcx> { /// If possible, prefer the wrapper methods on `ObligationCtxt`, /// `FnCtxt`, or `TypeChecker`. pub fn sub_raw( - self, + &self, cause: &ObligationCause<'tcx>, param_env: ParamEnv<'tcx>, define_opaque_types: DefineOpaqueTypes, @@ -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`. @@ -288,41 +301,6 @@ pub trait ToTrace<'tcx>: Relate> + 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( - 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. @@ -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, diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index 76234c7459f84..7623a591f2b39 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -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)) } diff --git a/compiler/rustc_infer/src/infer/relate/lattice.rs b/compiler/rustc_infer/src/infer/relate/lattice.rs index 648bccbb618bc..875631eef1f65 100644 --- a/compiler/rustc_infer/src/infer/relate/lattice.rs +++ b/compiler/rustc_infer/src/infer/relate/lattice.rs @@ -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(()) diff --git a/compiler/rustc_trait_selection/src/traits/engine.rs b/compiler/rustc_trait_selection/src/traits/engine.rs index 8f57c3c222d6a..a2afa9faea97f 100644 --- a/compiler/rustc_trait_selection/src/traits/engine.rs +++ b/compiler/rustc_trait_selection/src/traits/engine.rs @@ -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)) }