1 use crate::infer::InferCtxt;
2 use crate::traits::query::evaluate_obligation::InferCtxtExt;
3 use crate::traits::PredicateObligation;
4 use rustc_infer::traits::TraitEngine;
7 pub(crate) fn update<'tcx, T>(
9 infcx: &InferCtxt<'tcx>,
10 obligation: &PredicateObligation<'tcx>,
15 if let ty::PredicateKind::Trait(tpred) = obligation.predicate.kind().skip_binder()
16 && let Some(ty) = infcx.shallow_resolve(tpred.self_ty()).ty_vid().map(|t| infcx.root_var(t))
17 && infcx.tcx.lang_items().sized_trait().map_or(false, |st| st != tpred.trait_ref.def_id)
19 let new_self_ty = infcx.tcx.types.unit;
21 let trait_ref = ty::TraitRef {
22 substs: infcx.tcx.mk_substs_trait(new_self_ty, &tpred.trait_ref.substs[1..]),
26 // Then construct a new obligation with Self = () added
27 // to the ParamEnv, and see if it holds.
28 let o = obligation.with(infcx.tcx,
33 // (*) binder moved here
34 ty::PredicateKind::Trait(ty::TraitPredicate {
36 constness: tpred.constness,
37 polarity: tpred.polarity,
41 // Don't report overflow errors. Otherwise equivalent to may_hold.
42 if let Ok(result) = infcx.probe(|_| infcx.evaluate_obligation(&o)) && result.may_apply() {
43 engine.relationships().entry(ty).or_default().self_in_trait = true;
47 if let ty::PredicateKind::Projection(predicate) = obligation.predicate.kind().skip_binder() {
48 // If the projection predicate (Foo::Bar == X) has X as a non-TyVid,
49 // we need to make it into one.
50 if let Some(vid) = predicate.term.ty().and_then(|ty| ty.ty_vid()) {
51 debug!("relationship: {:?}.output = true", vid);
52 engine.relationships().entry(vid).or_default().output = true;