Skip to content

Commit 4be923d

Browse files
committed
[bindings] Avoid double-use'ing traits by writing out the path
1 parent 686208b commit 4be923d

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

c-bindings-gen/src/main.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -808,10 +808,10 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, i: &syn::ItemImpl, types: &mut Typ
808808
}
809809
}
810810
) );
811-
write!(w, "\t}}\n}}\nuse {}::{} as {}TraitImport;\n", types.orig_crate, full_trait_path, trait_obj.ident).unwrap();
811+
writeln!(w, "\t}}\n}}\n").unwrap();
812812

813813
macro_rules! impl_meth {
814-
($m: expr, $trait: expr, $indent: expr) => {
814+
($m: expr, $trait_path: expr, $trait: expr, $indent: expr) => {
815815
let trait_method = $trait.items.iter().filter_map(|item| {
816816
if let syn::TraitItem::Method(t_m) = item { Some(t_m) } else { None }
817817
}).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
842842
t_gen_args += "_"
843843
}
844844
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();
846846
} 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();
848848
}
849849

850850
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
881881
for item in i.items.iter() {
882882
match item {
883883
syn::ImplItem::Method(m) => {
884-
impl_meth!(m, trait_obj, "");
884+
impl_meth!(m, full_trait_path, trait_obj, "");
885885
},
886886
syn::ImplItem::Type(_) => {},
887887
_ => unimplemented!(),
888888
}
889889
}
890890
walk_supertraits!(trait_obj, Some(&types), (
891-
(s, t) => {
891+
(s, _) => {
892892
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();
894893
for item in supertrait_obj.items.iter() {
895894
match item {
896895
syn::TraitItem::Method(m) => {
897-
impl_meth!(m, supertrait_obj, "\t");
896+
impl_meth!(m, s, supertrait_obj, "\t");
898897
},
899898
_ => {},
900899
}

0 commit comments

Comments
 (0)