@@ -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 }
@@ -468,12 +484,13 @@ impl chalk_solve::RustIrDatabase<Interner> for ChalkContext<'_> {
468484 // `resume_type`, `yield_type`, and `return_type` of the coroutine in question.
469485 let subst = TyBuilder :: subst_for_coroutine ( self . db , parent) . fill_with_unknown ( ) . build ( ) ;
470486
487+ let len = subst. len ( Interner ) ;
471488 let input_output = rust_ir:: CoroutineInputOutputDatum {
472- resume_type : TyKind :: BoundVar ( BoundVar :: new ( DebruijnIndex :: INNERMOST , 0 ) )
489+ resume_type : TyKind :: BoundVar ( BoundVar :: new ( DebruijnIndex :: INNERMOST , len - 3 ) )
473490 . intern ( Interner ) ,
474- yield_type : TyKind :: BoundVar ( BoundVar :: new ( DebruijnIndex :: INNERMOST , 1 ) )
491+ yield_type : TyKind :: BoundVar ( BoundVar :: new ( DebruijnIndex :: INNERMOST , len - 2 ) )
475492 . intern ( Interner ) ,
476- return_type : TyKind :: BoundVar ( BoundVar :: new ( DebruijnIndex :: INNERMOST , 2 ) )
493+ return_type : TyKind :: BoundVar ( BoundVar :: new ( DebruijnIndex :: INNERMOST , len - 1 ) )
477494 . intern ( Interner ) ,
478495 // FIXME: calculate upvars
479496 upvars : vec ! [ ] ,
@@ -620,10 +637,10 @@ pub(crate) fn associated_ty_data_query(
620637 . with_type_param_mode ( crate :: lower:: ParamLoweringMode :: Variable ) ;
621638
622639 let trait_subst = TyBuilder :: subst_for_def ( db, trait_, None )
623- . fill_with_bound_vars ( crate :: DebruijnIndex :: INNERMOST , generic_params . len_self ( ) )
640+ . fill_with_bound_vars ( crate :: DebruijnIndex :: INNERMOST , 0 )
624641 . build ( ) ;
625642 let pro_ty = TyBuilder :: assoc_type_projection ( db, type_alias, Some ( trait_subst) )
626- . fill_with_bound_vars ( crate :: DebruijnIndex :: INNERMOST , 0 )
643+ . fill_with_bound_vars ( crate :: DebruijnIndex :: INNERMOST , generic_params . len_self ( ) )
627644 . build ( ) ;
628645 let self_ty = TyKind :: Alias ( AliasTy :: Projection ( pro_ty) ) . intern ( Interner ) ;
629646
@@ -1022,8 +1039,9 @@ pub(super) fn generic_predicate_to_inline_bound(
10221039 }
10231040 WhereClause :: AliasEq ( AliasEq { alias : AliasTy :: Projection ( projection_ty) , ty } ) => {
10241041 let generics = generics ( db, from_assoc_type_id ( projection_ty. associated_ty_id ) . into ( ) ) ;
1025- let ( assoc_args, trait_args) =
1026- projection_ty. substitution . as_slice ( Interner ) . split_at ( generics. len_self ( ) ) ;
1042+ let parent_len = generics. parent_generics ( ) . map_or ( 0 , |g| g. len_self ( ) ) ;
1043+ let ( trait_args, assoc_args) =
1044+ projection_ty. substitution . as_slice ( Interner ) . split_at ( parent_len) ;
10271045 let ( self_ty, args_no_self) =
10281046 trait_args. split_first ( ) . expect ( "projection without trait self type" ) ;
10291047 if self_ty. assert_ty_ref ( Interner ) != & self_ty_shifted_in {
0 commit comments