@@ -34,9 +34,11 @@ impl ToChalk for Ty {
3434 let substitution = apply_ty. parameters . to_chalk ( db) . shifted_in ( & Interner ) ;
3535 chalk_ir:: TyData :: Function ( chalk_ir:: FnPointer {
3636 num_binders : 0 ,
37- abi : ( ) ,
38- safety : chalk_ir:: Safety :: Safe ,
39- variadic : is_varargs,
37+ sig : chalk_ir:: FnSig {
38+ abi : ( ) ,
39+ safety : chalk_ir:: Safety :: Safe ,
40+ variadic : is_varargs,
41+ } ,
4042 substitution,
4143 } )
4244 . intern ( & Interner )
@@ -48,7 +50,7 @@ impl ToChalk for Ty {
4850 }
4951 } ,
5052 Ty :: Projection ( proj_ty) => {
51- let associated_ty_id = proj_ty. associated_ty . to_chalk ( db) ;
53+ let associated_ty_id = TypeAliasAsAssocType ( proj_ty. associated_ty ) . to_chalk ( db) ;
5254 let substitution = proj_ty. parameters . to_chalk ( db) ;
5355 chalk_ir:: AliasTy :: Projection ( chalk_ir:: ProjectionTy {
5456 associated_ty_id,
@@ -114,7 +116,8 @@ impl ToChalk for Ty {
114116 Ty :: Placeholder ( db. lookup_intern_type_param_id ( interned_id) )
115117 }
116118 chalk_ir:: TyData :: Alias ( chalk_ir:: AliasTy :: Projection ( proj) ) => {
117- let associated_ty = from_chalk ( db, proj. associated_ty_id ) ;
119+ let associated_ty =
120+ from_chalk :: < TypeAliasAsAssocType , _ > ( db, proj. associated_ty_id ) . 0 ;
118121 let parameters = from_chalk ( db, proj. substitution ) ;
119122 Ty :: Projection ( ProjectionTy { associated_ty, parameters } )
120123 }
@@ -125,7 +128,7 @@ impl ToChalk for Ty {
125128 }
126129 chalk_ir:: TyData :: Function ( chalk_ir:: FnPointer {
127130 num_binders,
128- variadic,
131+ sig : chalk_ir :: FnSig { variadic, .. } ,
129132 substitution,
130133 ..
131134 } ) => {
@@ -290,15 +293,22 @@ impl ToChalk for TypeCtor {
290293 fn to_chalk ( self , db : & dyn HirDatabase ) -> TypeName < Interner > {
291294 match self {
292295 TypeCtor :: AssociatedType ( type_alias) => {
293- let type_id = type_alias. to_chalk ( db) ;
294- TypeName :: AssociatedType ( type_id)
296+ let assoc_type = TypeAliasAsAssocType ( type_alias) ;
297+ let assoc_type_id = assoc_type. to_chalk ( db) ;
298+ TypeName :: AssociatedType ( assoc_type_id)
295299 }
296300
297301 TypeCtor :: OpaqueType ( impl_trait_id) => {
298302 let id = impl_trait_id. to_chalk ( db) ;
299303 TypeName :: OpaqueType ( id)
300304 }
301305
306+ TypeCtor :: ForeignType ( type_alias) => {
307+ let foreign_type = TypeAliasAsForeignType ( type_alias) ;
308+ let foreign_type_id = foreign_type. to_chalk ( db) ;
309+ TypeName :: Foreign ( foreign_type_id)
310+ }
311+
302312 TypeCtor :: Bool => TypeName :: Scalar ( Scalar :: Bool ) ,
303313 TypeCtor :: Char => TypeName :: Scalar ( Scalar :: Char ) ,
304314 TypeCtor :: Int ( int_ty) => TypeName :: Scalar ( int_ty_to_chalk ( int_ty) ) ,
@@ -339,7 +349,9 @@ impl ToChalk for TypeCtor {
339349 fn from_chalk ( db : & dyn HirDatabase , type_name : TypeName < Interner > ) -> TypeCtor {
340350 match type_name {
341351 TypeName :: Adt ( struct_id) => TypeCtor :: Adt ( struct_id. 0 ) ,
342- TypeName :: AssociatedType ( type_id) => TypeCtor :: AssociatedType ( from_chalk ( db, type_id) ) ,
352+ TypeName :: AssociatedType ( type_id) => {
353+ TypeCtor :: AssociatedType ( from_chalk :: < TypeAliasAsAssocType , _ > ( db, type_id) . 0 )
354+ }
343355 TypeName :: OpaqueType ( opaque_type_id) => {
344356 TypeCtor :: OpaqueType ( from_chalk ( db, opaque_type_id) )
345357 }
@@ -379,6 +391,10 @@ impl ToChalk for TypeCtor {
379391 TypeCtor :: Closure { def, expr }
380392 }
381393
394+ TypeName :: Foreign ( foreign_def_id) => {
395+ TypeCtor :: ForeignType ( from_chalk :: < TypeAliasAsForeignType , _ > ( db, foreign_def_id) . 0 )
396+ }
397+
382398 TypeName :: Error => {
383399 // this should not be reached, since we don't represent TypeName::Error with TypeCtor
384400 unreachable ! ( )
@@ -488,15 +504,31 @@ impl ToChalk for CallableDefId {
488504 }
489505}
490506
491- impl ToChalk for TypeAliasId {
507+ pub struct TypeAliasAsAssocType ( pub TypeAliasId ) ;
508+
509+ impl ToChalk for TypeAliasAsAssocType {
492510 type Chalk = AssocTypeId ;
493511
494512 fn to_chalk ( self , _db : & dyn HirDatabase ) -> AssocTypeId {
495- chalk_ir:: AssocTypeId ( self . as_intern_id ( ) )
513+ chalk_ir:: AssocTypeId ( self . 0 . as_intern_id ( ) )
514+ }
515+
516+ fn from_chalk ( _db : & dyn HirDatabase , assoc_type_id : AssocTypeId ) -> TypeAliasAsAssocType {
517+ TypeAliasAsAssocType ( InternKey :: from_intern_id ( assoc_type_id. 0 ) )
518+ }
519+ }
520+
521+ pub struct TypeAliasAsForeignType ( pub TypeAliasId ) ;
522+
523+ impl ToChalk for TypeAliasAsForeignType {
524+ type Chalk = ForeignDefId ;
525+
526+ fn to_chalk ( self , _db : & dyn HirDatabase ) -> ForeignDefId {
527+ chalk_ir:: ForeignDefId ( self . 0 . as_intern_id ( ) )
496528 }
497529
498- fn from_chalk ( _db : & dyn HirDatabase , type_alias_id : AssocTypeId ) -> TypeAliasId {
499- InternKey :: from_intern_id ( type_alias_id . 0 )
530+ fn from_chalk ( _db : & dyn HirDatabase , foreign_def_id : ForeignDefId ) -> TypeAliasAsForeignType {
531+ TypeAliasAsForeignType ( InternKey :: from_intern_id ( foreign_def_id . 0 ) )
500532 }
501533}
502534
@@ -580,7 +612,7 @@ impl ToChalk for ProjectionTy {
580612
581613 fn to_chalk ( self , db : & dyn HirDatabase ) -> chalk_ir:: ProjectionTy < Interner > {
582614 chalk_ir:: ProjectionTy {
583- associated_ty_id : self . associated_ty . to_chalk ( db) ,
615+ associated_ty_id : TypeAliasAsAssocType ( self . associated_ty ) . to_chalk ( db) ,
584616 substitution : self . parameters . to_chalk ( db) ,
585617 }
586618 }
@@ -590,7 +622,11 @@ impl ToChalk for ProjectionTy {
590622 projection_ty : chalk_ir:: ProjectionTy < Interner > ,
591623 ) -> ProjectionTy {
592624 ProjectionTy {
593- associated_ty : from_chalk ( db, projection_ty. associated_ty_id ) ,
625+ associated_ty : from_chalk :: < TypeAliasAsAssocType , _ > (
626+ db,
627+ projection_ty. associated_ty_id ,
628+ )
629+ . 0 ,
594630 parameters : from_chalk ( db, projection_ty. substitution ) ,
595631 }
596632 }
@@ -789,7 +825,8 @@ pub(super) fn generic_predicate_to_inline_bound(
789825 let alias_eq_bound = rust_ir:: AliasEqBound {
790826 value : proj. ty . clone ( ) . to_chalk ( db) ,
791827 trait_bound : rust_ir:: TraitBound { trait_id : trait_. to_chalk ( db) , args_no_self } ,
792- associated_ty_id : proj. projection_ty . associated_ty . to_chalk ( db) ,
828+ associated_ty_id : TypeAliasAsAssocType ( proj. projection_ty . associated_ty )
829+ . to_chalk ( db) ,
793830 parameters : Vec :: new ( ) , // FIXME we don't support generic associated types yet
794831 } ;
795832 Some ( rust_ir:: InlineBound :: AliasEqBound ( alias_eq_bound) )
0 commit comments