@@ -14,8 +14,8 @@ use syntax::{ast, AstNode};
14
14
15
15
use crate :: {
16
16
Adt , AsAssocItem , AssocItem , BuiltinType , Const , ConstParam , DocLinkDef , Enum , ExternCrateDecl ,
17
- Field , Function , GenericParam , Impl , LifetimeParam , Macro , Module , ModuleDef , Static , Struct ,
18
- Trait , TraitAlias , TypeAlias , TypeParam , Union , Variant , VariantDef ,
17
+ Field , Function , GenericParam , HasCrate , Impl , LifetimeParam , Macro , Module , ModuleDef , Static ,
18
+ Struct , Trait , TraitAlias , Type , TypeAlias , TypeParam , Union , Variant , VariantDef ,
19
19
} ;
20
20
21
21
pub trait HasAttrs {
@@ -201,8 +201,9 @@ fn resolve_assoc_or_field(
201
201
}
202
202
} ;
203
203
204
- // FIXME: Resolve associated items here, e.g. `Option::map`. Note that associated items take
205
- // precedence over fields.
204
+ if let Some ( assoc_item_def) = resolve_assoc_item ( db, & ty, & name, ns) {
205
+ return Some ( assoc_item_def) ;
206
+ }
206
207
207
208
let variant_def = match ty. as_adt ( ) ? {
208
209
Adt :: Struct ( it) => it. into ( ) ,
@@ -212,6 +213,35 @@ fn resolve_assoc_or_field(
212
213
resolve_field ( db, variant_def, name, ns)
213
214
}
214
215
216
+ fn resolve_assoc_item (
217
+ db : & dyn HirDatabase ,
218
+ ty : & Type ,
219
+ name : & Name ,
220
+ ns : Option < Namespace > ,
221
+ ) -> Option < DocLinkDef > {
222
+ ty. iterate_assoc_items ( db, ty. krate ( db) , move |assoc_item| {
223
+ if assoc_item. name ( db) ? != * name {
224
+ return None ;
225
+ }
226
+
227
+ let ( def, expected_ns) = match assoc_item {
228
+ AssocItem :: Function ( it) => ( ModuleDef :: Function ( it) , Namespace :: Values ) ,
229
+ AssocItem :: Const ( it) => ( ModuleDef :: Const ( it) , Namespace :: Values ) ,
230
+ AssocItem :: TypeAlias ( it) => {
231
+ // Inherent associated types are supported in nightly:
232
+ // https://github.com/rust-lang/rust/issues/8995
233
+ ( ModuleDef :: TypeAlias ( it) , Namespace :: Types )
234
+ }
235
+ } ;
236
+
237
+ if ns. unwrap_or ( expected_ns) != expected_ns {
238
+ return None ;
239
+ }
240
+
241
+ Some ( DocLinkDef :: ModuleDef ( def) )
242
+ } )
243
+ }
244
+
215
245
fn resolve_field (
216
246
db : & dyn HirDatabase ,
217
247
def : VariantDef ,
0 commit comments