use super::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
use super::InferCtxt;
-use crate::traits::ObligationCause;
+use crate::traits::{ObligationCause, PredicateObligation};
use rustc_middle::ty::relate::{RelateResult, TypeRelation};
use rustc_middle::ty::TyVar;
use rustc_middle::ty::{self, Ty};
fn cause(&self) -> &ObligationCause<'tcx>;
+ fn add_obligations(&mut self, obligations: Vec<PredicateObligation<'tcx>>);
+
+ fn define_opaque_types(&self) -> bool;
+
// Relates the type `v` to `a` and `b` such that `v` represents
// the LUB/GLB of `a` and `b` as appropriate.
//
}
/// Relates two types using a given lattice.
+#[instrument(skip(this), level = "debug")]
pub fn super_lattice_tys<'a, 'tcx: 'a, L>(
this: &mut L,
a: Ty<'tcx>,
where
L: LatticeDir<'a, 'tcx>,
{
- debug!("{}.lattice_tys({:?}, {:?})", this.tag(), a, b);
+ debug!("{}", this.tag());
if a == b {
return Ok(a);
}
let infcx = this.infcx();
+
let a = infcx.inner.borrow_mut().type_variables().replace_if_possible(a);
let b = infcx.inner.borrow_mut().type_variables().replace_if_possible(b);
+
match (a.kind(), b.kind()) {
// If one side is known to be a variable and one is not,
// create a variable (`v`) to represent the LUB. Make sure to
// But if we did in reverse order, we would create a `v <:
// LHS` (or vice versa) constraint and then instantiate
// `v`. This would require further processing to achieve same
- // end-result; in partiular, this screws up some of the logic
+ // end-result; in particular, this screws up some of the logic
// in coercion, which expects LUB to figure out that the LHS
// is (e.g.) `Box<i32>`. A more obvious solution might be to
// iterate on the subtype obligations that are returned, but I
Ok(v)
}
+ (&ty::Opaque(a_def_id, _), &ty::Opaque(b_def_id, _)) if a_def_id == b_def_id => {
+ infcx.super_combine_tys(this, a, b)
+ }
+ (&ty::Opaque(did, ..), _) | (_, &ty::Opaque(did, ..))
+ if this.define_opaque_types() && did.is_local() =>
+ {
+ this.add_obligations(
+ infcx
+ .handle_opaque_type(a, b, this.a_is_expected(), this.cause(), this.param_env())?
+ .obligations,
+ );
+ Ok(a)
+ }
+
_ => infcx.super_combine_tys(this, a, b),
}
}