@@ -794,6 +794,94 @@ fn assoc_type(
794794 }
795795}
796796
797+ fn assoc_method (
798+ w : & mut Buffer ,
799+ meth : & clean:: Item ,
800+ header : hir:: FnHeader ,
801+ g : & clean:: Generics ,
802+ d : & clean:: FnDecl ,
803+ link : AssocItemLink < ' _ > ,
804+ parent : ItemType ,
805+ cx : & Context < ' _ > ,
806+ render_mode : RenderMode ,
807+ ) {
808+ let name = meth. name . as_ref ( ) . unwrap ( ) ;
809+ let href = match link {
810+ AssocItemLink :: Anchor ( Some ( ref id) ) => Some ( format ! ( "#{}" , id) ) ,
811+ AssocItemLink :: Anchor ( None ) => Some ( format ! ( "#{}.{}" , meth. type_( ) , name) ) ,
812+ AssocItemLink :: GotoSource ( did, provided_methods) => {
813+ // We're creating a link from an impl-item to the corresponding
814+ // trait-item and need to map the anchored type accordingly.
815+ let ty = if provided_methods. contains ( name) {
816+ ItemType :: Method
817+ } else {
818+ ItemType :: TyMethod
819+ } ;
820+
821+ match ( href ( did. expect_def_id ( ) , cx) , ty) {
822+ ( Ok ( p) , ty) => Some ( format ! ( "{}#{}.{}" , p. 0 , ty, name) ) ,
823+ ( Err ( HrefError :: DocumentationNotBuilt ) , ItemType :: TyMethod ) => None ,
824+ ( Err ( _) , ty) => Some ( format ! ( "#{}.{}" , ty, name) ) ,
825+ }
826+ }
827+ } ;
828+ let vis = meth. visibility . print_with_space ( meth. def_id , cx) . to_string ( ) ;
829+ // FIXME: Once https://github.com/rust-lang/rust/issues/67792 is implemented, we can remove
830+ // this condition.
831+ let constness = match render_mode {
832+ RenderMode :: Normal => {
833+ print_constness_with_space ( & header. constness , meth. const_stability ( cx. tcx ( ) ) )
834+ }
835+ RenderMode :: ForDeref { .. } => "" ,
836+ } ;
837+ let asyncness = header. asyncness . print_with_space ( ) ;
838+ let unsafety = header. unsafety . print_with_space ( ) ;
839+ let defaultness = print_default_space ( meth. is_default ( ) ) ;
840+ let abi = print_abi_with_space ( header. abi ) . to_string ( ) ;
841+
842+ // NOTE: `{:#}` does not print HTML formatting, `{}` does. So `g.print` can't be reused between the length calculation and `write!`.
843+ let generics_len = format ! ( "{:#}" , g. print( cx) ) . len ( ) ;
844+ let mut header_len = "fn " . len ( )
845+ + vis. len ( )
846+ + constness. len ( )
847+ + asyncness. len ( )
848+ + unsafety. len ( )
849+ + defaultness. len ( )
850+ + abi. len ( )
851+ + name. as_str ( ) . len ( )
852+ + generics_len;
853+
854+ let ( indent, indent_str, end_newline) = if parent == ItemType :: Trait {
855+ header_len += 4 ;
856+ let indent_str = " " ;
857+ render_attributes_in_pre ( w, meth, indent_str) ;
858+ ( 4 , indent_str, false )
859+ } else {
860+ render_attributes_in_code ( w, meth) ;
861+ ( 0 , "" , true )
862+ } ;
863+ w. reserve ( header_len + "<a href=\" \" class=\" fnname\" >{" . len ( ) + "</a>" . len ( ) ) ;
864+ write ! (
865+ w,
866+ "{indent}{vis}{constness}{asyncness}{unsafety}{defaultness}{abi}fn <a {href} class=\" fnname\" >{name}</a>\
867+ {generics}{decl}{notable_traits}{where_clause}",
868+ indent = indent_str,
869+ vis = vis,
870+ constness = constness,
871+ asyncness = asyncness,
872+ unsafety = unsafety,
873+ defaultness = defaultness,
874+ abi = abi,
875+ // links without a href are valid - https://www.w3schools.com/tags/att_a_href.asp
876+ href = href. map( |href| format!( "href=\" {}\" " , href) ) . unwrap_or_else( || "" . to_string( ) ) ,
877+ name = name,
878+ generics = g. print( cx) ,
879+ decl = d. full_print( header_len, indent, header. asyncness, cx) ,
880+ notable_traits = notable_traits_decl( d, cx) ,
881+ where_clause = print_where_clause( g, cx, indent, end_newline) ,
882+ )
883+ }
884+
797885/// Writes a span containing the versions at which an item became stable and/or const-stable. For
798886/// example, if the item became stable at 1.0.0, and const-stable at 1.45.0, this function would
799887/// write a span containing "1.0.0 (const: 1.45.0)".
@@ -875,100 +963,13 @@ fn render_assoc_item(
875963 cx : & Context < ' _ > ,
876964 render_mode : RenderMode ,
877965) {
878- fn method (
879- w : & mut Buffer ,
880- meth : & clean:: Item ,
881- header : hir:: FnHeader ,
882- g : & clean:: Generics ,
883- d : & clean:: FnDecl ,
884- link : AssocItemLink < ' _ > ,
885- parent : ItemType ,
886- cx : & Context < ' _ > ,
887- render_mode : RenderMode ,
888- ) {
889- let name = meth. name . as_ref ( ) . unwrap ( ) ;
890- let href = match link {
891- AssocItemLink :: Anchor ( Some ( ref id) ) => Some ( format ! ( "#{}" , id) ) ,
892- AssocItemLink :: Anchor ( None ) => Some ( format ! ( "#{}.{}" , meth. type_( ) , name) ) ,
893- AssocItemLink :: GotoSource ( did, provided_methods) => {
894- // We're creating a link from an impl-item to the corresponding
895- // trait-item and need to map the anchored type accordingly.
896- let ty = if provided_methods. contains ( name) {
897- ItemType :: Method
898- } else {
899- ItemType :: TyMethod
900- } ;
901-
902- match ( href ( did. expect_def_id ( ) , cx) , ty) {
903- ( Ok ( p) , ty) => Some ( format ! ( "{}#{}.{}" , p. 0 , ty, name) ) ,
904- ( Err ( HrefError :: DocumentationNotBuilt ) , ItemType :: TyMethod ) => None ,
905- ( Err ( _) , ty) => Some ( format ! ( "#{}.{}" , ty, name) ) ,
906- }
907- }
908- } ;
909- let vis = meth. visibility . print_with_space ( meth. def_id , cx) . to_string ( ) ;
910- // FIXME: Once https://github.com/rust-lang/rust/issues/67792 is implemented, we can remove
911- // this condition.
912- let constness = match render_mode {
913- RenderMode :: Normal => {
914- print_constness_with_space ( & header. constness , meth. const_stability ( cx. tcx ( ) ) )
915- }
916- RenderMode :: ForDeref { .. } => "" ,
917- } ;
918- let asyncness = header. asyncness . print_with_space ( ) ;
919- let unsafety = header. unsafety . print_with_space ( ) ;
920- let defaultness = print_default_space ( meth. is_default ( ) ) ;
921- let abi = print_abi_with_space ( header. abi ) . to_string ( ) ;
922-
923- // NOTE: `{:#}` does not print HTML formatting, `{}` does. So `g.print` can't be reused between the length calculation and `write!`.
924- let generics_len = format ! ( "{:#}" , g. print( cx) ) . len ( ) ;
925- let mut header_len = "fn " . len ( )
926- + vis. len ( )
927- + constness. len ( )
928- + asyncness. len ( )
929- + unsafety. len ( )
930- + defaultness. len ( )
931- + abi. len ( )
932- + name. as_str ( ) . len ( )
933- + generics_len;
934-
935- let ( indent, indent_str, end_newline) = if parent == ItemType :: Trait {
936- header_len += 4 ;
937- let indent_str = " " ;
938- render_attributes_in_pre ( w, meth, indent_str) ;
939- ( 4 , indent_str, false )
940- } else {
941- render_attributes_in_code ( w, meth) ;
942- ( 0 , "" , true )
943- } ;
944- w. reserve ( header_len + "<a href=\" \" class=\" fnname\" >{" . len ( ) + "</a>" . len ( ) ) ;
945- write ! (
946- w,
947- "{indent}{vis}{constness}{asyncness}{unsafety}{defaultness}{abi}fn <a {href} class=\" fnname\" >{name}</a>\
948- {generics}{decl}{notable_traits}{where_clause}",
949- indent = indent_str,
950- vis = vis,
951- constness = constness,
952- asyncness = asyncness,
953- unsafety = unsafety,
954- defaultness = defaultness,
955- abi = abi,
956- // links without a href are valid - https://www.w3schools.com/tags/att_a_href.asp
957- href = href. map( |href| format!( "href=\" {}\" " , href) ) . unwrap_or_else( || "" . to_string( ) ) ,
958- name = name,
959- generics = g. print( cx) ,
960- decl = d. full_print( header_len, indent, header. asyncness, cx) ,
961- notable_traits = notable_traits_decl( d, cx) ,
962- where_clause = print_where_clause( g, cx, indent, end_newline) ,
963- )
964- }
965966 match * item. kind {
966967 clean:: StrippedItem ( ..) => { }
967968 clean:: TyMethodItem ( ref m) => {
968- method ( w, item, m. header , & m. generics , & m. decl , link, parent, cx, render_mode)
969+ assoc_method ( w, item, m. header , & m. generics , & m. decl , link, parent, cx, render_mode)
969970 }
970971 clean:: MethodItem ( ref m, _) => {
971- method ( w, item, m. header , & m. generics , & m. decl , link, parent, cx, render_mode)
972+ assoc_method ( w, item, m. header , & m. generics , & m. decl , link, parent, cx, render_mode)
972973 }
973974 clean:: AssocConstItem ( ref ty, _) => {
974975 assoc_const ( w, item, ty, link, if parent == ItemType :: Trait { " " } else { "" } , cx)
0 commit comments