8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
- use rustc:: hir:: { self , ImplPolarity } ;
12
11
use rustc:: hir:: def_id:: DefId ;
13
12
use rustc:: hir:: intravisit:: { self , NestedVisitorMap , Visitor } ;
14
- use rustc:: ty :: { self , Slice , TyCtxt } ;
13
+ use rustc:: traits :: { Clause , DomainGoal , Goal , PolyDomainGoal , ProgramClause , WhereClauseAtom } ;
15
14
use rustc:: ty:: subst:: Substs ;
16
- use rustc:: traits:: { WhereClauseAtom , PolyDomainGoal , DomainGoal , ProgramClause , Clause , Goal } ;
17
- use syntax:: ast;
15
+ use rustc:: ty:: { self , Slice , TyCtxt } ;
18
16
use rustc_data_structures:: sync:: Lrc ;
17
+ use syntax:: ast;
18
+ use syntax:: ast;
19
19
20
20
use std:: iter;
21
21
@@ -24,7 +24,10 @@ trait Lower<T> {
24
24
fn lower ( & self ) -> T ;
25
25
}
26
26
27
- impl < T , U > Lower < Vec < U > > for Vec < T > where T : Lower < U > {
27
+ impl < T , U > Lower < Vec < U > > for Vec < T >
28
+ where
29
+ T : Lower < U > ,
30
+ {
28
31
fn lower ( & self ) -> Vec < U > {
29
32
self . iter ( ) . map ( |item| item. lower ( ) ) . collect ( )
30
33
}
@@ -42,7 +45,10 @@ impl<'tcx> Lower<WhereClauseAtom<'tcx>> for ty::ProjectionPredicate<'tcx> {
42
45
}
43
46
}
44
47
45
- impl < ' tcx , T > Lower < DomainGoal < ' tcx > > for T where T : Lower < WhereClauseAtom < ' tcx > > {
48
+ impl < ' tcx , T > Lower < DomainGoal < ' tcx > > for T
49
+ where
50
+ T : Lower < WhereClauseAtom < ' tcx > > ,
51
+ {
46
52
fn lower ( & self ) -> DomainGoal < ' tcx > {
47
53
DomainGoal :: Holds ( self . lower ( ) )
48
54
}
@@ -67,7 +73,8 @@ impl<'tcx> Lower<DomainGoal<'tcx>> for ty::TypeOutlivesPredicate<'tcx> {
67
73
/// `forall<'a> { T: Fn(&'a i32) }` which corresponds to something like
68
74
/// `Binder<Holds(Implemented(TraitPredicate))>`.
69
75
impl < ' tcx , T > Lower < PolyDomainGoal < ' tcx > > for ty:: Binder < T >
70
- where T : Lower < DomainGoal < ' tcx > > + ty:: fold:: TypeFoldable < ' tcx >
76
+ where
77
+ T : Lower < DomainGoal < ' tcx > > + ty:: fold:: TypeFoldable < ' tcx > ,
71
78
{
72
79
fn lower ( & self ) -> PolyDomainGoal < ' tcx > {
73
80
self . map_bound_ref ( |p| p. lower ( ) )
@@ -84,10 +91,9 @@ impl<'tcx> Lower<PolyDomainGoal<'tcx>> for ty::Predicate<'tcx> {
84
91
TypeOutlives ( predicate) => predicate. lower ( ) ,
85
92
Projection ( predicate) => predicate. lower ( ) ,
86
93
WellFormed ( ty) => ty:: Binder :: dummy ( DomainGoal :: WellFormedTy ( * ty) ) ,
87
- ObjectSafe ( ..) |
88
- ClosureKind ( ..) |
89
- Subtype ( ..) |
90
- ConstEvaluatable ( ..) => unimplemented ! ( ) ,
94
+ ObjectSafe ( ..) | ClosureKind ( ..) | Subtype ( ..) | ConstEvaluatable ( ..) => {
95
+ unimplemented ! ( )
96
+ }
91
97
}
92
98
}
93
99
}
@@ -104,44 +110,41 @@ impl<'tcx> IntoFromEnvGoal for DomainGoal<'tcx> {
104
110
use self :: DomainGoal :: * ;
105
111
match self {
106
112
Holds ( wc_atom) => FromEnv ( wc_atom) ,
107
- WellFormed ( ..) |
108
- FromEnv ( ..) |
109
- WellFormedTy ( ..) |
110
- FromEnvTy ( ..) |
111
- Normalize ( ..) |
112
- RegionOutlives ( ..) |
113
- TypeOutlives ( ..) => self ,
113
+ WellFormed ( ..) | FromEnv ( ..) | WellFormedTy ( ..) | FromEnvTy ( ..) | Normalize ( ..)
114
+ | RegionOutlives ( ..) | TypeOutlives ( ..) => self ,
114
115
}
115
116
}
116
117
}
117
118
118
- crate fn program_clauses_for < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , def_id : DefId )
119
- -> Lrc < & ' tcx Slice < Clause < ' tcx > > >
120
- {
119
+ crate fn program_clauses_for < ' a , ' tcx > (
120
+ tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
121
+ def_id : DefId ,
122
+ ) -> Lrc < & ' tcx Slice < Clause < ' tcx > > > {
121
123
let node_id = tcx. hir . as_local_node_id ( def_id) . unwrap ( ) ;
122
124
let node = tcx. hir . find ( node_id) . unwrap ( ) ;
123
125
match node {
124
126
hir:: map:: Node :: NodeItem ( item) => match item. node {
125
127
hir:: ItemTrait ( ..) => program_clauses_for_trait ( tcx, def_id) ,
126
128
hir:: ItemImpl ( ..) => program_clauses_for_impl ( tcx, def_id) ,
127
129
_ => Lrc :: new ( tcx. mk_clauses ( iter:: empty :: < Clause > ( ) ) ) ,
128
- }
130
+ } ,
129
131
hir:: map:: Node :: NodeImplItem ( item) => {
130
132
if let hir:: ImplItemKind :: Type ( ..) = item. node {
131
133
program_clauses_for_associated_type_value ( tcx, def_id)
132
134
} else {
133
135
Lrc :: new ( tcx. mk_clauses ( iter:: empty :: < Clause > ( ) ) )
134
136
}
135
- } ,
137
+ }
136
138
137
139
// FIXME: other constructions e.g. traits, associated types...
138
140
_ => Lrc :: new ( tcx. mk_clauses ( iter:: empty :: < Clause > ( ) ) ) ,
139
141
}
140
142
}
141
143
142
- fn program_clauses_for_trait < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , def_id : DefId )
143
- -> Lrc < & ' tcx Slice < Clause < ' tcx > > >
144
- {
144
+ fn program_clauses_for_trait < ' a , ' tcx > (
145
+ tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
146
+ def_id : DefId ,
147
+ ) -> Lrc < & ' tcx Slice < Clause < ' tcx > > > {
145
148
// `trait Trait<P1..Pn> where WC { .. } // P0 == Self`
146
149
147
150
// Rule Implemented-From-Env (see rustc guide)
@@ -156,8 +159,8 @@ fn program_clauses_for_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefI
156
159
let trait_pred = ty:: TraitPredicate {
157
160
trait_ref : ty:: TraitRef {
158
161
def_id,
159
- substs : Substs :: identity_for_item ( tcx, def_id)
160
- }
162
+ substs : Substs :: identity_for_item ( tcx, def_id) ,
163
+ } ,
161
164
} ;
162
165
// `FromEnv(Self: Trait<P1..Pn>)`
163
166
let from_env = Goal :: from ( DomainGoal :: FromEnv ( trait_pred. lower ( ) ) ) ;
@@ -169,9 +172,7 @@ fn program_clauses_for_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefI
169
172
goal : impl_trait,
170
173
hypotheses : tcx. mk_goals ( iter:: once ( from_env) ) ,
171
174
} ;
172
- let clauses = iter:: once (
173
- Clause :: ForAll ( ty:: Binder :: dummy ( implemented_from_env) )
174
- ) ;
175
+ let clauses = iter:: once ( Clause :: ForAll ( ty:: Binder :: dummy ( implemented_from_env) ) ) ;
175
176
176
177
// Rule Implied-Bound-From-Trait
177
178
//
@@ -186,8 +187,8 @@ fn program_clauses_for_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefI
186
187
// FIXME: Remove the [1..] slice; this is a hack because the query
187
188
// predicates_of currently includes the trait itself (`Self: Trait<P1..Pn>`).
188
189
let where_clauses = & tcx. predicates_of ( def_id) . predicates ;
189
- let implied_bound_clauses =
190
- where_clauses [ 1 .. ] . into_iter ( )
190
+ let implied_bound_clauses = where_clauses [ 1 .. ]
191
+ . into_iter ( )
191
192
. map ( |wc| implied_bound_from_trait ( tcx, trait_pred, wc) ) ;
192
193
193
194
Lrc :: new ( tcx. mk_clauses ( clauses. chain ( implied_bound_clauses) ) )
@@ -203,17 +204,16 @@ fn implied_bound_from_trait<'a, 'tcx>(
203
204
let impl_trait = DomainGoal :: FromEnv ( WhereClauseAtom :: Implemented ( trait_pred) ) ;
204
205
205
206
// `FromEnv(WC) :- FromEnv(Self: Trait<P1..Pn>)`
206
- Clause :: ForAll (
207
- where_clause. lower ( ) . map_bound ( |goal| ProgramClause {
208
- goal : goal. into_from_env_goal ( ) ,
209
- hypotheses : tcx. mk_goals ( iter:: once ( Goal :: from ( impl_trait) ) ) ,
210
- } )
211
- )
207
+ Clause :: ForAll ( where_clause. lower ( ) . map_bound ( |goal| ProgramClause {
208
+ goal : goal. into_from_env_goal ( ) ,
209
+ hypotheses : tcx. mk_goals ( iter:: once ( Goal :: from ( impl_trait) ) ) ,
210
+ } ) )
212
211
}
213
212
214
- fn program_clauses_for_impl < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , def_id : DefId )
215
- -> Lrc < & ' tcx Slice < Clause < ' tcx > > >
216
- {
213
+ fn program_clauses_for_impl < ' a , ' tcx > (
214
+ tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
215
+ def_id : DefId ,
216
+ ) -> Lrc < & ' tcx Slice < Clause < ' tcx > > > {
217
217
if let ImplPolarity :: Negative = tcx. impl_polarity ( def_id) {
218
218
return Lrc :: new ( tcx. mk_clauses ( iter:: empty :: < Clause > ( ) ) ) ;
219
219
}
@@ -231,15 +231,17 @@ fn program_clauses_for_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId
231
231
let trait_ref = tcx. impl_trait_ref ( def_id) . unwrap ( ) ;
232
232
// `Implemented(A0: Trait<A1..An>)`
233
233
let trait_pred = ty:: TraitPredicate { trait_ref } . lower ( ) ;
234
- // `WC`
234
+ // `WC`
235
235
let where_clauses = tcx. predicates_of ( def_id) . predicates . lower ( ) ;
236
236
237
- // `Implemented(A0: Trait<A1..An>) :- WC`
237
+ // `Implemented(A0: Trait<A1..An>) :- WC`
238
238
let clause = ProgramClause {
239
239
goal : trait_pred,
240
240
hypotheses : tcx. mk_goals (
241
- where_clauses. into_iter ( ) . map ( |wc| Goal :: from_poly_domain_goal ( wc, tcx) )
242
- )
241
+ where_clauses
242
+ . into_iter ( )
243
+ . map ( |wc| Goal :: from_poly_domain_goal ( wc, tcx) ) ,
244
+ ) ,
243
245
} ;
244
246
Lrc :: new ( tcx. mk_clauses ( iter:: once ( Clause :: ForAll ( ty:: Binder :: dummy ( clause) ) ) ) )
245
247
}
@@ -290,7 +292,9 @@ pub fn program_clauses_for_associated_type_value<'a, 'tcx>(
290
292
let clause = ProgramClause {
291
293
goal : normalize_goal,
292
294
hypotheses : tcx. mk_goals (
293
- where_clauses. into_iter ( ) . map ( |wc| Goal :: from_poly_domain_goal ( wc, tcx) )
295
+ where_clauses
296
+ . into_iter ( )
297
+ . map ( |wc| Goal :: from_poly_domain_goal ( wc, tcx) ) ,
294
298
) ,
295
299
} ;
296
300
Lrc :: new ( tcx. mk_clauses ( iter:: once ( Clause :: ForAll ( ty:: Binder :: dummy ( clause) ) ) ) )
@@ -302,14 +306,16 @@ pub fn dump_program_clauses<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
302
306
}
303
307
304
308
let mut visitor = ClauseDumper { tcx } ;
305
- tcx. hir . krate ( ) . visit_all_item_likes ( & mut visitor. as_deep_visitor ( ) ) ;
309
+ tcx. hir
310
+ . krate ( )
311
+ . visit_all_item_likes ( & mut visitor. as_deep_visitor ( ) ) ;
306
312
}
307
313
308
314
struct ClauseDumper < ' a , ' tcx : ' a > {
309
315
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
310
316
}
311
317
312
- impl < ' a , ' tcx > ClauseDumper < ' a , ' tcx > {
318
+ impl < ' a , ' tcx > ClauseDumper < ' a , ' tcx > {
313
319
fn process_attrs ( & mut self , node_id : ast:: NodeId , attrs : & [ ast:: Attribute ] ) {
314
320
let def_id = self . tcx . hir . local_def_id ( node_id) ;
315
321
for attr in attrs {
@@ -321,7 +327,10 @@ impl<'a, 'tcx> ClauseDumper<'a, 'tcx > {
321
327
Clause :: Implies ( program_clause) => program_clause,
322
328
Clause :: ForAll ( program_clause) => program_clause. skip_binder ( ) ,
323
329
} ;
324
- self . tcx . sess . struct_span_err ( attr. span , & format ! ( "{}" , program_clause) ) . emit ( ) ;
330
+ self . tcx
331
+ . sess
332
+ . struct_span_err ( attr. span , & format ! ( "{}" , program_clause) )
333
+ . emit ( ) ;
325
334
}
326
335
}
327
336
}
0 commit comments