1
1
use chalk_ir:: cast:: { Cast , Caster } ;
2
2
use chalk_ir:: interner:: ChalkIr ;
3
3
use chalk_ir:: {
4
- self , AssocTypeId , BoundVar , DebruijnIndex , ImplId , QuantifiedWhereClauses , StructId ,
5
- Substitution , TraitId ,
4
+ self , AssocTypeId , BoundVar , DebruijnIndex , ImplId , ParameterKinds , QuantifiedWhereClauses ,
5
+ StructId , Substitution , TraitId ,
6
6
} ;
7
7
use chalk_parse:: ast:: * ;
8
8
use chalk_rust_ir as rust_ir;
@@ -161,16 +161,17 @@ impl<'k> Env<'k> {
161
161
} )
162
162
}
163
163
164
- fn in_binders < I , T , OP > ( & self , binders : I , op : OP ) -> LowerResult < chalk_ir:: Binders < T > >
164
+ fn in_binders < I , T , OP > ( & self , binders : I , op : OP ) -> LowerResult < chalk_ir:: Binders < ChalkIr , T > >
165
165
where
166
166
I : IntoIterator < Item = chalk_ir:: ParameterKind < Ident > > ,
167
167
I :: IntoIter : ExactSizeIterator ,
168
168
OP : FnOnce ( & Self ) -> LowerResult < T > ,
169
169
{
170
170
let binders: Vec < _ > = binders. into_iter ( ) . collect ( ) ;
171
171
let env = self . introduce ( binders. iter ( ) . cloned ( ) ) ?;
172
+ let interner = & ChalkIr ;
172
173
Ok ( chalk_ir:: Binders {
173
- binders : binders. anonymize ( ) ,
174
+ binders : ParameterKinds :: from ( interner , binders. anonymize ( ) ) ,
174
175
value : op ( & env) ?,
175
176
} )
176
177
}
@@ -525,11 +526,12 @@ trait LowerWhereClauses {
525
526
526
527
impl LowerTypeKind for StructDefn {
527
528
fn lower_type_kind ( & self ) -> LowerResult < TypeKind > {
529
+ let interner = & ChalkIr ;
528
530
Ok ( TypeKind {
529
531
sort : TypeSort :: Struct ,
530
532
name : self . name . str ,
531
533
binders : chalk_ir:: Binders {
532
- binders : self . all_parameters ( ) . anonymize ( ) ,
534
+ binders : ParameterKinds :: from ( interner , self . all_parameters ( ) . anonymize ( ) ) ,
533
535
value : ( ) ,
534
536
} ,
535
537
} )
@@ -544,13 +546,14 @@ impl LowerWhereClauses for StructDefn {
544
546
545
547
impl LowerTypeKind for TraitDefn {
546
548
fn lower_type_kind ( & self ) -> LowerResult < TypeKind > {
549
+ let interner = & ChalkIr ;
547
550
let binders: Vec < _ > = self . parameter_kinds . iter ( ) . map ( |p| p. lower ( ) ) . collect ( ) ;
548
551
Ok ( TypeKind {
549
552
sort : TypeSort :: Trait ,
550
553
name : self . name . str ,
551
554
binders : chalk_ir:: Binders {
552
555
// for the purposes of the *type*, ignore `Self`:
553
- binders : binders. anonymize ( ) ,
556
+ binders : ParameterKinds :: from ( interner , binders. anonymize ( ) ) ,
554
557
value : ( ) ,
555
558
} ,
556
559
} )
@@ -757,6 +760,7 @@ trait LowerTraitBound {
757
760
758
761
impl LowerTraitBound for TraitBound {
759
762
fn lower ( & self , env : & Env ) -> LowerResult < rust_ir:: TraitBound < ChalkIr > > {
763
+ let interner = & ChalkIr ;
760
764
let trait_id = env. lookup_trait ( self . trait_name ) ?;
761
765
762
766
let k = env. trait_kind ( trait_id) ;
@@ -770,15 +774,15 @@ impl LowerTraitBound for TraitBound {
770
774
. map ( |a| Ok ( a. lower ( env) ?) )
771
775
. collect :: < LowerResult < Vec < _ > > > ( ) ?;
772
776
773
- if parameters. len ( ) != k. binders . len ( ) {
777
+ if parameters. len ( ) != k. binders . len ( interner ) {
774
778
Err ( RustIrError :: IncorrectNumberOfTypeParameters {
775
779
identifier : self . trait_name ,
776
- expected : k. binders . len ( ) ,
780
+ expected : k. binders . len ( interner ) ,
777
781
actual : parameters. len ( ) ,
778
782
} ) ?;
779
783
}
780
784
781
- for ( binder, param) in k. binders . binders . iter ( ) . zip ( parameters. iter ( ) ) {
785
+ for ( binder, param) in k. binders . binders . iter ( interner ) . zip ( parameters. iter ( ) ) {
782
786
if binder. kind ( ) != param. kind ( ) {
783
787
Err ( RustIrError :: IncorrectTraitParameterKind {
784
788
identifier : self . trait_name ,
@@ -984,10 +988,10 @@ impl LowerTy for Ty {
984
988
Ty :: Id { name } => match env. lookup_type ( name) ? {
985
989
TypeLookup :: Struct ( id) => {
986
990
let k = env. struct_kind ( id) ;
987
- if k. binders . len ( ) > 0 {
991
+ if k. binders . len ( interner ) > 0 {
988
992
Err ( RustIrError :: IncorrectNumberOfTypeParameters {
989
993
identifier : name,
990
- expected : k. binders . len ( ) ,
994
+ expected : k. binders . len ( interner ) ,
991
995
actual : 0 ,
992
996
} )
993
997
} else {
@@ -1031,10 +1035,10 @@ impl LowerTy for Ty {
1031
1035
} ;
1032
1036
1033
1037
let k = env. struct_kind ( id) ;
1034
- if k. binders . len ( ) != args. len ( ) {
1038
+ if k. binders . len ( interner ) != args. len ( ) {
1035
1039
Err ( RustIrError :: IncorrectNumberOfTypeParameters {
1036
1040
identifier : name,
1037
- expected : k. binders . len ( ) ,
1041
+ expected : k. binders . len ( interner ) ,
1038
1042
actual : args. len ( ) ,
1039
1043
} ) ?;
1040
1044
}
@@ -1044,7 +1048,7 @@ impl LowerTy for Ty {
1044
1048
args. iter ( ) . map ( |t| Ok ( t. lower ( env) ?) ) ,
1045
1049
) ?;
1046
1050
1047
- for ( param, arg) in k. binders . binders . iter ( ) . zip ( args. iter ( ) ) {
1051
+ for ( param, arg) in k. binders . binders . iter ( interner ) . zip ( args. iter ( ) ) {
1048
1052
if param. kind ( ) != arg. kind ( ) {
1049
1053
Err ( RustIrError :: IncorrectParameterKind {
1050
1054
identifier : name,
@@ -1207,7 +1211,10 @@ impl LowerClause for Clause {
1207
1211
let clauses = implications
1208
1212
. into_iter ( )
1209
1213
. map (
1210
- |implication : chalk_ir:: Binders < chalk_ir:: ProgramClauseImplication < ChalkIr > > | {
1214
+ |implication : chalk_ir:: Binders <
1215
+ ChalkIr ,
1216
+ chalk_ir:: ProgramClauseImplication < ChalkIr > ,
1217
+ > | {
1211
1218
chalk_ir:: ProgramClauseData :: ForAll ( implication) . intern ( interner)
1212
1219
} ,
1213
1220
)
@@ -1273,14 +1280,16 @@ pub trait LowerGoal<A> {
1273
1280
1274
1281
impl LowerGoal < LoweredProgram > for Goal {
1275
1282
fn lower ( & self , program : & LoweredProgram ) -> LowerResult < chalk_ir:: Goal < ChalkIr > > {
1283
+ let interner = & ChalkIr ;
1276
1284
let associated_ty_lookups: BTreeMap < _ , _ > = program
1277
1285
. associated_ty_data
1278
1286
. iter ( )
1279
1287
. map ( |( & associated_ty_id, datum) | {
1280
1288
let trait_datum = & program. trait_data [ & datum. trait_id ] ;
1281
- let num_trait_params = trait_datum. binders . len ( ) ;
1282
- let num_addl_params = datum. binders . len ( ) - num_trait_params;
1283
- let addl_parameter_kinds = datum. binders . binders [ ..num_addl_params] . to_owned ( ) ;
1289
+ let num_trait_params = trait_datum. binders . len ( interner) ;
1290
+ let num_addl_params = datum. binders . len ( interner) - num_trait_params;
1291
+ let addl_parameter_kinds =
1292
+ datum. binders . binders . as_slice ( interner) [ ..num_addl_params] . to_owned ( ) ;
1284
1293
let lookup = AssociatedTyLookup {
1285
1294
id : associated_ty_id,
1286
1295
addl_parameter_kinds,
0 commit comments