@@ -31,7 +31,7 @@ use std::cell::Cell;
31
31
use std:: mem;
32
32
use std:: ops:: Range ;
33
33
34
- use crate :: clean:: { self , Crate , GetDefId , Item , ItemLink , PrimitiveType } ;
34
+ use crate :: clean:: { self , Crate , Item , ItemLink , PrimitiveType } ;
35
35
use crate :: core:: DocContext ;
36
36
use crate :: fold:: DocFolder ;
37
37
use crate :: html:: markdown:: markdown_links;
@@ -685,78 +685,23 @@ fn resolve_associated_trait_item(
685
685
ns : Namespace ,
686
686
cx : & DocContext < ' _ > ,
687
687
) -> Option < ( ty:: AssocKind , DefId ) > {
688
- let ty = cx. tcx . type_of ( did) ;
689
- // First consider blanket impls: `impl From<T> for T`
690
- let implicit_impls = crate :: clean:: get_auto_trait_and_blanket_impls ( cx, ty, did) ;
691
- let mut candidates: Vec < _ > = implicit_impls
692
- . flat_map ( |impl_outer| {
693
- match impl_outer. kind {
694
- clean:: ImplItem ( impl_) => {
695
- debug ! ( "considering auto or blanket impl for trait {:?}" , impl_. trait_) ;
696
- // Give precedence to methods that were overridden
697
- if !impl_. provided_trait_methods . contains ( & * item_name. as_str ( ) ) {
698
- let mut items = impl_. items . into_iter ( ) . filter_map ( |assoc| {
699
- if assoc. name != Some ( item_name) {
700
- return None ;
701
- }
702
- let kind = assoc
703
- . kind
704
- . as_assoc_kind ( )
705
- . expect ( "inner items for a trait should be associated items" ) ;
706
- if kind. namespace ( ) != ns {
707
- return None ;
708
- }
709
-
710
- trace ! ( "considering associated item {:?}" , assoc. kind) ;
711
- // We have a slight issue: normal methods come from `clean` types,
712
- // but provided methods come directly from `tcx`.
713
- // Fortunately, we don't need the whole method, we just need to know
714
- // what kind of associated item it is.
715
- Some ( ( kind, assoc. def_id ) )
716
- } ) ;
717
- let assoc = items. next ( ) ;
718
- debug_assert_eq ! ( items. count( ) , 0 ) ;
719
- assoc
720
- } else {
721
- // These are provided methods or default types:
722
- // ```
723
- // trait T {
724
- // type A = usize;
725
- // fn has_default() -> A { 0 }
726
- // }
727
- // ```
728
- let trait_ = impl_. trait_ . unwrap ( ) . def_id ( ) . unwrap ( ) ;
729
- cx. tcx
730
- . associated_items ( trait_)
731
- . find_by_name_and_namespace (
732
- cx. tcx ,
733
- Ident :: with_dummy_span ( item_name) ,
734
- ns,
735
- trait_,
736
- )
737
- . map ( |assoc| ( assoc. kind , assoc. def_id ) )
738
- }
739
- }
740
- _ => panic ! ( "get_impls returned something that wasn't an impl" ) ,
741
- }
742
- } )
743
- . collect ( ) ;
688
+ // FIXME: this should also consider blanket impls (`impl<T> X for T`). Unfortunately
689
+ // `get_auto_trait_and_blanket_impls` is broken because the caching behavior is wrong. In the
690
+ // meantime, just don't look for these blanket impls.
744
691
745
692
// Next consider explicit impls: `impl MyTrait for MyType`
746
693
// Give precedence to inherent impls.
747
- if candidates. is_empty ( ) {
748
- let traits = traits_implemented_by ( cx, did, module) ;
749
- debug ! ( "considering traits {:?}" , traits) ;
750
- candidates. extend ( traits. iter ( ) . filter_map ( |& trait_| {
751
- cx. tcx
752
- . associated_items ( trait_)
753
- . find_by_name_and_namespace ( cx. tcx , Ident :: with_dummy_span ( item_name) , ns, trait_)
754
- . map ( |assoc| ( assoc. kind , assoc. def_id ) )
755
- } ) ) ;
756
- }
694
+ let traits = traits_implemented_by ( cx, did, module) ;
695
+ debug ! ( "considering traits {:?}" , traits) ;
696
+ let mut candidates = traits. iter ( ) . filter_map ( |& trait_| {
697
+ cx. tcx
698
+ . associated_items ( trait_)
699
+ . find_by_name_and_namespace ( cx. tcx , Ident :: with_dummy_span ( item_name) , ns, trait_)
700
+ . map ( |assoc| ( assoc. kind , assoc. def_id ) )
701
+ } ) ;
757
702
// FIXME(#74563): warn about ambiguity
758
- debug ! ( "the candidates were {:?}" , candidates) ;
759
- candidates. pop ( )
703
+ debug ! ( "the candidates were {:?}" , candidates. clone ( ) . collect :: < Vec <_>> ( ) ) ;
704
+ candidates. next ( )
760
705
}
761
706
762
707
/// Given a type, return all traits in scope in `module` implemented by that type.
0 commit comments