]>
Commit | Line | Data |
---|---|---|
c295e0f8 XL |
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}; | |
6 | ||
7 | pub(crate) fn update<'tcx, T>( | |
8 | engine: &mut T, | |
9 | infcx: &InferCtxt<'_, 'tcx>, | |
10 | obligation: &PredicateObligation<'tcx>, | |
11 | ) where | |
12 | T: TraitEngine<'tcx>, | |
13 | { | |
14 | // (*) binder skipped | |
5e7ed085 FG |
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) | |
18 | { | |
19 | let new_self_ty = infcx.tcx.types.unit; | |
c295e0f8 | 20 | |
5e7ed085 FG |
21 | let trait_ref = ty::TraitRef { |
22 | substs: infcx.tcx.mk_substs_trait(new_self_ty, &tpred.trait_ref.substs[1..]), | |
23 | ..tpred.trait_ref | |
24 | }; | |
c295e0f8 | 25 | |
5e7ed085 FG |
26 | // Then construct a new obligation with Self = () added |
27 | // to the ParamEnv, and see if it holds. | |
28 | let o = rustc_infer::traits::Obligation::new( | |
29 | ObligationCause::dummy(), | |
30 | obligation.param_env, | |
31 | obligation | |
32 | .predicate | |
33 | .kind() | |
34 | .map_bound(|_| { | |
35 | // (*) binder moved here | |
36 | ty::PredicateKind::Trait(ty::TraitPredicate { | |
37 | trait_ref, | |
38 | constness: tpred.constness, | |
39 | polarity: tpred.polarity, | |
40 | }) | |
41 | }) | |
42 | .to_predicate(infcx.tcx), | |
43 | ); | |
44 | // Don't report overflow errors. Otherwise equivalent to may_hold. | |
45 | if let Ok(result) = infcx.probe(|_| infcx.evaluate_obligation(&o)) && result.may_apply() { | |
46 | engine.relationships().entry(ty).or_default().self_in_trait = true; | |
c295e0f8 XL |
47 | } |
48 | } | |
49 | ||
50 | if let ty::PredicateKind::Projection(predicate) = obligation.predicate.kind().skip_binder() { | |
51 | // If the projection predicate (Foo::Bar == X) has X as a non-TyVid, | |
52 | // we need to make it into one. | |
5099ac24 | 53 | if let Some(vid) = predicate.term.ty().and_then(|ty| ty.ty_vid()) { |
c295e0f8 XL |
54 | debug!("relationship: {:?}.output = true", vid); |
55 | engine.relationships().entry(vid).or_default().output = true; | |
56 | } | |
57 | } | |
58 | } |