]> git.proxmox.com Git - rustc.git/blame - compiler/rustc_trait_selection/src/traits/relationships.rs
New upstream version 1.68.2+dfsg1
[rustc.git] / compiler / rustc_trait_selection / src / traits / relationships.rs
CommitLineData
c295e0f8
XL
1use crate::infer::InferCtxt;
2use crate::traits::query::evaluate_obligation::InferCtxtExt;
487cf647 3use crate::traits::PredicateObligation;
c295e0f8 4use rustc_infer::traits::TraitEngine;
487cf647 5use rustc_middle::ty;
c295e0f8
XL
6
7pub(crate) fn update<'tcx, T>(
8 engine: &mut T,
2b03887a 9 infcx: &InferCtxt<'tcx>,
c295e0f8
XL
10 obligation: &PredicateObligation<'tcx>,
11) where
12 T: TraitEngine<'tcx>,
13{
14 // (*) binder skipped
487cf647 15 if let ty::PredicateKind::Clause(ty::Clause::Trait(tpred)) = obligation.predicate.kind().skip_binder()
5e7ed085
FG
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 // Then construct a new obligation with Self = () added
22 // to the ParamEnv, and see if it holds.
487cf647 23 let o = obligation.with(infcx.tcx,
5e7ed085
FG
24 obligation
25 .predicate
26 .kind()
064997fb 27 .rebind(
5e7ed085 28 // (*) binder moved here
9c376795 29 ty::PredicateKind::Clause(ty::Clause::Trait(tpred.with_self_ty(infcx.tcx, new_self_ty)))
487cf647 30 ),
5e7ed085
FG
31 );
32 // Don't report overflow errors. Otherwise equivalent to may_hold.
33 if let Ok(result) = infcx.probe(|_| infcx.evaluate_obligation(&o)) && result.may_apply() {
34 engine.relationships().entry(ty).or_default().self_in_trait = true;
c295e0f8
XL
35 }
36 }
37
487cf647
FG
38 if let ty::PredicateKind::Clause(ty::Clause::Projection(predicate)) =
39 obligation.predicate.kind().skip_binder()
40 {
c295e0f8
XL
41 // If the projection predicate (Foo::Bar == X) has X as a non-TyVid,
42 // we need to make it into one.
5099ac24 43 if let Some(vid) = predicate.term.ty().and_then(|ty| ty.ty_vid()) {
c295e0f8
XL
44 debug!("relationship: {:?}.output = true", vid);
45 engine.relationships().entry(vid).or_default().output = true;
46 }
47 }
48}