@@ -105,13 +105,13 @@ pub fn unnormalized_obligations<'tcx>(
105
105
106
106
/// Returns the obligations that make this trait reference
107
107
/// 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
109
109
/// if `Bar: Eq`.
110
110
pub fn trait_obligations < ' tcx > (
111
111
infcx : & InferCtxt < ' tcx > ,
112
112
param_env : ty:: ParamEnv < ' tcx > ,
113
113
body_id : LocalDefId ,
114
- trait_pred : & ty:: TraitPredicate < ' tcx > ,
114
+ trait_pred : ty:: TraitPredicate < ' tcx > ,
115
115
span : Span ,
116
116
item : & ' tcx hir:: Item < ' tcx > ,
117
117
) -> Vec < traits:: PredicateObligation < ' tcx > > {
@@ -129,12 +129,17 @@ pub fn trait_obligations<'tcx>(
129
129
wf. normalize ( infcx)
130
130
}
131
131
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`.
132
137
#[ instrument( skip( infcx) , ret) ]
133
- pub fn predicate_obligations < ' tcx > (
138
+ pub fn clause_obligations < ' tcx > (
134
139
infcx : & InferCtxt < ' tcx > ,
135
140
param_env : ty:: ParamEnv < ' tcx > ,
136
141
body_id : LocalDefId ,
137
- predicate : ty:: Predicate < ' tcx > ,
142
+ clause : ty:: Clause < ' tcx > ,
138
143
span : Span ,
139
144
) -> Vec < traits:: PredicateObligation < ' tcx > > {
140
145
let mut wf = WfPredicates {
@@ -148,45 +153,32 @@ pub fn predicate_obligations<'tcx>(
148
153
} ;
149
154
150
155
// 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 ) ;
154
159
}
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) ) => {
160
162
wf. compute ( ty. into ( ) ) ;
161
163
}
162
- ty:: PredicateKind :: Clause ( ty :: ClauseKind :: Projection ( t) ) => {
164
+ ty:: ClauseKind :: Projection ( t) => {
163
165
wf. compute_projection ( t. projection_ty ) ;
164
166
wf. compute ( match t. term . unpack ( ) {
165
167
ty:: TermKind :: Ty ( ty) => ty. into ( ) ,
166
168
ty:: TermKind :: Const ( c) => c. into ( ) ,
167
169
} )
168
170
}
169
- ty:: PredicateKind :: Clause ( ty :: ClauseKind :: ConstArgHasType ( ct, ty) ) => {
171
+ ty:: ClauseKind :: ConstArgHasType ( ct, ty) => {
170
172
wf. compute ( ct. into ( ) ) ;
171
173
wf. compute ( ty. into ( ) ) ;
172
174
}
173
- ty:: PredicateKind :: Clause ( ty :: ClauseKind :: WellFormed ( arg) ) => {
175
+ ty:: ClauseKind :: WellFormed ( arg) => {
174
176
wf. compute ( arg) ;
175
177
}
176
178
177
- ty:: PredicateKind :: Clause ( ty :: ClauseKind :: ConstEvaluatable ( ct) ) => {
179
+ ty:: ClauseKind :: ConstEvaluatable ( ct) => {
178
180
wf. compute ( ct. into ( ) ) ;
179
181
}
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
- }
190
182
}
191
183
192
184
wf. normalize ( infcx)
@@ -233,7 +225,7 @@ enum Elaborate {
233
225
234
226
fn extend_cause_with_original_assoc_item_obligation < ' tcx > (
235
227
tcx : TyCtxt < ' tcx > ,
236
- trait_ref : & ty:: TraitRef < ' tcx > ,
228
+ trait_ref : ty:: TraitRef < ' tcx > ,
237
229
item : Option < & hir:: Item < ' tcx > > ,
238
230
cause : & mut traits:: ObligationCause < ' tcx > ,
239
231
pred : ty:: Predicate < ' tcx > ,
@@ -336,9 +328,9 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
336
328
}
337
329
338
330
/// 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 ) {
340
332
let tcx = self . tcx ( ) ;
341
- let trait_ref = & trait_pred. trait_ref ;
333
+ let trait_ref = trait_pred. trait_ref ;
342
334
343
335
// Negative trait predicates don't require supertraits to hold, just
344
336
// that their args are WF.
@@ -411,7 +403,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
411
403
412
404
// Compute the obligations that are required for `trait_ref` to be WF,
413
405
// 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 > ) {
415
407
for arg in trait_ref. args {
416
408
self . compute ( arg) ;
417
409
}
0 commit comments