@@ -55,6 +55,22 @@ impl chalk_solve::RustIrDatabase<Interner> for ChalkContext<'_> {
5555 fn associated_ty_data ( & self , id : AssocTypeId ) -> Arc < AssociatedTyDatum > {
5656 self . db . associated_ty_data ( from_assoc_type_id ( id) )
5757 }
58+ fn associated_ty_from_impl (
59+ & self ,
60+ impl_id : chalk_ir:: ImplId < Interner > ,
61+ assoc_type_id : chalk_ir:: AssocTypeId < Interner > ,
62+ ) -> Option < rust_ir:: AssociatedTyValueId < Interner > > {
63+ let alias_id = from_assoc_type_id ( assoc_type_id) ;
64+ let trait_sig = self . db . type_alias_signature ( alias_id) ;
65+ self . db . impl_items ( hir_def:: ImplId :: from_chalk ( self . db , impl_id) ) . items . iter ( ) . find_map (
66+ |( name, item) | match item {
67+ AssocItemId :: TypeAliasId ( alias) if & trait_sig. name == name => {
68+ Some ( TypeAliasAsValue ( * alias) . to_chalk ( self . db ) )
69+ }
70+ _ => None ,
71+ } ,
72+ )
73+ }
5874 fn trait_datum ( & self , trait_id : TraitId ) -> Arc < TraitDatum > {
5975 self . db . trait_datum ( self . krate , trait_id)
6076 }
@@ -467,12 +483,13 @@ impl chalk_solve::RustIrDatabase<Interner> for ChalkContext<'_> {
467483 // `resume_type`, `yield_type`, and `return_type` of the coroutine in question.
468484 let subst = TyBuilder :: subst_for_coroutine ( self . db , parent) . fill_with_unknown ( ) . build ( ) ;
469485
486+ let len = subst. len ( Interner ) ;
470487 let input_output = rust_ir:: CoroutineInputOutputDatum {
471- resume_type : TyKind :: BoundVar ( BoundVar :: new ( DebruijnIndex :: INNERMOST , 0 ) )
488+ resume_type : TyKind :: BoundVar ( BoundVar :: new ( DebruijnIndex :: INNERMOST , len - 3 ) )
472489 . intern ( Interner ) ,
473- yield_type : TyKind :: BoundVar ( BoundVar :: new ( DebruijnIndex :: INNERMOST , 1 ) )
490+ yield_type : TyKind :: BoundVar ( BoundVar :: new ( DebruijnIndex :: INNERMOST , len - 2 ) )
474491 . intern ( Interner ) ,
475- return_type : TyKind :: BoundVar ( BoundVar :: new ( DebruijnIndex :: INNERMOST , 2 ) )
492+ return_type : TyKind :: BoundVar ( BoundVar :: new ( DebruijnIndex :: INNERMOST , len - 1 ) )
476493 . intern ( Interner ) ,
477494 // FIXME: calculate upvars
478495 upvars : vec ! [ ] ,
@@ -619,10 +636,10 @@ pub(crate) fn associated_ty_data_query(
619636 . with_type_param_mode ( crate :: lower:: ParamLoweringMode :: Variable ) ;
620637
621638 let trait_subst = TyBuilder :: subst_for_def ( db, trait_, None )
622- . fill_with_bound_vars ( crate :: DebruijnIndex :: INNERMOST , generic_params . len_self ( ) )
639+ . fill_with_bound_vars ( crate :: DebruijnIndex :: INNERMOST , 0 )
623640 . build ( ) ;
624641 let pro_ty = TyBuilder :: assoc_type_projection ( db, type_alias, Some ( trait_subst) )
625- . fill_with_bound_vars ( crate :: DebruijnIndex :: INNERMOST , 0 )
642+ . fill_with_bound_vars ( crate :: DebruijnIndex :: INNERMOST , generic_params . len_self ( ) )
626643 . build ( ) ;
627644 let self_ty = TyKind :: Alias ( AliasTy :: Projection ( pro_ty) ) . intern ( Interner ) ;
628645
@@ -1021,8 +1038,9 @@ pub(super) fn generic_predicate_to_inline_bound(
10211038 }
10221039 WhereClause :: AliasEq ( AliasEq { alias : AliasTy :: Projection ( projection_ty) , ty } ) => {
10231040 let generics = generics ( db, from_assoc_type_id ( projection_ty. associated_ty_id ) . into ( ) ) ;
1024- let ( assoc_args, trait_args) =
1025- projection_ty. substitution . as_slice ( Interner ) . split_at ( generics. len_self ( ) ) ;
1041+ let parent_len = generics. parent_generics ( ) . map_or ( 0 , |g| g. len_self ( ) ) ;
1042+ let ( trait_args, assoc_args) =
1043+ projection_ty. substitution . as_slice ( Interner ) . split_at ( parent_len) ;
10261044 let ( self_ty, args_no_self) =
10271045 trait_args. split_first ( ) . expect ( "projection without trait self type" ) ;
10281046 if self_ty. assert_ty_ref ( Interner ) != & self_ty_shifted_in {
0 commit comments