Skip to content

Commit b2e6d08

Browse files
committed
use ocx type relation routines
1 parent f5f6761 commit b2e6d08

File tree

4 files changed

+28
-20
lines changed

4 files changed

+28
-20
lines changed

compiler/rustc_const_eval/src/util/compare_types.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ pub fn is_subtype<'tcx>(
4848
let cause = ObligationCause::dummy();
4949
let src = ocx.normalize(cause.clone(), param_env, src);
5050
let dest = ocx.normalize(cause.clone(), param_env, dest);
51-
let Ok(infer_ok) = infcx.at(&cause, param_env).sub(src, dest) else {
52-
return false;
51+
match ocx.sub(&cause, param_env, src, dest) {
52+
Ok(()) => {}
53+
Err(_) => return false,
5354
};
54-
let () = ocx.register_infer_ok_obligations(infer_ok);
5555
let errors = ocx.select_all_or_error();
5656
// With `Reveal::All`, opaque types get normalized away, with `Reveal::UserFacing`
5757
// we would get unification errors because we're unable to look into opaque types,

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,8 @@ fn check_opaque_meets_bounds<'tcx>(
451451

452452
let misc_cause = traits::ObligationCause::misc(span, hir_id);
453453

454-
match infcx.at(&misc_cause, param_env).eq(opaque_ty, hidden_ty) {
455-
Ok(infer_ok) => ocx.register_infer_ok_obligations(infer_ok),
454+
match ocx.eq(&misc_cause, param_env, opaque_ty, hidden_ty) {
455+
Ok(()) => {}
456456
Err(ty_err) => {
457457
tcx.sess.delay_span_bug(
458458
span,

compiler/rustc_hir_analysis/src/check/compare_method.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,8 @@ pub fn collect_trait_impl_trait_tys<'tcx>(
402402
unnormalized_trait_sig.inputs_and_output.iter().chain(trait_sig.inputs_and_output.iter()),
403403
);
404404

405-
match infcx.at(&cause, param_env).eq(trait_return_ty, impl_return_ty) {
406-
Ok(infer::InferOk { value: (), obligations }) => {
407-
ocx.register_obligations(obligations);
408-
}
405+
match ocx.eq(&cause, param_env, trait_return_ty, impl_return_ty) {
406+
Ok(()) => {}
409407
Err(terr) => {
410408
let mut diag = struct_span_err!(
411409
tcx.sess,
@@ -442,10 +440,8 @@ pub fn collect_trait_impl_trait_tys<'tcx>(
442440
// the lifetimes of the return type, but do this after unifying just the
443441
// return types, since we want to avoid duplicating errors from
444442
// `compare_predicate_entailment`.
445-
match infcx.at(&cause, param_env).eq(trait_fty, impl_fty) {
446-
Ok(infer::InferOk { value: (), obligations }) => {
447-
ocx.register_obligations(obligations);
448-
}
443+
match ocx.eq(&cause, param_env, trait_fty, impl_fty) {
444+
Ok(()) => {}
449445
Err(terr) => {
450446
// This function gets called during `compare_predicate_entailment` when normalizing a
451447
// signature that contains RPITIT. When the method signatures don't match, we have to

compiler/rustc_trait_selection/src/traits/engine.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,20 +125,32 @@ impl<'a, 'tcx> ObligationCtxt<'a, 'tcx> {
125125
.map(|infer_ok| self.register_infer_ok_obligations(infer_ok))
126126
}
127127

128+
/// Checks whether `expected` is a subtype of `actual`: `expected <: actual`.
129+
pub fn sub<T: ToTrace<'tcx>>(
130+
&self,
131+
cause: &ObligationCause<'tcx>,
132+
param_env: ty::ParamEnv<'tcx>,
133+
expected: T,
134+
actual: T,
135+
) -> Result<(), TypeError<'tcx>> {
136+
self.infcx
137+
.at(cause, param_env)
138+
.sup(expected, actual)
139+
.map(|infer_ok| self.register_infer_ok_obligations(infer_ok))
140+
}
141+
142+
/// Checks whether `expected` is a supertype of `actual`: `expected :> actual`.
128143
pub fn sup<T: ToTrace<'tcx>>(
129144
&self,
130145
cause: &ObligationCause<'tcx>,
131146
param_env: ty::ParamEnv<'tcx>,
132147
expected: T,
133148
actual: T,
134149
) -> Result<(), TypeError<'tcx>> {
135-
match self.infcx.at(cause, param_env).sup(expected, actual) {
136-
Ok(InferOk { obligations, value: () }) => {
137-
self.register_obligations(obligations);
138-
Ok(())
139-
}
140-
Err(e) => Err(e),
141-
}
150+
self.infcx
151+
.at(cause, param_env)
152+
.sup(expected, actual)
153+
.map(|infer_ok| self.register_infer_ok_obligations(infer_ok))
142154
}
143155

144156
pub fn select_where_possible(&self) -> Vec<FulfillmentError<'tcx>> {

0 commit comments

Comments
 (0)