@@ -172,7 +172,6 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
172
172
current_item : & Option < String > ,
173
173
parent_id : Option < DefId > ,
174
174
extra_fragment : & Option < String > ,
175
- item : & Item ,
176
175
) -> Result < ( Res , Option < String > ) , ErrorKind > {
177
176
let cx = self . cx ;
178
177
@@ -291,43 +290,23 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
291
290
did,
292
291
) => {
293
292
debug ! ( "looking for associated item named {} for item {:?}" , item_name, did) ;
294
- let impl_kind = resolve_associated_trait_item ( did, item_name, & self . cx ) ?;
295
- // TODO: is this necessary? It doesn't look right, and also only works for local items
296
- let trait_kind = self . cx . as_local_hir_id ( item. def_id )
297
- . and_then ( |item_hir| {
298
- // Checks if item_name belongs to `impl SomeTrait for SomeItem`
299
- let parent_hir = self . cx . tcx . hir ( ) . get_parent_item ( item_hir) ;
300
- let item_parent = self . cx . tcx . hir ( ) . find ( parent_hir) ;
301
- match item_parent {
302
- Some ( hir:: Node :: Item ( hir:: Item {
303
- kind : hir:: ItemKind :: Impl { of_trait : Some ( _) , self_ty, .. } ,
304
- ..
305
- } ) ) => cx
306
- . tcx
307
- . associated_item_def_ids ( self_ty. hir_id . owner )
308
- . iter ( )
309
- . map ( |child| {
310
- let associated_item = cx. tcx . associated_item ( * child) ;
311
- associated_item
312
- } )
313
- . find ( |child| child. ident . name == item_name)
314
- . map ( |child| child. kind ) ,
315
- _ => None ,
316
- }
317
- } ) ;
318
- debug ! ( "considering items {:?} and {:?}" , impl_kind, trait_kind) ;
319
- let kind = match ( impl_kind, trait_kind) {
320
- ( Some ( from_kind) , Some ( _) ) => {
321
- // Although it's ambiguous, return impl version for compat. sake.
322
- // To handle that properly resolve() would have to support
323
- // something like
324
- // [`ambi_fn`](<SomeStruct as SomeTrait>::ambi_fn)
325
- Some ( from_kind)
326
- }
327
- ( None , Some ( from_kind) ) => Some ( from_kind) ,
328
- ( Some ( from_kind) , None ) => Some ( from_kind) ,
329
- _ => None ,
330
- } ;
293
+ // Checks if item_name belongs to `impl SomeItem`
294
+ let mut kind = cx
295
+ . tcx
296
+ . inherent_impls ( did)
297
+ . iter ( )
298
+ . flat_map ( |imp| cx. tcx . associated_items ( * imp) . in_definition_order ( ) )
299
+ . find ( |item| item. ident . name == item_name)
300
+ . map ( |item| item. kind ) ;
301
+
302
+ // Check if item_name belogns to `impl SomeTrait for SomeItem`
303
+ // This gives precedence to `impl SomeItem`:
304
+ // Although having both would be ambiguous, use impl version for compat. sake.
305
+ // To handle that properly resolve() would have to support
306
+ // something like [`ambi_fn`](<SomeStruct as SomeTrait>::ambi_fn)
307
+ if kind. is_none ( ) {
308
+ kind = resolve_associated_trait_item ( did, item_name, & self . cx ) ?;
309
+ }
331
310
332
311
if let Some ( kind) = kind {
333
312
let out = match kind {
@@ -725,7 +704,6 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
725
704
& current_item,
726
705
base_node,
727
706
& extra_fragment,
728
- & item,
729
707
) {
730
708
Ok ( res) => res,
731
709
Err ( ErrorKind :: ResolutionFailure ) => {
@@ -760,7 +738,6 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
760
738
& current_item,
761
739
base_node,
762
740
& extra_fragment,
763
- & item,
764
741
) {
765
742
Ok ( res) => res,
766
743
Err ( ErrorKind :: ResolutionFailure ) => {
@@ -798,7 +775,6 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
798
775
& current_item,
799
776
base_node,
800
777
& extra_fragment,
801
- & item,
802
778
) {
803
779
Err ( ErrorKind :: AnchorFailure ( msg) ) => {
804
780
anchor_failure ( cx, & item, & ori_link, & dox, link_range, msg) ;
@@ -813,7 +789,6 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
813
789
& current_item,
814
790
base_node,
815
791
& extra_fragment,
816
- & item,
817
792
) {
818
793
Err ( ErrorKind :: AnchorFailure ( msg) ) => {
819
794
anchor_failure ( cx, & item, & ori_link, & dox, link_range, msg) ;
0 commit comments