1 use crate::infer::InferCtxt;
2 use crate::traits::query::evaluate_obligation::InferCtxtExt;
3 use crate::traits::{ObligationCause, PredicateObligation};
4 use rustc_infer::traits::TraitEngine;
5 use rustc_middle::ty::{self, ToPredicate};
7 pub(crate) fn update<'tcx, T>(
9 infcx: &InferCtxt<'_, 'tcx>,
10 obligation: &PredicateObligation<'tcx>,
15 if let ty::PredicateKind::Trait(predicate) = obligation.predicate.kind().skip_binder() {
17 infcx.shallow_resolve(predicate.self_ty()).ty_vid().map(|t| infcx.root_var(t))
23 .map_or(false, |st| st != predicate.trait_ref.def_id)
25 let new_self_ty = infcx.tcx.types.unit;
27 let trait_ref = ty::TraitRef {
30 .mk_substs_trait(new_self_ty, &predicate.trait_ref.substs[1..]),
34 // Then contstruct a new obligation with Self = () added
35 // to the ParamEnv, and see if it holds.
36 let o = rustc_infer::traits::Obligation::new(
37 ObligationCause::dummy(),
43 // (*) binder moved here
44 ty::PredicateKind::Trait(ty::TraitPredicate {
46 constness: predicate.constness,
47 polarity: predicate.polarity,
50 .to_predicate(infcx.tcx),
52 // Don't report overflow errors. Otherwise equivalent to may_hold.
53 if let Ok(result) = infcx.probe(|_| infcx.evaluate_obligation(&o)) {
54 if result.may_apply() {
55 engine.relationships().entry(ty).or_default().self_in_trait = true;
62 if let ty::PredicateKind::Projection(predicate) = obligation.predicate.kind().skip_binder() {
63 // If the projection predicate (Foo::Bar == X) has X as a non-TyVid,
64 // we need to make it into one.
65 if let Some(vid) = predicate.term.ty().and_then(|ty| ty.ty_vid()) {
66 debug!("relationship: {:?}.output = true", vid);
67 engine.relationships().entry(vid).or_default().output = true;