@@ -13,9 +13,10 @@ use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor};
13
13
use rustc:: hir:: map:: definitions:: DefPathData ;
14
14
use rustc:: hir:: { self , ImplPolarity } ;
15
15
use rustc:: traits:: {
16
- Clause , Clauses , DomainGoal , Goal , PolyDomainGoal , ProgramClause , WhereClauseAtom ,
16
+ Clause , Clauses , DomainGoal , FromEnv , Goal , PolyDomainGoal , ProgramClause , WellFormed ,
17
+ WhereClause ,
17
18
} ;
18
- use rustc:: ty:: subst :: Substs ;
19
+ use rustc:: ty:: query :: Providers ;
19
20
use rustc:: ty:: { self , Slice , TyCtxt } ;
20
21
use rustc_data_structures:: fx:: FxHashSet ;
21
22
use std:: mem;
@@ -139,11 +140,13 @@ impl<'tcx> IntoFromEnvGoal for DomainGoal<'tcx> {
139
140
140
141
impl < ' tcx > IntoWellFormedGoal for DomainGoal < ' tcx > {
141
142
fn into_wellformed_goal ( self ) -> DomainGoal < ' tcx > {
142
- use self :: DomainGoal :: * ;
143
+ use self :: WhereClause :: * ;
144
+
143
145
match self {
144
- Holds ( wc_atom) => WellFormed ( wc_atom) ,
145
- WellFormed ( ..) | FromEnv ( ..) | WellFormedTy ( ..) | FromEnvTy ( ..) | Normalize ( ..)
146
- | RegionOutlives ( ..) | TypeOutlives ( ..) => self ,
146
+ DomainGoal :: Holds ( Implemented ( trait_ref) ) => {
147
+ DomainGoal :: WellFormed ( WellFormed :: Trait ( trait_ref) )
148
+ }
149
+ other => other,
147
150
}
148
151
}
149
152
}
@@ -256,6 +259,8 @@ fn program_clauses_for_trait<'a, 'tcx>(
256
259
257
260
let clauses = iter:: once ( Clause :: ForAll ( ty:: Binder :: dummy ( implemented_from_env) ) ) ;
258
261
262
+ let where_clauses = & tcx. predicates_defined_on ( def_id) . predicates ;
263
+
259
264
// Rule Implied-Bound-From-Trait
260
265
//
261
266
// For each where clause WC:
@@ -266,7 +271,6 @@ fn program_clauses_for_trait<'a, 'tcx>(
266
271
// ```
267
272
268
273
// `FromEnv(WC) :- FromEnv(Self: Trait<P1..Pn>)`, for each where clause WC
269
- let where_clauses = & tcx. predicates_defined_on ( def_id) . predicates ;
270
274
let implied_bound_clauses = where_clauses
271
275
. into_iter ( )
272
276
. map ( |wc| wc. lower ( ) )
@@ -276,43 +280,36 @@ fn program_clauses_for_trait<'a, 'tcx>(
276
280
goal : goal. into_from_env_goal ( ) ,
277
281
hypotheses,
278
282
} ) )
279
- . map ( |wc| implied_bound_from_trait ( tcx, trait_pred, wc) ) ;
280
- let wellformed_clauses = wellformed_from_bound ( tcx, trait_pred, & where_clauses[ 1 ..] ) ;
281
- tcx. mk_clauses ( clauses. chain ( implied_bound_clauses) . chain ( wellformed_clauses) )
282
- }
283
+ . map ( Clause :: ForAll ) ;
283
284
284
- fn wellformed_from_bound < ' a , ' tcx > (
285
- tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
286
- trait_pred : ty:: TraitPredicate < ' tcx > ,
287
- where_clauses : & [ ty:: Predicate < ' tcx > ] ,
288
- ) -> iter:: Once < Clause < ' tcx > > {
289
285
// Rule WellFormed-TraitRef
290
286
//
291
287
// For each where clause WC:
292
288
// forall<Self, P1..Pn> {
293
289
// WellFormed(Self: Trait<P1..Pn>) :- Implemented(Self: Trait<P1..Pn>) && WellFormed(WC)
294
290
// }
295
291
296
- // WellFormed(Self: Trait<P1..Pn>)
297
- let wellformed_trait = DomainGoal :: WellFormed ( WhereClauseAtom :: Implemented ( trait_pred) ) ;
298
- // Implemented(Self: Trait<P1..Pn>)
299
- let impl_trait = ty:: Binder :: dummy ( DomainGoal :: Holds ( WhereClauseAtom :: Implemented ( trait_pred) ) ) ;
300
- // WellFormed(WC)
301
- let wellformed_wc = where_clause
302
- . lower ( )
303
- . map_bound ( |wc| wc. into_wellformed_goal ( ) ) ;
304
- // Implemented(Self: Trait<P1..Pn>) && WellFormed(WC)
305
- let mut wcs = vec ! [ impl_trait] ;
306
- wcs. extend ( wellformed_wcs) ;
292
+ let wellformed_clauses = where_clauses
293
+ . into_iter ( )
294
+ . map ( |wc| wc. lower ( ) )
295
+ // WellFormed(Self: Trait<P1..Pn>) :- Implemented(Self: Trait<P1..Pn>) && WellFormed(WC)
296
+ . map ( |wc| {
297
+ wc. map_bound ( |goal| ProgramClause {
298
+ goal : goal. into_wellformed_goal ( ) ,
299
+ hypotheses : tcx. mk_goals (
300
+ where_clauses
301
+ . into_iter ( )
302
+ . map ( |wc| Goal :: from_poly_domain_goal ( wc. lower ( ) , tcx) ) ,
303
+ ) ,
304
+ } )
305
+ } )
306
+ . map ( Clause :: ForAll ) ;
307
307
308
- let clause = ProgramClause {
309
- goal : wellformed_trait,
310
- hypotheses : tcx. mk_goals (
311
- wcs. into_iter ( )
312
- . map ( |wc| Goal :: from_poly_domain_goal ( wc, tcx) ) ,
313
- ) ,
314
- } ;
315
- iter:: once ( Clause :: ForAll ( ty:: Binder :: dummy ( clause) ) )
308
+ tcx. mk_clauses (
309
+ clauses
310
+ . chain ( implied_bound_clauses)
311
+ . chain ( wellformed_clauses) ,
312
+ )
316
313
}
317
314
318
315
fn program_clauses_for_impl < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , def_id : DefId ) -> Clauses < ' tcx > {
0 commit comments