@@ -911,11 +911,29 @@ fn resolve(cx: &DocContext, path_str: &str, is_val: bool) -> Result<(Def, Option
911
911
& path_str, is_val)
912
912
} ) ;
913
913
914
- if result. is_ok ( ) {
915
- return result. map ( |path| ( path. def , None ) ) ;
914
+ if let Ok ( result) = result {
915
+ // In case this is a trait item, skip the
916
+ // early return and try looking for the trait
917
+ let value = match result. def {
918
+ Def :: Method ( _) | Def :: AssociatedConst ( _) => true ,
919
+ Def :: AssociatedTy ( _) => false ,
920
+ // not a trait item, just return what we found
921
+ _ => return Ok ( ( result. def , None ) )
922
+ } ;
923
+
924
+ if value != is_val {
925
+ return Err ( ( ) )
926
+ }
927
+ } else {
928
+ // If resolution failed, it may still be a method
929
+ // because methods are not handled by the resolver
930
+ // If so, bail when we're not looking for a value
931
+ if !is_val {
932
+ return Err ( ( ) )
933
+ }
916
934
}
917
935
918
- // Try looking for methods and other associated items
936
+ // Try looking for methods and associated items
919
937
let mut split = path_str. rsplitn ( 2 , "::" ) ;
920
938
let mut item_name = if let Some ( first) = split. next ( ) {
921
939
first
@@ -935,8 +953,6 @@ fn resolve(cx: &DocContext, path_str: &str, is_val: bool) -> Result<(Def, Option
935
953
resolver. resolve_str_path_error ( DUMMY_SP ,
936
954
& path, false )
937
955
} ) ?;
938
-
939
-
940
956
match ty. def {
941
957
Def :: Struct ( did) | Def :: Union ( did) | Def :: Enum ( did) | Def :: TyAlias ( did) => {
942
958
let item = cx. tcx . inherent_impls ( did) . iter ( )
@@ -952,9 +968,22 @@ fn resolve(cx: &DocContext, path_str: &str, is_val: bool) -> Result<(Def, Option
952
968
Err ( ( ) )
953
969
}
954
970
}
955
- Def :: Trait ( _) => {
956
- // XXXManishearth todo
957
- Err ( ( ) )
971
+ Def :: Trait ( did) => {
972
+ let item = cx. tcx . associated_item_def_ids ( did) . iter ( )
973
+ . map ( |item| cx. tcx . associated_item ( * item) )
974
+ . find ( |item| item. name == item_name) ;
975
+ if let Some ( item) = item {
976
+ let kind = match item. kind {
977
+ ty:: AssociatedKind :: Const if is_val => "associatedconstant" ,
978
+ ty:: AssociatedKind :: Type if !is_val => "associatedtype" ,
979
+ ty:: AssociatedKind :: Method if is_val => "tymethod" ,
980
+ _ => return Err ( ( ) )
981
+ } ;
982
+
983
+ Ok ( ( ty. def , Some ( format ! ( "{}.{}" , kind, item_name) ) ) )
984
+ } else {
985
+ Err ( ( ) )
986
+ }
958
987
}
959
988
_ => Err ( ( ) )
960
989
}
0 commit comments