@@ -15,6 +15,7 @@ use rustc::hir::def_id::DefId;
15
15
use rustc_target:: spec:: abi;
16
16
use super :: ChalkInferenceContext ;
17
17
use crate :: lowering:: Lower ;
18
+ use crate :: generic_types;
18
19
use std:: iter;
19
20
20
21
fn assemble_clauses_from_impls < ' tcx > (
@@ -47,24 +48,19 @@ fn assemble_clauses_from_assoc_ty_values<'tcx>(
47
48
} ) ;
48
49
}
49
50
50
- fn program_clauses_for_raw_ptr < ' tcx > ( tcx : ty:: TyCtxt < ' _ , ' _ , ' tcx > ) -> Clauses < ' tcx > {
51
- let ty = ty:: Bound (
52
- ty:: INNERMOST ,
53
- ty:: BoundVar :: from_u32 ( 0 ) . into ( )
54
- ) ;
55
- let ty = tcx. mk_ty ( ty) ;
56
51
57
- let ptr_ty = tcx. mk_ptr ( ty:: TypeAndMut {
58
- ty,
59
- mutbl : hir:: Mutability :: MutImmutable ,
60
- } ) ;
52
+ fn program_clauses_for_raw_ptr < ' tcx > (
53
+ tcx : ty:: TyCtxt < ' _ , ' _ , ' tcx > ,
54
+ mutbl : hir:: Mutability
55
+ ) -> Clauses < ' tcx > {
56
+ let ptr_ty = generic_types:: raw_ptr ( tcx, mutbl) ;
61
57
62
58
let wf_clause = ProgramClause {
63
59
goal : DomainGoal :: WellFormed ( WellFormed :: Ty ( ptr_ty) ) ,
64
60
hypotheses : ty:: List :: empty ( ) ,
65
61
category : ProgramClauseCategory :: WellFormed ,
66
62
} ;
67
- let wf_clause = Clause :: ForAll ( ty :: Binder :: bind ( wf_clause) ) ;
63
+ let wf_clause = Clause :: Implies ( wf_clause) ;
68
64
69
65
// `forall<T> { WellFormed(*const T). }`
70
66
tcx. mk_clauses ( iter:: once ( wf_clause) )
@@ -77,20 +73,7 @@ fn program_clauses_for_fn_ptr<'tcx>(
77
73
unsafety : hir:: Unsafety ,
78
74
abi : abi:: Abi
79
75
) -> Clauses < ' tcx > {
80
- let inputs_and_output = tcx. mk_type_list (
81
- ( 0 ..arity_and_output) . into_iter ( )
82
- . map ( |i| ty:: BoundVar :: from ( i) )
83
- // DebruijnIndex(1) because we are going to inject these in a `PolyFnSig`
84
- . map ( |var| tcx. mk_ty ( ty:: Bound ( ty:: DebruijnIndex :: from ( 1usize ) , var. into ( ) ) ) )
85
- ) ;
86
-
87
- let fn_sig = ty:: Binder :: bind ( ty:: FnSig {
88
- inputs_and_output,
89
- variadic,
90
- unsafety,
91
- abi,
92
- } ) ;
93
- let fn_ptr = tcx. mk_fn_ptr ( fn_sig) ;
76
+ let fn_ptr = generic_types:: fn_ptr ( tcx, arity_and_output, variadic, unsafety, abi) ;
94
77
95
78
let wf_clause = ProgramClause {
96
79
goal : DomainGoal :: WellFormed ( WellFormed :: Ty ( fn_ptr) ) ,
@@ -105,12 +88,7 @@ fn program_clauses_for_fn_ptr<'tcx>(
105
88
}
106
89
107
90
fn program_clauses_for_slice < ' tcx > ( tcx : ty:: TyCtxt < ' _ , ' _ , ' tcx > ) -> Clauses < ' tcx > {
108
- let ty = ty:: Bound (
109
- ty:: INNERMOST ,
110
- ty:: BoundVar :: from_u32 ( 0 ) . into ( )
111
- ) ;
112
- let ty = tcx. mk_ty ( ty) ;
113
-
91
+ let ty = generic_types:: bound ( tcx, 0 ) ;
114
92
let slice_ty = tcx. mk_slice ( ty) ;
115
93
116
94
let sized_trait = match tcx. lang_items ( ) . sized_trait ( ) {
@@ -142,12 +120,7 @@ fn program_clauses_for_array<'tcx>(
142
120
tcx : ty:: TyCtxt < ' _ , ' _ , ' tcx > ,
143
121
length : & ' tcx ty:: Const < ' tcx >
144
122
) -> Clauses < ' tcx > {
145
- let ty = ty:: Bound (
146
- ty:: INNERMOST ,
147
- ty:: BoundVar :: from_u32 ( 0 ) . into ( )
148
- ) ;
149
- let ty = tcx. mk_ty ( ty) ;
150
-
123
+ let ty = generic_types:: bound ( tcx, 0 ) ;
151
124
let array_ty = tcx. mk_ty ( ty:: Array ( ty, length) ) ;
152
125
153
126
let sized_trait = match tcx. lang_items ( ) . sized_trait ( ) {
@@ -179,12 +152,7 @@ fn program_clauses_for_tuple<'tcx>(
179
152
tcx : ty:: TyCtxt < ' _ , ' _ , ' tcx > ,
180
153
arity : usize
181
154
) -> Clauses < ' tcx > {
182
- let type_list = tcx. mk_type_list (
183
- ( 0 ..arity) . into_iter ( )
184
- . map ( |i| ty:: BoundVar :: from ( i) )
185
- . map ( |var| tcx. mk_ty ( ty:: Bound ( ty:: INNERMOST , var. into ( ) ) ) )
186
- ) ;
187
-
155
+ let type_list = generic_types:: type_list ( tcx, arity) ;
188
156
let tuple_ty = tcx. mk_ty ( ty:: Tuple ( type_list) ) ;
189
157
190
158
let sized_trait = match tcx. lang_items ( ) . sized_trait ( ) {
@@ -221,17 +189,17 @@ fn program_clauses_for_tuple<'tcx>(
221
189
tcx. mk_clauses ( iter:: once ( wf_clause) )
222
190
}
223
191
224
- fn program_clauses_for_ref < ' tcx > ( tcx : ty:: TyCtxt < ' _ , ' _ , ' tcx > ) -> Clauses < ' tcx > {
192
+ fn program_clauses_for_ref < ' tcx > (
193
+ tcx : ty:: TyCtxt < ' _ , ' _ , ' tcx > ,
194
+ mutbl : hir:: Mutability
195
+ ) -> Clauses < ' tcx > {
225
196
let region = tcx. mk_region (
226
197
ty:: ReLateBound ( ty:: INNERMOST , ty:: BoundRegion :: BrAnon ( 0 ) )
227
198
) ;
228
- let ty = tcx. mk_ty (
229
- ty:: Bound ( ty:: INNERMOST , ty:: BoundVar :: from_u32 ( 1 ) . into ( ) )
230
- ) ;
231
-
199
+ let ty = generic_types:: bound ( tcx, 1 ) ;
232
200
let ref_ty = tcx. mk_ref ( region, ty:: TypeAndMut {
233
201
ty,
234
- mutbl : hir :: Mutability :: MutImmutable ,
202
+ mutbl,
235
203
} ) ;
236
204
237
205
let outlives: DomainGoal = ty:: OutlivesPredicate ( ty, region) . lower ( ) ;
@@ -367,7 +335,7 @@ impl ChalkInferenceContext<'cx, 'gcx, 'tcx> {
367
335
}
368
336
369
337
// Always WF (recall that we do not check for parameters to be WF).
370
- ty:: RawPtr ( .. ) => program_clauses_for_raw_ptr ( self . infcx . tcx ) ,
338
+ ty:: RawPtr ( ptr ) => program_clauses_for_raw_ptr ( self . infcx . tcx , ptr . mutbl ) ,
371
339
372
340
// Always WF (recall that we do not check for parameters to be WF).
373
341
ty:: FnPtr ( fn_ptr) => {
@@ -394,7 +362,7 @@ impl ChalkInferenceContext<'cx, 'gcx, 'tcx> {
394
362
) ,
395
363
396
364
// WF if `sub_ty` outlives `region`.
397
- ty:: Ref ( .. ) => program_clauses_for_ref ( self . infcx . tcx ) ,
365
+ ty:: Ref ( _ , _ , mutbl ) => program_clauses_for_ref ( self . infcx . tcx , mutbl ) ,
398
366
399
367
ty:: Dynamic ( ..) => {
400
368
// FIXME: no rules yet for trait objects
0 commit comments