Bubble the opaque type ordering int opaque type handling

This commit is contained in:
Oli Scherer 2022-10-07 09:56:42 +00:00
parent 196a429a67
commit f3bd222ad9

View file

@ -103,7 +103,7 @@ impl<'tcx> InferCtxt<'tcx> {
return Ok(InferOk { value: (), obligations: vec![] });
}
let (a, b) = if a_is_expected { (a, b) } else { (b, a) };
let process = |a: Ty<'tcx>, b: Ty<'tcx>| match *a.kind() {
let process = |a: Ty<'tcx>, b: Ty<'tcx>, a_is_expected| match *a.kind() {
ty::Opaque(def_id, substs) if def_id.is_local() => {
let def_id = def_id.expect_local();
let origin = match self.defining_use_anchor {
@ -169,13 +169,14 @@ impl<'tcx> InferCtxt<'tcx> {
param_env,
b,
origin,
a_is_expected,
))
}
_ => None,
};
if let Some(res) = process(a, b) {
if let Some(res) = process(a, b, true) {
res
} else if let Some(res) = process(b, a) {
} else if let Some(res) = process(b, a, false) {
res
} else {
let (a, b) = self.resolve_vars_if_possible((a, b));
@ -514,13 +515,14 @@ impl UseKind {
impl<'tcx> InferCtxt<'tcx> {
#[instrument(skip(self), level = "debug")]
pub fn register_hidden_type(
fn register_hidden_type(
&self,
opaque_type_key: OpaqueTypeKey<'tcx>,
cause: ObligationCause<'tcx>,
param_env: ty::ParamEnv<'tcx>,
hidden_ty: Ty<'tcx>,
origin: hir::OpaqueTyOrigin,
a_is_expected: bool,
) -> InferResult<'tcx, ()> {
let tcx = self.tcx;
let OpaqueTypeKey { def_id, substs } = opaque_type_key;
@ -539,7 +541,8 @@ impl<'tcx> InferCtxt<'tcx> {
origin,
);
if let Some(prev) = prev {
obligations = self.at(&cause, param_env).eq(prev, hidden_ty)?.obligations;
obligations =
self.at(&cause, param_env).eq_exp(a_is_expected, prev, hidden_ty)?.obligations;
}
let item_bounds = tcx.bound_explicit_item_bounds(def_id.to_def_id());