@@ -536,7 +536,7 @@ fn writeln_opaque<W: std::io::Write>(w: &mut W, ident: &syn::Ident, struct_name:
536
536
writeln ! ( w, "\t /// the Rust equivalent takes an Option, it may be set to null to indicate None." ) . unwrap ( ) ;
537
537
writeln ! ( w, "\t pub inner: *mut native{},\n \t pub is_owned: bool,\n }}\n " , ident) . unwrap ( ) ;
538
538
writeln ! ( w, "impl Drop for {} {{\n \t fn drop(&mut self) {{" , struct_name) . unwrap ( ) ;
539
- writeln ! ( w, "\t \t if self.is_owned && !self.inner.is_null( ) {{" ) . unwrap ( ) ;
539
+ writeln ! ( w, "\t \t if self.is_owned && !<*mut native{}>::is_null( self.inner) {{" , ident ) . unwrap ( ) ;
540
540
writeln ! ( w, "\t \t \t let _ = unsafe {{ Box::from_raw(self.inner) }};\n \t \t }}\n \t }}\n }}" ) . unwrap ( ) ;
541
541
writeln ! ( w, "#[no_mangle]\n pub extern \" C\" fn {}_free(this_ptr: {}) {{ }}" , struct_name, struct_name) . unwrap ( ) ;
542
542
writeln ! ( w, "#[allow(unused)]" ) . unwrap ( ) ;
@@ -808,10 +808,10 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, i: &syn::ItemImpl, types: &mut Typ
808
808
}
809
809
}
810
810
) ) ;
811
- write ! ( w, "\t }}\n }}\n use {}::{} as {}TraitImport; \n " , types . orig_crate , full_trait_path , trait_obj . ident ) . unwrap ( ) ;
811
+ writeln ! ( w, "\t }}\n }}\n " ) . unwrap ( ) ;
812
812
813
813
macro_rules! impl_meth {
814
- ( $m: expr, $trait: expr, $indent: expr) => {
814
+ ( $m: expr, $trait_path : expr , $ trait: expr, $indent: expr) => {
815
815
let trait_method = $trait. items. iter( ) . filter_map( |item| {
816
816
if let syn:: TraitItem :: Method ( t_m) = item { Some ( t_m) } else { None }
817
817
} ) . find( |trait_meth| trait_meth. sig. ident == $m. sig. ident) . unwrap( ) ;
@@ -842,9 +842,9 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, i: &syn::ItemImpl, types: &mut Typ
842
842
t_gen_args += "_"
843
843
}
844
844
if takes_self {
845
- write!( w, "<native{} as {}TraitImport <{}>>::{}(unsafe {{ &mut *(this_arg as *mut native{}) }}, " , ident, $trait . ident , t_gen_args, $m. sig. ident, ident) . unwrap( ) ;
845
+ write!( w, "<native{} as {}::{} <{}>>::{}(unsafe {{ &mut *(this_arg as *mut native{}) }}, " , ident, types . orig_crate , $trait_path , t_gen_args, $m. sig. ident, ident) . unwrap( ) ;
846
846
} else {
847
- write!( w, "<native{} as {}TraitImport <{}>>::{}(" , ident, $trait . ident , t_gen_args, $m. sig. ident) . unwrap( ) ;
847
+ write!( w, "<native{} as {}::{} <{}>>::{}(" , ident, types . orig_crate , $trait_path , t_gen_args, $m. sig. ident) . unwrap( ) ;
848
848
}
849
849
850
850
let mut real_type = "" . to_string( ) ;
@@ -881,20 +881,19 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, i: &syn::ItemImpl, types: &mut Typ
881
881
for item in i. items . iter ( ) {
882
882
match item {
883
883
syn:: ImplItem :: Method ( m) => {
884
- impl_meth ! ( m, trait_obj, "" ) ;
884
+ impl_meth ! ( m, full_trait_path , trait_obj, "" ) ;
885
885
} ,
886
886
syn:: ImplItem :: Type ( _) => { } ,
887
887
_ => unimplemented ! ( ) ,
888
888
}
889
889
}
890
890
walk_supertraits ! ( trait_obj, Some ( & types) , (
891
- ( s, t ) => {
891
+ ( s, _ ) => {
892
892
if let Some ( supertrait_obj) = types. crate_types. traits. get( s) . cloned( ) {
893
- writeln!( w, "use {}::{} as native{}Trait;" , types. orig_crate, s, t) . unwrap( ) ;
894
893
for item in supertrait_obj. items. iter( ) {
895
894
match item {
896
895
syn:: TraitItem :: Method ( m) => {
897
- impl_meth!( m, supertrait_obj, "\t " ) ;
896
+ impl_meth!( m, s , supertrait_obj, "\t " ) ;
898
897
} ,
899
898
_ => { } ,
900
899
}
@@ -914,7 +913,7 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, i: &syn::ItemImpl, types: &mut Typ
914
913
writeln ! ( w, "impl Clone for {} {{" , ident) . unwrap ( ) ;
915
914
writeln ! ( w, "\t fn clone(&self) -> Self {{" ) . unwrap ( ) ;
916
915
writeln ! ( w, "\t \t Self {{" ) . unwrap ( ) ;
917
- writeln ! ( w, "\t \t \t inner: if self.inner.is_null( ) {{ std::ptr::null_mut() }} else {{" ) . unwrap ( ) ;
916
+ writeln ! ( w, "\t \t \t inner: if <*mut native{}>::is_null( self.inner) {{ std::ptr::null_mut() }} else {{" , ident ) . unwrap ( ) ;
918
917
writeln ! ( w, "\t \t \t \t Box::into_raw(Box::new(unsafe {{ &*self.inner }}.clone())) }}," ) . unwrap ( ) ;
919
918
writeln ! ( w, "\t \t \t is_owned: true," ) . unwrap ( ) ;
920
919
writeln ! ( w, "\t \t }}\n \t }}\n }}" ) . unwrap ( ) ;
0 commit comments