@@ -92,15 +92,18 @@ macro_rules! walk_supertraits { ($t: expr, $types: expr, ($( $pat: pat => $e: ex
92
92
if supertrait. paren_token. is_some( ) || supertrait. lifetimes. is_some( ) {
93
93
unimplemented!( ) ;
94
94
}
95
- if let Some ( ident) = supertrait. path. get_ident( ) {
96
- match ( & format!( "{}" , ident) as & str , & ident) {
95
+ // First try to resolve path to find in-crate traits, but if that doesn't work
96
+ // assume its a prelude trait (eg Clone, etc) and just use the single ident.
97
+ if let Some ( path) = $types. maybe_resolve_path( & supertrait. path, None ) {
98
+ match ( & path as & str , & supertrait. path. segments. iter( ) . last( ) . unwrap( ) . ident) {
97
99
$( $pat => $e, ) *
98
100
}
99
- } else {
100
- let path = $types. resolve_path( & supertrait. path, None ) ;
101
- match ( & path as & str , & supertrait. path. segments. iter( ) . last( ) . unwrap( ) . ident) {
101
+ } else if let Some ( ident) = supertrait. path. get_ident( ) {
102
+ match ( & format!( "{}" , ident) as & str , & ident) {
102
103
$( $pat => $e, ) *
103
104
}
105
+ } else {
106
+ panic!( "Supertrait unresolvable and not single-ident" ) ;
104
107
}
105
108
} ,
106
109
syn:: TypeParamBound :: Lifetime ( _) => unimplemented!( ) ,
@@ -661,8 +664,7 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, i: &syn::ItemImpl, types: &mut Typ
661
664
writeln!( w, "\t \t clone: Some({}_clone_void)," , ident) . unwrap( ) ;
662
665
} ,
663
666
( s, t) => {
664
- if s. starts_with( "util::" ) {
665
- let supertrait_obj = types. crate_types. traits. get( s) . unwrap( ) ;
667
+ if let Some ( supertrait_obj) = types. crate_types. traits. get( s) {
666
668
writeln!( w, "\t \t {}: crate::{} {{" , t, s) . unwrap( ) ;
667
669
writeln!( w, "\t \t \t this_arg: unsafe {{ (*this_arg).inner as *mut c_void }}," ) . unwrap( ) ;
668
670
writeln!( w, "\t \t \t free: None," ) . unwrap( ) ;
@@ -753,9 +755,8 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, i: &syn::ItemImpl, types: &mut Typ
753
755
}
754
756
walk_supertraits ! ( trait_obj, types, (
755
757
( s, t) => {
756
- if s . starts_with ( "util::" ) {
758
+ if let Some ( supertrait_obj ) = types . crate_types . traits . get ( s ) . cloned ( ) {
757
759
writeln!( w, "use {}::{} as native{}Trait;" , types. orig_crate, s, t) . unwrap( ) ;
758
- let supertrait_obj = * types. crate_types. traits. get( s) . unwrap( ) ;
759
760
for item in supertrait_obj. items. iter( ) {
760
761
match item {
761
762
syn:: TraitItem :: Method ( m) => {
0 commit comments