@@ -105,13 +105,13 @@ pub fn unnormalized_obligations<'tcx>(
105105
106106/// Returns the obligations that make this trait reference
107107/// well-formed. For example, if there is a trait `Set` defined like
108- /// `trait Set<K:Eq>`, then the trait reference `Foo: Set<Bar>` is WF
108+ /// `trait Set<K: Eq>`, then the trait bound `Foo: Set<Bar>` is WF
109109/// if `Bar: Eq`.
110110pub fn trait_obligations < ' tcx > (
111111 infcx : & InferCtxt < ' tcx > ,
112112 param_env : ty:: ParamEnv < ' tcx > ,
113113 body_id : LocalDefId ,
114- trait_pred : & ty:: TraitPredicate < ' tcx > ,
114+ trait_pred : ty:: TraitPredicate < ' tcx > ,
115115 span : Span ,
116116 item : & ' tcx hir:: Item < ' tcx > ,
117117) -> Vec < traits:: PredicateObligation < ' tcx > > {
@@ -129,12 +129,17 @@ pub fn trait_obligations<'tcx>(
129129 wf. normalize ( infcx)
130130}
131131
132+ /// Returns the requirements for `clause` to be well-formed.
133+ ///
134+ /// For example, if there is a trait `Set` defined like
135+ /// `trait Set<K: Eq>`, then the trait bound `Foo: Set<Bar>` is WF
136+ /// if `Bar: Eq`.
132137#[ instrument( skip( infcx) , ret) ]
133- pub fn predicate_obligations < ' tcx > (
138+ pub fn clause_obligations < ' tcx > (
134139 infcx : & InferCtxt < ' tcx > ,
135140 param_env : ty:: ParamEnv < ' tcx > ,
136141 body_id : LocalDefId ,
137- predicate : ty:: Predicate < ' tcx > ,
142+ clause : ty:: Clause < ' tcx > ,
138143 span : Span ,
139144) -> Vec < traits:: PredicateObligation < ' tcx > > {
140145 let mut wf = WfPredicates {
@@ -148,45 +153,32 @@ pub fn predicate_obligations<'tcx>(
148153 } ;
149154
150155 // It's ok to skip the binder here because wf code is prepared for it
151- match predicate . kind ( ) . skip_binder ( ) {
152- ty:: PredicateKind :: Clause ( ty :: ClauseKind :: Trait ( t) ) => {
153- wf. compute_trait_pred ( & t, Elaborate :: None ) ;
156+ match clause . kind ( ) . skip_binder ( ) {
157+ ty:: ClauseKind :: Trait ( t) => {
158+ wf. compute_trait_pred ( t, Elaborate :: None ) ;
154159 }
155- ty:: PredicateKind :: Clause ( ty:: ClauseKind :: RegionOutlives ( ..) ) => { }
156- ty:: PredicateKind :: Clause ( ty:: ClauseKind :: TypeOutlives ( ty:: OutlivesPredicate (
157- ty,
158- _reg,
159- ) ) ) => {
160+ ty:: ClauseKind :: RegionOutlives ( ..) => { }
161+ ty:: ClauseKind :: TypeOutlives ( ty:: OutlivesPredicate ( ty, _reg) ) => {
160162 wf. compute ( ty. into ( ) ) ;
161163 }
162- ty:: PredicateKind :: Clause ( ty :: ClauseKind :: Projection ( t) ) => {
164+ ty:: ClauseKind :: Projection ( t) => {
163165 wf. compute_projection ( t. projection_ty ) ;
164166 wf. compute ( match t. term . unpack ( ) {
165167 ty:: TermKind :: Ty ( ty) => ty. into ( ) ,
166168 ty:: TermKind :: Const ( c) => c. into ( ) ,
167169 } )
168170 }
169- ty:: PredicateKind :: Clause ( ty :: ClauseKind :: ConstArgHasType ( ct, ty) ) => {
171+ ty:: ClauseKind :: ConstArgHasType ( ct, ty) => {
170172 wf. compute ( ct. into ( ) ) ;
171173 wf. compute ( ty. into ( ) ) ;
172174 }
173- ty:: PredicateKind :: Clause ( ty :: ClauseKind :: WellFormed ( arg) ) => {
175+ ty:: ClauseKind :: WellFormed ( arg) => {
174176 wf. compute ( arg) ;
175177 }
176178
177- ty:: PredicateKind :: Clause ( ty :: ClauseKind :: ConstEvaluatable ( ct) ) => {
179+ ty:: ClauseKind :: ConstEvaluatable ( ct) => {
178180 wf. compute ( ct. into ( ) ) ;
179181 }
180-
181- ty:: PredicateKind :: ObjectSafe ( _)
182- | ty:: PredicateKind :: ClosureKind ( ..)
183- | ty:: PredicateKind :: Subtype ( ..)
184- | ty:: PredicateKind :: Coerce ( ..)
185- | ty:: PredicateKind :: ConstEquate ( ..)
186- | ty:: PredicateKind :: Ambiguous
187- | ty:: PredicateKind :: AliasRelate ( ..) => {
188- bug ! ( "We should only wf check where clauses, unexpected predicate: {predicate:?}" )
189- }
190182 }
191183
192184 wf. normalize ( infcx)
@@ -233,7 +225,7 @@ enum Elaborate {
233225
234226fn extend_cause_with_original_assoc_item_obligation < ' tcx > (
235227 tcx : TyCtxt < ' tcx > ,
236- trait_ref : & ty:: TraitRef < ' tcx > ,
228+ trait_ref : ty:: TraitRef < ' tcx > ,
237229 item : Option < & hir:: Item < ' tcx > > ,
238230 cause : & mut traits:: ObligationCause < ' tcx > ,
239231 pred : ty:: Predicate < ' tcx > ,
@@ -336,9 +328,9 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
336328 }
337329
338330 /// Pushes the obligations required for `trait_ref` to be WF into `self.out`.
339- fn compute_trait_pred ( & mut self , trait_pred : & ty:: TraitPredicate < ' tcx > , elaborate : Elaborate ) {
331+ fn compute_trait_pred ( & mut self , trait_pred : ty:: TraitPredicate < ' tcx > , elaborate : Elaborate ) {
340332 let tcx = self . tcx ( ) ;
341- let trait_ref = & trait_pred. trait_ref ;
333+ let trait_ref = trait_pred. trait_ref ;
342334
343335 // Negative trait predicates don't require supertraits to hold, just
344336 // that their args are WF.
@@ -411,7 +403,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
411403
412404 // Compute the obligations that are required for `trait_ref` to be WF,
413405 // given that it is a *negative* trait predicate.
414- fn compute_negative_trait_pred ( & mut self , trait_ref : & ty:: TraitRef < ' tcx > ) {
406+ fn compute_negative_trait_pred ( & mut self , trait_ref : ty:: TraitRef < ' tcx > ) {
415407 for arg in trait_ref. args {
416408 self . compute ( arg) ;
417409 }
0 commit comments