@@ -465,6 +465,24 @@ impl Parse {
465465 if has_assoc_const {
466466 impls_with_assoc_consts. push ( item_impl) ;
467467 }
468+
469+ if let syn:: Type :: Path ( ref path) = * item_impl. self_ty {
470+ if let Some ( type_name) = path. path . get_ident ( ) {
471+ for method in item_impl. items . iter ( ) . filter_map ( |item| match item {
472+ syn:: ImplItem :: Method ( method) => Some ( method) ,
473+ _ => None ,
474+ } ) {
475+ self . load_syn_method (
476+ config,
477+ binding_crate_name,
478+ crate_name,
479+ mod_cfg,
480+ type_name,
481+ method,
482+ )
483+ }
484+ }
485+ }
468486 }
469487 syn:: Item :: Macro ( ref item) => {
470488 self . load_builtin_macro ( config, crate_name, mod_cfg, item)
@@ -540,6 +558,36 @@ impl Parse {
540558 }
541559 }
542560
561+ /// Loads a `fn` declaration inside an `impl` block, if the type is a simple identifier
562+ fn load_syn_method (
563+ & mut self ,
564+ config : & Config ,
565+ binding_crate_name : & str ,
566+ crate_name : & str ,
567+ mod_cfg : Option < & Cfg > ,
568+ type_name : & syn:: Ident ,
569+ item : & syn:: ImplItemMethod ,
570+ ) {
571+ if let Some ( mut func) = self . load_fn_declaration (
572+ config,
573+ binding_crate_name,
574+ crate_name,
575+ mod_cfg,
576+ item,
577+ & item. sig ,
578+ & item. vis ,
579+ & item. attrs ,
580+ ) {
581+ if config. function . use_swift_name {
582+ func. attributes . push ( format ! (
583+ "swift_name(\" {}\" )" ,
584+ item. swift_name( Some ( type_name) )
585+ ) )
586+ }
587+ self . functions . push ( func) ;
588+ }
589+ }
590+
543591 /// Loads a `fn` declaration
544592 fn load_syn_fn (
545593 & mut self ,
@@ -549,65 +597,76 @@ impl Parse {
549597 mod_cfg : Option < & Cfg > ,
550598 item : & syn:: ItemFn ,
551599 ) {
600+ if let Some ( mut func) = self . load_fn_declaration (
601+ config,
602+ binding_crate_name,
603+ crate_name,
604+ mod_cfg,
605+ item,
606+ & item. sig ,
607+ & item. vis ,
608+ & item. attrs ,
609+ ) {
610+ if config. function . use_swift_name {
611+ func. attributes
612+ . push ( format ! ( "swift_name(\" {}\" )" , item. swift_name( None ) ) )
613+ }
614+ self . functions . push ( func) ;
615+ }
616+ }
617+
618+ fn load_fn_declaration (
619+ & mut self ,
620+ config : & Config ,
621+ binding_crate_name : & str ,
622+ crate_name : & str ,
623+ mod_cfg : Option < & Cfg > ,
624+ named_symbol : & dyn SynItemFnHelpers ,
625+ sig : & syn:: Signature ,
626+ vis : & syn:: Visibility ,
627+ attrs : & [ syn:: Attribute ] ,
628+ ) -> Option < Function > {
552629 if !config
553630 . parse
554631 . should_generate_top_level_item ( crate_name, binding_crate_name)
555632 {
556633 info ! (
557634 "Skip {}::{} - (fn's outside of the binding crate are not used)." ,
558- crate_name, & item . sig. ident
635+ crate_name, & sig. ident
559636 ) ;
560- return ;
637+ return None ;
561638 }
562639
563- if let syn:: Visibility :: Public ( _) = item . vis {
564- if item . sig . abi . is_omitted ( ) || item . sig . abi . is_c ( ) {
565- if let Some ( exported_name) = item . exported_name ( ) {
640+ if let syn:: Visibility :: Public ( _) = vis {
641+ if sig. abi . is_omitted ( ) || sig. abi . is_c ( ) {
642+ if let Some ( exported_name) = named_symbol . exported_name ( ) {
566643 let path = Path :: new ( exported_name) ;
567- match Function :: load ( path, & item . sig , false , & item . attrs , mod_cfg) {
644+ match Function :: load ( path, & sig, false , & attrs, mod_cfg) {
568645 Ok ( func) => {
569- info ! ( "Take {}::{}." , crate_name, & item. sig. ident) ;
570-
571- self . functions . push ( func) ;
646+ info ! ( "Take {}::{}." , crate_name, & sig. ident) ;
647+ return Some ( func) ;
572648 }
573649 Err ( msg) => {
574- error ! (
575- "Cannot use fn {}::{} ({})." ,
576- crate_name, & item. sig. ident, msg
577- ) ;
650+ error ! ( "Cannot use fn {}::{} ({})." , crate_name, & sig. ident, msg) ;
578651 }
579652 }
580- return ;
653+ } else {
654+ warn ! (
655+ "Skipping {}::{} - (not `no_mangle`, and has no `export_name` attribute)" ,
656+ crate_name, & sig. ident
657+ ) ;
581658 }
659+ } else {
660+ warn ! (
661+ "Skipping {}::{} - (not `extern \" C\" `" ,
662+ crate_name, & sig. ident
663+ ) ;
582664 }
583- }
584-
585- // TODO
586- if let syn:: Visibility :: Public ( _) = item. vis {
587665 } else {
588- warn ! ( "Skip {}::{} - (not `pub`)." , crate_name, & item. sig. ident) ;
589- }
590-
591- if !( item. sig . abi . is_omitted ( ) || item. sig . abi . is_c ( ) ) {
592- warn ! (
593- "Skip {}::{} - (wrong ABI - not `extern` or `extern \" C\" `)." ,
594- crate_name, & item. sig. ident
595- ) ;
596- }
597-
598- if item. exported_name ( ) . is_none ( ) {
599- warn ! (
600- "Skip {}::{} - (not `no_mangle`, and has no `export_name` attribute)" ,
601- crate_name, & item. sig. ident
602- ) ;
666+ warn ! ( "Skipping {}::{} - (not `pub`)" , crate_name, & sig. ident) ;
603667 }
604668
605- if item. sig . abi . is_some ( ) && !( item. sig . abi . is_omitted ( ) || item. sig . abi . is_c ( ) ) {
606- warn ! (
607- "Skip {}::{} - (non `extern \" C\" `)." ,
608- crate_name, & item. sig. ident
609- ) ;
610- }
669+ None
611670 }
612671
613672 /// Loads associated `const` declarations
0 commit comments