@@ -3,51 +3,20 @@ use smallvec::smallvec;
33use crate :: traits:: { Obligation , ObligationCause , PredicateObligation } ;
44use rustc_data_structures:: fx:: FxHashSet ;
55use rustc_middle:: ty:: outlives:: Component ;
6- use rustc_middle:: ty:: { self , ToPolyTraitRef , ToPredicate , TyCtxt , WithConstness } ;
6+ use rustc_middle:: ty:: { self , ToPredicate , TyCtxt , WithConstness } ;
77use rustc_span:: Span ;
88
99pub fn anonymize_predicate < ' tcx > (
1010 tcx : TyCtxt < ' tcx > ,
1111 pred : ty:: Predicate < ' tcx > ,
1212) -> 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 )
1717 }
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+ }
5120}
5221
5322struct PredicateSet < ' tcx > {
@@ -158,15 +127,16 @@ impl Elaborator<'tcx> {
158127
159128 fn elaborate ( & mut self , obligation : & PredicateObligation < ' tcx > ) {
160129 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, _) => {
163133 // Get predicates declared on the trait.
164134 let predicates = tcx. super_predicates_of ( data. def_id ( ) ) ;
165135
166- let obligations = predicates. predicates . iter ( ) . map ( |( pred, span) | {
136+ let obligations = predicates. predicates . iter ( ) . map ( |& ( pred, span) | {
167137 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) ,
170140 )
171141 } ) ;
172142 debug ! ( "super_predicates: data={:?}" , data) ;
@@ -180,36 +150,36 @@ impl Elaborator<'tcx> {
180150
181151 self . stack . extend ( obligations) ;
182152 }
183- ty:: PredicateKind :: WellFormed ( ..) => {
153+ ty:: PredicateAtom :: WellFormed ( ..) => {
184154 // Currently, we do not elaborate WF predicates,
185155 // although we easily could.
186156 }
187- ty:: PredicateKind :: ObjectSafe ( ..) => {
157+ ty:: PredicateAtom :: ObjectSafe ( ..) => {
188158 // Currently, we do not elaborate object-safe
189159 // predicates.
190160 }
191- ty:: PredicateKind :: Subtype ( ..) => {
161+ ty:: PredicateAtom :: Subtype ( ..) => {
192162 // Currently, we do not "elaborate" predicates like `X <: Y`,
193163 // though conceivably we might.
194164 }
195- ty:: PredicateKind :: Projection ( ..) => {
165+ ty:: PredicateAtom :: Projection ( ..) => {
196166 // Nothing to elaborate in a projection predicate.
197167 }
198- ty:: PredicateKind :: ClosureKind ( ..) => {
168+ ty:: PredicateAtom :: ClosureKind ( ..) => {
199169 // Nothing to elaborate when waiting for a closure's kind to be inferred.
200170 }
201- ty:: PredicateKind :: ConstEvaluatable ( ..) => {
171+ ty:: PredicateAtom :: ConstEvaluatable ( ..) => {
202172 // Currently, we do not elaborate const-evaluatable
203173 // predicates.
204174 }
205- ty:: PredicateKind :: ConstEquate ( ..) => {
175+ ty:: PredicateAtom :: ConstEquate ( ..) => {
206176 // Currently, we do not elaborate const-equate
207177 // predicates.
208178 }
209- ty:: PredicateKind :: RegionOutlives ( ..) => {
179+ ty:: PredicateAtom :: RegionOutlives ( ..) => {
210180 // Nothing to elaborate from `'a: 'b`.
211181 }
212- ty:: PredicateKind :: TypeOutlives ( ref data ) => {
182+ ty:: PredicateAtom :: TypeOutlives ( ty :: OutlivesPredicate ( ty_max , r_min ) ) => {
213183 // We know that `T: 'a` for some type `T`. We can
214184 // often elaborate this. For example, if we know that
215185 // `[U]: 'a`, that implies that `U: 'a`. Similarly, if
@@ -224,8 +194,6 @@ impl Elaborator<'tcx> {
224194 // consider this as evidence that `T: 'static`, but
225195 // I'm a bit wary of such constructions and so for now
226196 // I want to be conservative. --nmatsakis
227- let ty_max = data. skip_binder ( ) . 0 ;
228- let r_min = data. skip_binder ( ) . 1 ;
229197 if r_min. is_late_bound ( ) {
230198 return ;
231199 }
@@ -241,16 +209,16 @@ impl Elaborator<'tcx> {
241209 if r. is_late_bound ( ) {
242210 None
243211 } 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,
246214 ) ) )
247215 }
248216 }
249217
250218 Component :: Param ( p) => {
251219 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,
254222 ) ) )
255223 }
256224
@@ -331,8 +299,8 @@ impl<'tcx, I: Iterator<Item = PredicateObligation<'tcx>>> Iterator for FilterToT
331299
332300 fn next ( & mut self ) -> Option < ty:: PolyTraitRef < ' tcx > > {
333301 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) ;
336304 }
337305 }
338306 None
0 commit comments