@@ -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
}
@@ -468,12 +484,13 @@ impl chalk_solve::RustIrDatabase<Interner> for ChalkContext<'_> {
468
484
// `resume_type`, `yield_type`, and `return_type` of the coroutine in question.
469
485
let subst = TyBuilder :: subst_for_coroutine ( self . db , parent) . fill_with_unknown ( ) . build ( ) ;
470
486
487
+ let len = subst. len ( Interner ) ;
471
488
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 ) )
473
490
. intern ( Interner ) ,
474
- yield_type : TyKind :: BoundVar ( BoundVar :: new ( DebruijnIndex :: INNERMOST , 1 ) )
491
+ yield_type : TyKind :: BoundVar ( BoundVar :: new ( DebruijnIndex :: INNERMOST , len - 2 ) )
475
492
. intern ( Interner ) ,
476
- return_type : TyKind :: BoundVar ( BoundVar :: new ( DebruijnIndex :: INNERMOST , 2 ) )
493
+ return_type : TyKind :: BoundVar ( BoundVar :: new ( DebruijnIndex :: INNERMOST , len - 1 ) )
477
494
. intern ( Interner ) ,
478
495
// FIXME: calculate upvars
479
496
upvars : vec ! [ ] ,
@@ -620,10 +637,10 @@ pub(crate) fn associated_ty_data_query(
620
637
. with_type_param_mode ( crate :: lower:: ParamLoweringMode :: Variable ) ;
621
638
622
639
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 )
624
641
. build ( ) ;
625
642
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 ( ) )
627
644
. build ( ) ;
628
645
let self_ty = TyKind :: Alias ( AliasTy :: Projection ( pro_ty) ) . intern ( Interner ) ;
629
646
@@ -1022,8 +1039,9 @@ pub(super) fn generic_predicate_to_inline_bound(
1022
1039
}
1023
1040
WhereClause :: AliasEq ( AliasEq { alias : AliasTy :: Projection ( projection_ty) , ty } ) => {
1024
1041
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) ;
1027
1045
let ( self_ty, args_no_self) =
1028
1046
trait_args. split_first ( ) . expect ( "projection without trait self type" ) ;
1029
1047
if self_ty. assert_ty_ref ( Interner ) != & self_ty_shifted_in {
0 commit comments