use ocx
type relation routines
This commit is contained in:
parent
f5f67618e2
commit
b2e6d08e3f
4 changed files with 28 additions and 20 deletions
|
@ -48,10 +48,10 @@ pub fn is_subtype<'tcx>(
|
||||||
let cause = ObligationCause::dummy();
|
let cause = ObligationCause::dummy();
|
||||||
let src = ocx.normalize(cause.clone(), param_env, src);
|
let src = ocx.normalize(cause.clone(), param_env, src);
|
||||||
let dest = ocx.normalize(cause.clone(), param_env, dest);
|
let dest = ocx.normalize(cause.clone(), param_env, dest);
|
||||||
let Ok(infer_ok) = infcx.at(&cause, param_env).sub(src, dest) else {
|
match ocx.sub(&cause, param_env, src, dest) {
|
||||||
return false;
|
Ok(()) => {}
|
||||||
|
Err(_) => return false,
|
||||||
};
|
};
|
||||||
let () = ocx.register_infer_ok_obligations(infer_ok);
|
|
||||||
let errors = ocx.select_all_or_error();
|
let errors = ocx.select_all_or_error();
|
||||||
// With `Reveal::All`, opaque types get normalized away, with `Reveal::UserFacing`
|
// With `Reveal::All`, opaque types get normalized away, with `Reveal::UserFacing`
|
||||||
// we would get unification errors because we're unable to look into opaque types,
|
// we would get unification errors because we're unable to look into opaque types,
|
||||||
|
|
|
@ -451,8 +451,8 @@ fn check_opaque_meets_bounds<'tcx>(
|
||||||
|
|
||||||
let misc_cause = traits::ObligationCause::misc(span, hir_id);
|
let misc_cause = traits::ObligationCause::misc(span, hir_id);
|
||||||
|
|
||||||
match infcx.at(&misc_cause, param_env).eq(opaque_ty, hidden_ty) {
|
match ocx.eq(&misc_cause, param_env, opaque_ty, hidden_ty) {
|
||||||
Ok(infer_ok) => ocx.register_infer_ok_obligations(infer_ok),
|
Ok(()) => {}
|
||||||
Err(ty_err) => {
|
Err(ty_err) => {
|
||||||
tcx.sess.delay_span_bug(
|
tcx.sess.delay_span_bug(
|
||||||
span,
|
span,
|
||||||
|
|
|
@ -402,10 +402,8 @@ pub fn collect_trait_impl_trait_tys<'tcx>(
|
||||||
unnormalized_trait_sig.inputs_and_output.iter().chain(trait_sig.inputs_and_output.iter()),
|
unnormalized_trait_sig.inputs_and_output.iter().chain(trait_sig.inputs_and_output.iter()),
|
||||||
);
|
);
|
||||||
|
|
||||||
match infcx.at(&cause, param_env).eq(trait_return_ty, impl_return_ty) {
|
match ocx.eq(&cause, param_env, trait_return_ty, impl_return_ty) {
|
||||||
Ok(infer::InferOk { value: (), obligations }) => {
|
Ok(()) => {}
|
||||||
ocx.register_obligations(obligations);
|
|
||||||
}
|
|
||||||
Err(terr) => {
|
Err(terr) => {
|
||||||
let mut diag = struct_span_err!(
|
let mut diag = struct_span_err!(
|
||||||
tcx.sess,
|
tcx.sess,
|
||||||
|
@ -442,10 +440,8 @@ pub fn collect_trait_impl_trait_tys<'tcx>(
|
||||||
// the lifetimes of the return type, but do this after unifying just the
|
// the lifetimes of the return type, but do this after unifying just the
|
||||||
// return types, since we want to avoid duplicating errors from
|
// return types, since we want to avoid duplicating errors from
|
||||||
// `compare_predicate_entailment`.
|
// `compare_predicate_entailment`.
|
||||||
match infcx.at(&cause, param_env).eq(trait_fty, impl_fty) {
|
match ocx.eq(&cause, param_env, trait_fty, impl_fty) {
|
||||||
Ok(infer::InferOk { value: (), obligations }) => {
|
Ok(()) => {}
|
||||||
ocx.register_obligations(obligations);
|
|
||||||
}
|
|
||||||
Err(terr) => {
|
Err(terr) => {
|
||||||
// This function gets called during `compare_predicate_entailment` when normalizing a
|
// This function gets called during `compare_predicate_entailment` when normalizing a
|
||||||
// signature that contains RPITIT. When the method signatures don't match, we have to
|
// signature that contains RPITIT. When the method signatures don't match, we have to
|
||||||
|
|
|
@ -125,6 +125,21 @@ impl<'a, 'tcx> ObligationCtxt<'a, 'tcx> {
|
||||||
.map(|infer_ok| self.register_infer_ok_obligations(infer_ok))
|
.map(|infer_ok| self.register_infer_ok_obligations(infer_ok))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Checks whether `expected` is a subtype of `actual`: `expected <: actual`.
|
||||||
|
pub fn sub<T: ToTrace<'tcx>>(
|
||||||
|
&self,
|
||||||
|
cause: &ObligationCause<'tcx>,
|
||||||
|
param_env: ty::ParamEnv<'tcx>,
|
||||||
|
expected: T,
|
||||||
|
actual: T,
|
||||||
|
) -> Result<(), TypeError<'tcx>> {
|
||||||
|
self.infcx
|
||||||
|
.at(cause, param_env)
|
||||||
|
.sup(expected, actual)
|
||||||
|
.map(|infer_ok| self.register_infer_ok_obligations(infer_ok))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Checks whether `expected` is a supertype of `actual`: `expected :> actual`.
|
||||||
pub fn sup<T: ToTrace<'tcx>>(
|
pub fn sup<T: ToTrace<'tcx>>(
|
||||||
&self,
|
&self,
|
||||||
cause: &ObligationCause<'tcx>,
|
cause: &ObligationCause<'tcx>,
|
||||||
|
@ -132,13 +147,10 @@ impl<'a, 'tcx> ObligationCtxt<'a, 'tcx> {
|
||||||
expected: T,
|
expected: T,
|
||||||
actual: T,
|
actual: T,
|
||||||
) -> Result<(), TypeError<'tcx>> {
|
) -> Result<(), TypeError<'tcx>> {
|
||||||
match self.infcx.at(cause, param_env).sup(expected, actual) {
|
self.infcx
|
||||||
Ok(InferOk { obligations, value: () }) => {
|
.at(cause, param_env)
|
||||||
self.register_obligations(obligations);
|
.sup(expected, actual)
|
||||||
Ok(())
|
.map(|infer_ok| self.register_infer_ok_obligations(infer_ok))
|
||||||
}
|
|
||||||
Err(e) => Err(e),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn select_where_possible(&self) -> Vec<FulfillmentError<'tcx>> {
|
pub fn select_where_possible(&self) -> Vec<FulfillmentError<'tcx>> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue