@@ -3,51 +3,20 @@ use smallvec::smallvec;
3
3
use crate :: traits:: { Obligation , ObligationCause , PredicateObligation } ;
4
4
use rustc_data_structures:: fx:: FxHashSet ;
5
5
use rustc_middle:: ty:: outlives:: Component ;
6
- use rustc_middle:: ty:: { self , ToPolyTraitRef , ToPredicate , TyCtxt , WithConstness } ;
6
+ use rustc_middle:: ty:: { self , ToPredicate , TyCtxt , WithConstness } ;
7
7
use rustc_span:: Span ;
8
8
9
9
pub fn anonymize_predicate < ' tcx > (
10
10
tcx : TyCtxt < ' tcx > ,
11
11
pred : ty:: Predicate < ' tcx > ,
12
12
) -> ty:: Predicate < ' tcx > {
13
- let kind = pred. kind ( ) ;
14
- let new = match kind {
15
- & ty:: PredicateKind :: Trait ( ref data , constness ) => {
16
- ty :: PredicateKind :: Trait ( tcx. anonymize_late_bound_regions ( data ) , constness )
13
+ match pred. kind ( ) {
14
+ ty :: PredicateKind :: ForAll ( binder ) => {
15
+ let new = ty:: PredicateKind :: ForAll ( tcx . anonymize_late_bound_regions ( binder ) ) ;
16
+ tcx. reuse_or_mk_predicate ( pred , new )
17
17
}
18
-
19
- ty:: PredicateKind :: RegionOutlives ( data) => {
20
- ty:: PredicateKind :: RegionOutlives ( tcx. anonymize_late_bound_regions ( data) )
21
- }
22
-
23
- ty:: PredicateKind :: TypeOutlives ( data) => {
24
- ty:: PredicateKind :: TypeOutlives ( tcx. anonymize_late_bound_regions ( data) )
25
- }
26
-
27
- ty:: PredicateKind :: Projection ( data) => {
28
- ty:: PredicateKind :: Projection ( tcx. anonymize_late_bound_regions ( data) )
29
- }
30
-
31
- & ty:: PredicateKind :: WellFormed ( data) => ty:: PredicateKind :: WellFormed ( data) ,
32
-
33
- & ty:: PredicateKind :: ObjectSafe ( data) => ty:: PredicateKind :: ObjectSafe ( data) ,
34
-
35
- & ty:: PredicateKind :: ClosureKind ( closure_def_id, closure_substs, kind) => {
36
- ty:: PredicateKind :: ClosureKind ( closure_def_id, closure_substs, kind)
37
- }
38
-
39
- ty:: PredicateKind :: Subtype ( data) => {
40
- ty:: PredicateKind :: Subtype ( tcx. anonymize_late_bound_regions ( data) )
41
- }
42
-
43
- & ty:: PredicateKind :: ConstEvaluatable ( def_id, substs) => {
44
- ty:: PredicateKind :: ConstEvaluatable ( def_id, substs)
45
- }
46
-
47
- ty:: PredicateKind :: ConstEquate ( c1, c2) => ty:: PredicateKind :: ConstEquate ( c1, c2) ,
48
- } ;
49
-
50
- if new != * kind { new. to_predicate ( tcx) } else { pred }
18
+ ty:: PredicateKind :: Atom ( _) => pred,
19
+ }
51
20
}
52
21
53
22
struct PredicateSet < ' tcx > {
@@ -158,15 +127,16 @@ impl Elaborator<'tcx> {
158
127
159
128
fn elaborate ( & mut self , obligation : & PredicateObligation < ' tcx > ) {
160
129
let tcx = self . visited . tcx ;
161
- match obligation. predicate . kind ( ) {
162
- ty:: PredicateKind :: Trait ( ref data, _) => {
130
+
131
+ match obligation. predicate . skip_binders ( ) {
132
+ ty:: PredicateAtom :: Trait ( data, _) => {
163
133
// Get predicates declared on the trait.
164
134
let predicates = tcx. super_predicates_of ( data. def_id ( ) ) ;
165
135
166
- let obligations = predicates. predicates . iter ( ) . map ( |( pred, span) | {
136
+ let obligations = predicates. predicates . iter ( ) . map ( |& ( pred, span) | {
167
137
predicate_obligation (
168
- pred. subst_supertrait ( tcx, & data. to_poly_trait_ref ( ) ) ,
169
- Some ( * span) ,
138
+ pred. subst_supertrait ( tcx, & ty :: Binder :: bind ( data. trait_ref ) ) ,
139
+ Some ( span) ,
170
140
)
171
141
} ) ;
172
142
debug ! ( "super_predicates: data={:?}" , data) ;
@@ -180,36 +150,36 @@ impl Elaborator<'tcx> {
180
150
181
151
self . stack . extend ( obligations) ;
182
152
}
183
- ty:: PredicateKind :: WellFormed ( ..) => {
153
+ ty:: PredicateAtom :: WellFormed ( ..) => {
184
154
// Currently, we do not elaborate WF predicates,
185
155
// although we easily could.
186
156
}
187
- ty:: PredicateKind :: ObjectSafe ( ..) => {
157
+ ty:: PredicateAtom :: ObjectSafe ( ..) => {
188
158
// Currently, we do not elaborate object-safe
189
159
// predicates.
190
160
}
191
- ty:: PredicateKind :: Subtype ( ..) => {
161
+ ty:: PredicateAtom :: Subtype ( ..) => {
192
162
// Currently, we do not "elaborate" predicates like `X <: Y`,
193
163
// though conceivably we might.
194
164
}
195
- ty:: PredicateKind :: Projection ( ..) => {
165
+ ty:: PredicateAtom :: Projection ( ..) => {
196
166
// Nothing to elaborate in a projection predicate.
197
167
}
198
- ty:: PredicateKind :: ClosureKind ( ..) => {
168
+ ty:: PredicateAtom :: ClosureKind ( ..) => {
199
169
// Nothing to elaborate when waiting for a closure's kind to be inferred.
200
170
}
201
- ty:: PredicateKind :: ConstEvaluatable ( ..) => {
171
+ ty:: PredicateAtom :: ConstEvaluatable ( ..) => {
202
172
// Currently, we do not elaborate const-evaluatable
203
173
// predicates.
204
174
}
205
- ty:: PredicateKind :: ConstEquate ( ..) => {
175
+ ty:: PredicateAtom :: ConstEquate ( ..) => {
206
176
// Currently, we do not elaborate const-equate
207
177
// predicates.
208
178
}
209
- ty:: PredicateKind :: RegionOutlives ( ..) => {
179
+ ty:: PredicateAtom :: RegionOutlives ( ..) => {
210
180
// Nothing to elaborate from `'a: 'b`.
211
181
}
212
- ty:: PredicateKind :: TypeOutlives ( ref data ) => {
182
+ ty:: PredicateAtom :: TypeOutlives ( ty :: OutlivesPredicate ( ty_max , r_min ) ) => {
213
183
// We know that `T: 'a` for some type `T`. We can
214
184
// often elaborate this. For example, if we know that
215
185
// `[U]: 'a`, that implies that `U: 'a`. Similarly, if
@@ -224,8 +194,6 @@ impl Elaborator<'tcx> {
224
194
// consider this as evidence that `T: 'static`, but
225
195
// I'm a bit wary of such constructions and so for now
226
196
// I want to be conservative. --nmatsakis
227
- let ty_max = data. skip_binder ( ) . 0 ;
228
- let r_min = data. skip_binder ( ) . 1 ;
229
197
if r_min. is_late_bound ( ) {
230
198
return ;
231
199
}
@@ -241,16 +209,16 @@ impl Elaborator<'tcx> {
241
209
if r. is_late_bound ( ) {
242
210
None
243
211
} else {
244
- Some ( ty:: PredicateKind :: RegionOutlives ( ty:: Binder :: dummy (
245
- ty :: OutlivesPredicate ( r, r_min) ,
212
+ Some ( ty:: PredicateAtom :: RegionOutlives ( ty:: OutlivesPredicate (
213
+ r, r_min,
246
214
) ) )
247
215
}
248
216
}
249
217
250
218
Component :: Param ( p) => {
251
219
let ty = tcx. mk_ty_param ( p. index , p. name ) ;
252
- Some ( ty:: PredicateKind :: TypeOutlives ( ty:: Binder :: dummy (
253
- ty:: OutlivesPredicate ( ty , r_min) ,
220
+ Some ( ty:: PredicateAtom :: TypeOutlives ( ty:: OutlivesPredicate (
221
+ ty, r_min,
254
222
) ) )
255
223
}
256
224
@@ -331,8 +299,8 @@ impl<'tcx, I: Iterator<Item = PredicateObligation<'tcx>>> Iterator for FilterToT
331
299
332
300
fn next ( & mut self ) -> Option < ty:: PolyTraitRef < ' tcx > > {
333
301
while let Some ( obligation) = self . base_iterator . next ( ) {
334
- if let ty :: PredicateKind :: Trait ( data, _ ) = obligation. predicate . kind ( ) {
335
- return Some ( data. to_poly_trait_ref ( ) ) ;
302
+ if let Some ( data) = obligation. predicate . to_opt_poly_trait_ref ( ) {
303
+ return Some ( data) ;
336
304
}
337
305
}
338
306
None
0 commit comments