@@ -9,7 +9,7 @@ use span::Edition;
9
9
use tracing:: debug;
10
10
11
11
use chalk_ir:: { CanonicalVarKinds , cast:: Caster , fold:: shift:: Shift } ;
12
- use chalk_solve:: rust_ir:: { self , OpaqueTyDatumBound , WellKnownTrait } ;
12
+ use chalk_solve:: rust_ir:: { self , AssociatedTyDatumBound , OpaqueTyDatumBound , WellKnownTrait } ;
13
13
14
14
use base_db:: Crate ;
15
15
use hir_def:: {
@@ -24,12 +24,15 @@ use crate::{
24
24
AliasEq , AliasTy , BoundVar , DebruijnIndex , Interner , ProjectionTy , ProjectionTyExt ,
25
25
QuantifiedWhereClause , Substitution , TraitRef , TraitRefExt , Ty , TyBuilder , TyExt , TyKind ,
26
26
WhereClause ,
27
- db:: { HirDatabase , InternedCoroutine } ,
27
+ db:: { HirDatabase , InternedCoroutine , RpititImplAssocTy , RpititImplAssocTyId } ,
28
28
from_assoc_type_id, from_chalk_trait_id, from_foreign_def_id,
29
29
generics:: generics,
30
30
lower:: LifetimeElisionKind ,
31
31
make_binders, make_single_type_binders,
32
- mapping:: { ToChalk , TypeAliasAsValue , from_chalk} ,
32
+ mapping:: {
33
+ AnyImplAssocType , AnyTraitAssocType , ToChalk , from_assoc_type_value_id, from_chalk,
34
+ to_assoc_type_id_rpitit, to_assoc_type_value_id, to_assoc_type_value_id_rpitit,
35
+ } ,
33
36
method_resolution:: { ALL_FLOAT_FPS , ALL_INT_FPS , TraitImpls , TyFingerprint } ,
34
37
to_assoc_type_id, to_chalk_trait_id,
35
38
traits:: ChalkContext ,
@@ -54,23 +57,48 @@ pub(crate) type Variances = chalk_ir::Variances<Interner>;
54
57
55
58
impl chalk_solve:: RustIrDatabase < Interner > for ChalkContext < ' _ > {
56
59
fn associated_ty_data ( & self , id : AssocTypeId ) -> Arc < AssociatedTyDatum > {
57
- self . db . associated_ty_data ( from_assoc_type_id ( id) )
60
+ match from_assoc_type_id ( self . db , id) {
61
+ AnyTraitAssocType :: Normal ( id) => self . db . associated_ty_data ( id) ,
62
+ AnyTraitAssocType :: Rpitit ( assoc_type_id) => {
63
+ let assoc_type = assoc_type_id. loc ( self . db ) ;
64
+ Arc :: new ( AssociatedTyDatum {
65
+ id,
66
+ trait_id : to_chalk_trait_id ( assoc_type. trait_id ) ,
67
+ name : sym:: synthesized_rpitit_assoc,
68
+ binders : assoc_type
69
+ . bounds
70
+ . clone ( )
71
+ . map ( |bounds| AssociatedTyDatumBound { bounds, where_clauses : Vec :: new ( ) } ) ,
72
+ } )
73
+ }
74
+ }
58
75
}
59
76
fn associated_ty_from_impl (
60
77
& self ,
61
78
impl_id : chalk_ir:: ImplId < Interner > ,
62
79
assoc_type_id : chalk_ir:: AssocTypeId < Interner > ,
63
80
) -> Option < rust_ir:: AssociatedTyValueId < Interner > > {
64
- let alias_id = from_assoc_type_id ( assoc_type_id) ;
65
- let trait_sig = self . db . type_alias_signature ( alias_id) ;
66
- self . db . impl_items ( hir_def:: ImplId :: from_chalk ( self . db , impl_id) ) . items . iter ( ) . find_map (
67
- |( name, item) | match item {
68
- AssocItemId :: TypeAliasId ( alias) if & trait_sig. name == name => {
69
- Some ( TypeAliasAsValue ( * alias) . to_chalk ( self . db ) )
70
- }
71
- _ => None ,
72
- } ,
73
- )
81
+ match from_assoc_type_id ( self . db , assoc_type_id) {
82
+ AnyTraitAssocType :: Normal ( alias_id) => {
83
+ let trait_sig = self . db . type_alias_signature ( alias_id) ;
84
+ self . db
85
+ . impl_items ( hir_def:: ImplId :: from_chalk ( self . db , impl_id) )
86
+ . items
87
+ . iter ( )
88
+ . find_map ( |( name, item) | match item {
89
+ AssocItemId :: TypeAliasId ( alias) if & trait_sig. name == name => {
90
+ Some ( to_assoc_type_value_id ( * alias) )
91
+ }
92
+ _ => None ,
93
+ } )
94
+ }
95
+ AnyTraitAssocType :: Rpitit ( trait_assoc) => {
96
+ Some ( to_assoc_type_value_id_rpitit ( RpititImplAssocTyId :: new (
97
+ self . db ,
98
+ RpititImplAssocTy { impl_id : from_chalk ( self . db , impl_id) , trait_assoc } ,
99
+ ) ) )
100
+ }
101
+ }
74
102
}
75
103
fn trait_datum ( & self , trait_id : TraitId ) -> Arc < TraitDatum > {
76
104
self . db . trait_datum ( self . krate , trait_id)
@@ -456,8 +484,13 @@ impl chalk_solve::RustIrDatabase<Interner> for ChalkContext<'_> {
456
484
Arc :: new ( rust_ir:: AdtSizeAlign :: from_one_zst ( false ) )
457
485
}
458
486
fn assoc_type_name ( & self , assoc_ty_id : chalk_ir:: AssocTypeId < Interner > ) -> String {
459
- let id = self . db . associated_ty_data ( from_assoc_type_id ( assoc_ty_id) ) . name ;
460
- self . db . type_alias_signature ( id) . name . display ( self . db , self . edition ( ) ) . to_string ( )
487
+ let name = match from_assoc_type_id ( self . db , assoc_ty_id) {
488
+ AnyTraitAssocType :: Normal ( id) => self . db . type_alias_signature ( id) . name . clone ( ) ,
489
+ AnyTraitAssocType :: Rpitit ( id) => {
490
+ self . db . function_signature ( id. loc ( self . db ) . synthesized_from_method ) . name . clone ( )
491
+ }
492
+ } ;
493
+ name. display ( self . db , self . edition ( ) ) . to_string ( )
461
494
}
462
495
fn opaque_type_name ( & self , opaque_ty_id : chalk_ir:: OpaqueTyId < Interner > ) -> String {
463
496
format ! ( "Opaque_{:?}" , opaque_ty_id. 0 )
@@ -673,7 +706,7 @@ pub(crate) fn associated_ty_data_query(
673
706
let datum = AssociatedTyDatum {
674
707
trait_id : to_chalk_trait_id ( trait_) ,
675
708
id : to_assoc_type_id ( type_alias) ,
676
- name : type_alias ,
709
+ name : type_alias_data . name . symbol ( ) . clone ( ) ,
677
710
binders : make_binders ( db, & generic_params, bound_data) ,
678
711
} ;
679
712
Arc :: new ( datum)
@@ -883,7 +916,7 @@ fn impl_def_datum(db: &dyn HirDatabase, krate: Crate, impl_id: hir_def::ImplId)
883
916
let name = & db. type_alias_signature ( type_alias) . name ;
884
917
trait_data. associated_type_by_name ( name) . is_some ( )
885
918
} )
886
- . map ( |type_alias| TypeAliasAsValue ( type_alias) . to_chalk ( db ) )
919
+ . map ( |type_alias| to_assoc_type_value_id ( type_alias) )
887
920
. collect ( ) ;
888
921
debug ! ( "impl_datum: {:?}" , impl_datum_bound) ;
889
922
let impl_datum = ImplDatum {
@@ -900,8 +933,19 @@ pub(crate) fn associated_ty_value_query(
900
933
krate : Crate ,
901
934
id : AssociatedTyValueId ,
902
935
) -> Arc < AssociatedTyValue > {
903
- let type_alias: TypeAliasAsValue = from_chalk ( db, id) ;
904
- type_alias_associated_ty_value ( db, krate, type_alias. 0 )
936
+ match from_assoc_type_value_id ( db, id) {
937
+ AnyImplAssocType :: Normal ( type_alias) => {
938
+ type_alias_associated_ty_value ( db, krate, type_alias)
939
+ }
940
+ AnyImplAssocType :: Rpitit ( assoc_type_id) => {
941
+ let assoc_type = assoc_type_id. loc ( db) ;
942
+ Arc :: new ( AssociatedTyValue {
943
+ impl_id : assoc_type. impl_id . to_chalk ( db) ,
944
+ associated_ty_id : to_assoc_type_id_rpitit ( assoc_type. trait_assoc ) ,
945
+ value : assoc_type. value . clone ( ) ,
946
+ } )
947
+ }
948
+ }
905
949
}
906
950
907
951
fn type_alias_associated_ty_value (
@@ -1037,7 +1081,16 @@ pub(super) fn generic_predicate_to_inline_bound(
1037
1081
Some ( chalk_ir:: Binders :: new ( binders, rust_ir:: InlineBound :: TraitBound ( trait_bound) ) )
1038
1082
}
1039
1083
WhereClause :: AliasEq ( AliasEq { alias : AliasTy :: Projection ( projection_ty) , ty } ) => {
1040
- let generics = generics ( db, from_assoc_type_id ( projection_ty. associated_ty_id ) . into ( ) ) ;
1084
+ let generic_def = match from_assoc_type_id ( db, projection_ty. associated_ty_id ) {
1085
+ AnyTraitAssocType :: Normal ( type_alias) => type_alias. into ( ) ,
1086
+ AnyTraitAssocType :: Rpitit ( _) => {
1087
+ unreachable ! (
1088
+ "there is no way to refer to a RPITIT synthesized \
1089
+ associated type on associated type's self bounds (`type Assoc: Bound`)"
1090
+ )
1091
+ }
1092
+ } ;
1093
+ let generics = generics ( db, generic_def) ;
1041
1094
let parent_len = generics. parent_generics ( ) . map_or ( 0 , |g| g. len_self ( ) ) ;
1042
1095
let ( trait_args, assoc_args) =
1043
1096
projection_ty. substitution . as_slice ( Interner ) . split_at ( parent_len) ;
0 commit comments