@@ -55,6 +55,22 @@ impl chalk_solve::RustIrDatabase<Interner> for ChalkContext<'_> {
55
55
fn associated_ty_data ( & self , id : AssocTypeId ) -> Arc < AssociatedTyDatum > {
56
56
self . db . associated_ty_data ( from_assoc_type_id ( id) )
57
57
}
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
+ }
58
74
fn trait_datum ( & self , trait_id : TraitId ) -> Arc < TraitDatum > {
59
75
self . db . trait_datum ( self . krate , trait_id)
60
76
}
@@ -467,12 +483,13 @@ impl chalk_solve::RustIrDatabase<Interner> for ChalkContext<'_> {
467
483
// `resume_type`, `yield_type`, and `return_type` of the coroutine in question.
468
484
let subst = TyBuilder :: subst_for_coroutine ( self . db , parent) . fill_with_unknown ( ) . build ( ) ;
469
485
486
+ let len = subst. len ( Interner ) ;
470
487
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 ) )
472
489
. intern ( Interner ) ,
473
- yield_type : TyKind :: BoundVar ( BoundVar :: new ( DebruijnIndex :: INNERMOST , 1 ) )
490
+ yield_type : TyKind :: BoundVar ( BoundVar :: new ( DebruijnIndex :: INNERMOST , len - 2 ) )
474
491
. intern ( Interner ) ,
475
- return_type : TyKind :: BoundVar ( BoundVar :: new ( DebruijnIndex :: INNERMOST , 2 ) )
492
+ return_type : TyKind :: BoundVar ( BoundVar :: new ( DebruijnIndex :: INNERMOST , len - 1 ) )
476
493
. intern ( Interner ) ,
477
494
// FIXME: calculate upvars
478
495
upvars : vec ! [ ] ,
@@ -619,10 +636,10 @@ pub(crate) fn associated_ty_data_query(
619
636
. with_type_param_mode ( crate :: lower:: ParamLoweringMode :: Variable ) ;
620
637
621
638
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 )
623
640
. build ( ) ;
624
641
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 ( ) )
626
643
. build ( ) ;
627
644
let self_ty = TyKind :: Alias ( AliasTy :: Projection ( pro_ty) ) . intern ( Interner ) ;
628
645
@@ -1021,8 +1038,9 @@ pub(super) fn generic_predicate_to_inline_bound(
1021
1038
}
1022
1039
WhereClause :: AliasEq ( AliasEq { alias : AliasTy :: Projection ( projection_ty) , ty } ) => {
1023
1040
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) ;
1026
1044
let ( self_ty, args_no_self) =
1027
1045
trait_args. split_first ( ) . expect ( "projection without trait self type" ) ;
1028
1046
if self_ty. assert_ty_ref ( Interner ) != & self_ty_shifted_in {
0 commit comments