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