8
8
9
9
use rustc_middle:: traits:: ChalkRustInterner as RustInterner ;
10
10
use rustc_middle:: ty:: subst:: { InternalSubsts , Subst , SubstsRef } ;
11
- use rustc_middle:: ty:: { self , AssocItemContainer , AssocKind , TyCtxt } ;
11
+ use rustc_middle:: ty:: { self , AssocItemContainer , AssocKind , TyCtxt , TypeFoldable } ;
12
12
13
13
use rustc_hir:: def_id:: DefId ;
14
14
use rustc_hir:: Unsafety ;
@@ -18,11 +18,13 @@ use rustc_span::symbol::sym;
18
18
use std:: fmt;
19
19
use std:: sync:: Arc ;
20
20
21
- use crate :: chalk:: lowering:: LowerInto ;
21
+ use crate :: chalk:: lowering:: { self , LowerInto } ;
22
22
23
23
pub struct RustIrDatabase < ' tcx > {
24
24
pub tcx : TyCtxt < ' tcx > ,
25
25
pub interner : RustInterner < ' tcx > ,
26
+ pub restatic_placeholder : ty:: Region < ' tcx > ,
27
+ pub reempty_placeholder : ty:: Region < ' tcx > ,
26
28
}
27
29
28
30
impl fmt:: Debug for RustIrDatabase < ' _ > {
@@ -31,6 +33,26 @@ impl fmt::Debug for RustIrDatabase<'_> {
31
33
}
32
34
}
33
35
36
+ impl < ' tcx > RustIrDatabase < ' tcx > {
37
+ fn where_clauses_for (
38
+ & self ,
39
+ def_id : DefId ,
40
+ bound_vars : SubstsRef < ' tcx > ,
41
+ ) -> Vec < chalk_ir:: QuantifiedWhereClause < RustInterner < ' tcx > > > {
42
+ let predicates = self . tcx . predicates_of ( def_id) . predicates ;
43
+ let mut regions_substitutor = lowering:: RegionsSubstitutor :: new (
44
+ self . tcx ,
45
+ self . restatic_placeholder ,
46
+ self . reempty_placeholder ,
47
+ ) ;
48
+ predicates
49
+ . iter ( )
50
+ . map ( |( wc, _) | wc. subst ( self . tcx , bound_vars) )
51
+ . map ( |wc| wc. fold_with ( & mut regions_substitutor) )
52
+ . filter_map ( |wc| LowerInto :: < Option < chalk_ir:: QuantifiedWhereClause < RustInterner < ' tcx > > > > :: lower_into ( wc, & self . interner ) ) . collect ( )
53
+ }
54
+ }
55
+
34
56
impl < ' tcx > chalk_solve:: RustIrDatabase < RustInterner < ' tcx > > for RustIrDatabase < ' tcx > {
35
57
fn interner ( & self ) -> & RustInterner < ' tcx > {
36
58
& self . interner
@@ -55,11 +77,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
55
77
// FIXME(chalk): this really isn't right I don't think. The functions
56
78
// for GATs are a bit hard to figure out. Are these supposed to be where
57
79
// clauses or bounds?
58
- let predicates = self . tcx . predicates_defined_on ( def_id) . predicates ;
59
- let where_clauses: Vec < _ > = predicates
60
- . iter ( )
61
- . map ( |( wc, _) | wc. subst ( self . tcx , & bound_vars) )
62
- . filter_map ( |wc| LowerInto :: < Option < chalk_ir:: QuantifiedWhereClause < RustInterner < ' tcx > > > > :: lower_into ( wc, & self . interner ) ) . collect ( ) ;
80
+ let where_clauses = self . where_clauses_for ( def_id, bound_vars) ;
63
81
64
82
Arc :: new ( chalk_solve:: rust_ir:: AssociatedTyDatum {
65
83
trait_id : chalk_ir:: TraitId ( trait_def_id) ,
@@ -81,11 +99,9 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
81
99
82
100
let bound_vars = bound_vars_for_item ( self . tcx , def_id) ;
83
101
let binders = binders_for ( & self . interner , bound_vars) ;
84
- let predicates = self . tcx . predicates_defined_on ( def_id) . predicates ;
85
- let where_clauses: Vec < _ > = predicates
86
- . iter ( )
87
- . map ( |( wc, _) | wc. subst ( self . tcx , & bound_vars) )
88
- . filter_map ( |wc| LowerInto :: < Option < chalk_ir:: QuantifiedWhereClause < RustInterner < ' tcx > > > > :: lower_into ( wc, & self . interner ) ) . collect ( ) ;
102
+
103
+ let where_clauses = self . where_clauses_for ( def_id, bound_vars) ;
104
+
89
105
let associated_ty_ids: Vec < _ > = self
90
106
. tcx
91
107
. associated_items ( def_id)
@@ -140,12 +156,8 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
140
156
let bound_vars = bound_vars_for_item ( self . tcx , adt_def. did ) ;
141
157
let binders = binders_for ( & self . interner , bound_vars) ;
142
158
143
- let predicates = self . tcx . predicates_of ( adt_def. did ) . predicates ;
144
- let where_clauses: Vec < _ > = predicates
145
- . iter ( )
146
- . map ( |( wc, _) | wc. subst ( self . tcx , bound_vars) )
147
- . filter_map ( |wc| LowerInto :: < Option < chalk_ir:: QuantifiedWhereClause < RustInterner < ' tcx > > > > :: lower_into ( wc, & self . interner ) )
148
- . collect ( ) ;
159
+ let where_clauses = self . where_clauses_for ( adt_def. did , bound_vars) ;
160
+
149
161
let variants: Vec < _ > = adt_def
150
162
. variants
151
163
. iter ( )
@@ -201,14 +213,11 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
201
213
let bound_vars = bound_vars_for_item ( self . tcx , def_id) ;
202
214
let binders = binders_for ( & self . interner , bound_vars) ;
203
215
204
- let predicates = self . tcx . predicates_defined_on ( def_id) . predicates ;
205
- let where_clauses: Vec < _ > = predicates
206
- . iter ( )
207
- . map ( |( wc, _) | wc. subst ( self . tcx , & bound_vars) )
208
- . filter_map ( |wc| LowerInto :: < Option < chalk_ir:: QuantifiedWhereClause < RustInterner < ' tcx > > > > :: lower_into ( wc, & self . interner ) ) . collect ( ) ;
216
+ let where_clauses = self . where_clauses_for ( def_id, bound_vars) ;
209
217
210
218
let sig = self . tcx . fn_sig ( def_id) ;
211
219
let inputs_and_output = sig. inputs_and_output ( ) ;
220
+ let inputs_and_output = inputs_and_output. subst ( self . tcx , bound_vars) ;
212
221
let ( inputs_and_output, iobinders, _) = crate :: chalk:: lowering:: collect_bound_vars (
213
222
& self . interner ,
214
223
self . tcx ,
@@ -253,12 +262,14 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
253
262
254
263
let trait_ref = self . tcx . impl_trait_ref ( def_id) . expect ( "not an impl" ) ;
255
264
let trait_ref = trait_ref. subst ( self . tcx , bound_vars) ;
265
+ let mut regions_substitutor = lowering:: RegionsSubstitutor :: new (
266
+ self . tcx ,
267
+ self . restatic_placeholder ,
268
+ self . reempty_placeholder ,
269
+ ) ;
270
+ let trait_ref = trait_ref. fold_with ( & mut regions_substitutor) ;
256
271
257
- let predicates = self . tcx . predicates_of ( def_id) . predicates ;
258
- let where_clauses: Vec < _ > = predicates
259
- . iter ( )
260
- . map ( |( wc, _) | wc. subst ( self . tcx , bound_vars) )
261
- . filter_map ( |wc| LowerInto :: < Option < chalk_ir:: QuantifiedWhereClause < RustInterner < ' tcx > > > > :: lower_into ( wc, & self . interner ) ) . collect ( ) ;
272
+ let where_clauses = self . where_clauses_for ( def_id, bound_vars) ;
262
273
263
274
let value = chalk_solve:: rust_ir:: ImplDatumBound {
264
275
trait_ref : trait_ref. lower_into ( & self . interner ) ,
@@ -293,6 +304,12 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
293
304
294
305
let self_ty = trait_ref. self_ty ( ) ;
295
306
let self_ty = self_ty. subst ( self . tcx , bound_vars) ;
307
+ let mut regions_substitutor = lowering:: RegionsSubstitutor :: new (
308
+ self . tcx ,
309
+ self . restatic_placeholder ,
310
+ self . reempty_placeholder ,
311
+ ) ;
312
+ let self_ty = self_ty. fold_with ( & mut regions_substitutor) ;
296
313
let lowered_ty = self_ty. lower_into ( & self . interner ) ;
297
314
298
315
parameters[ 0 ] . assert_ty_ref ( & self . interner ) . could_match ( & self . interner , & lowered_ty)
@@ -370,11 +387,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
370
387
) -> Arc < chalk_solve:: rust_ir:: OpaqueTyDatum < RustInterner < ' tcx > > > {
371
388
let bound_vars = bound_vars_for_item ( self . tcx , opaque_ty_id. 0 ) ;
372
389
let binders = binders_for ( & self . interner , bound_vars) ;
373
- let predicates = self . tcx . predicates_defined_on ( opaque_ty_id. 0 ) . predicates ;
374
- let where_clauses: Vec < _ > = predicates
375
- . iter ( )
376
- . map ( |( wc, _) | wc. subst ( self . tcx , & bound_vars) )
377
- . filter_map ( |wc| LowerInto :: < Option < chalk_ir:: QuantifiedWhereClause < RustInterner < ' tcx > > > > :: lower_into ( wc, & self . interner ) ) . collect ( ) ;
390
+ let where_clauses = self . where_clauses_for ( opaque_ty_id. 0 , bound_vars) ;
378
391
379
392
let value = chalk_solve:: rust_ir:: OpaqueTyDatumBound {
380
393
bounds : chalk_ir:: Binders :: new ( binders. clone ( ) , vec ! [ ] ) ,
0 commit comments