@@ -87,7 +87,7 @@ impl TypeAliasData {
87
87
#[ derive( Debug , Clone , PartialEq , Eq ) ]
88
88
pub struct TraitData {
89
89
pub name : Option < Name > ,
90
- pub items : Vec < AssocItemId > ,
90
+ pub items : Vec < ( Name , AssocItemId ) > ,
91
91
pub auto : bool ,
92
92
}
93
93
@@ -97,28 +97,42 @@ impl TraitData {
97
97
let name = src. value . name ( ) . map ( |n| n. as_name ( ) ) ;
98
98
let auto = src. value . is_auto ( ) ;
99
99
let ast_id_map = db. ast_id_map ( src. file_id ) ;
100
+
101
+ let container = ContainerId :: TraitId ( tr) ;
100
102
let items = if let Some ( item_list) = src. value . item_list ( ) {
101
103
item_list
102
104
. impl_items ( )
103
105
. map ( |item_node| match item_node {
104
- ast:: ImplItem :: FnDef ( it) => FunctionLoc {
105
- container : ContainerId :: TraitId ( tr) ,
106
- ast_id : AstId :: new ( src. file_id , ast_id_map. ast_id ( & it) ) ,
106
+ ast:: ImplItem :: FnDef ( it) => {
107
+ let name = it. name ( ) . map ( |it| it. as_name ( ) ) . unwrap_or_else ( Name :: missing) ;
108
+ let def = FunctionLoc {
109
+ container,
110
+ ast_id : AstId :: new ( src. file_id , ast_id_map. ast_id ( & it) ) ,
111
+ }
112
+ . intern ( db)
113
+ . into ( ) ;
114
+ ( name, def)
107
115
}
108
- . intern ( db)
109
- . into ( ) ,
110
- ast:: ImplItem :: ConstDef ( it) => ConstLoc {
111
- container : ContainerId :: TraitId ( tr) ,
112
- ast_id : AstId :: new ( src. file_id , ast_id_map. ast_id ( & it) ) ,
116
+ ast:: ImplItem :: ConstDef ( it) => {
117
+ let name = it. name ( ) . map ( |it| it. as_name ( ) ) . unwrap_or_else ( Name :: missing) ;
118
+ let def = ConstLoc {
119
+ container,
120
+ ast_id : AstId :: new ( src. file_id , ast_id_map. ast_id ( & it) ) ,
121
+ }
122
+ . intern ( db)
123
+ . into ( ) ;
124
+ ( name, def)
113
125
}
114
- . intern ( db)
115
- . into ( ) ,
116
- ast:: ImplItem :: TypeAliasDef ( it) => TypeAliasLoc {
117
- container : ContainerId :: TraitId ( tr) ,
118
- ast_id : AstId :: new ( src. file_id , ast_id_map. ast_id ( & it) ) ,
126
+ ast:: ImplItem :: TypeAliasDef ( it) => {
127
+ let name = it. name ( ) . map ( |it| it. as_name ( ) ) . unwrap_or_else ( Name :: missing) ;
128
+ let def = TypeAliasLoc {
129
+ container,
130
+ ast_id : AstId :: new ( src. file_id , ast_id_map. ast_id ( & it) ) ,
131
+ }
132
+ . intern ( db)
133
+ . into ( ) ;
134
+ ( name, def)
119
135
}
120
- . intern ( db)
121
- . into ( ) ,
122
136
} )
123
137
. collect ( )
124
138
} else {
@@ -128,11 +142,18 @@ impl TraitData {
128
142
}
129
143
130
144
pub fn associated_types ( & self ) -> impl Iterator < Item = TypeAliasId > + ' _ {
131
- self . items . iter ( ) . filter_map ( |item| match item {
145
+ self . items . iter ( ) . filter_map ( |( _name , item) | match item {
132
146
AssocItemId :: TypeAliasId ( t) => Some ( * t) ,
133
147
_ => None ,
134
148
} )
135
149
}
150
+
151
+ pub fn associated_type_by_name ( & self , name : & Name ) -> Option < TypeAliasId > {
152
+ self . items . iter ( ) . find_map ( |( item_name, item) | match item {
153
+ AssocItemId :: TypeAliasId ( t) if item_name == name => Some ( * t) ,
154
+ _ => None ,
155
+ } )
156
+ }
136
157
}
137
158
138
159
#[ derive( Debug , Clone , PartialEq , Eq ) ]
0 commit comments