@@ -31,7 +31,7 @@ use std::cell::Cell;
3131use std:: mem;
3232use std:: ops:: Range ;
3333
34- use crate :: clean:: { self , Crate , GetDefId , Item , ItemLink , PrimitiveType } ;
34+ use crate :: clean:: { self , Crate , Item , ItemLink , PrimitiveType } ;
3535use crate :: core:: DocContext ;
3636use crate :: fold:: DocFolder ;
3737use crate :: html:: markdown:: markdown_links;
@@ -685,78 +685,23 @@ fn resolve_associated_trait_item(
685685 ns : Namespace ,
686686 cx : & DocContext < ' _ > ,
687687) -> 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.
744691
745692 // Next consider explicit impls: `impl MyTrait for MyType`
746693 // 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+ } ) ;
757702 // 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 ( )
760705}
761706
762707/// Given a type, return all traits in scope in `module` implemented by that type.
0 commit comments